10
10
11
11
#include " Client.h"
12
12
#include " Index.grpc.pb.h"
13
+ #include " index/Index.h"
13
14
#include " index/Serialization.h"
14
15
#include " marshalling/Marshalling.h"
15
16
#include " support/Logger.h"
16
17
#include " support/Trace.h"
18
+ #include " llvm/ADT/StringRef.h"
17
19
18
20
#include < chrono>
19
21
@@ -27,14 +29,24 @@ class IndexClient : public clangd::SymbolIndex {
27
29
using StreamingCall = std::unique_ptr<grpc::ClientReader<ReplyT>> (
28
30
remote::SymbolIndex::Stub::*)(grpc::ClientContext *, const RequestT &);
29
31
32
+ template <typename ClangdRequestT, typename RequestT>
33
+ RequestT serializeRequest (ClangdRequestT Request) const {
34
+ return toProtobuf (Request);
35
+ }
36
+
37
+ template <>
38
+ FuzzyFindRequest serializeRequest (clangd::FuzzyFindRequest Request) const {
39
+ return toProtobuf (Request, ProjectRoot);
40
+ }
41
+
30
42
template <typename RequestT, typename ReplyT, typename ClangdRequestT,
31
43
typename CallbackT>
32
44
bool streamRPC (ClangdRequestT Request,
33
45
StreamingCall<RequestT, ReplyT> RPCCall,
34
46
CallbackT Callback) const {
35
47
bool FinalResult = false ;
36
48
trace::Span Tracer (RequestT::descriptor ()->name ());
37
- const auto RPCRequest = toProtobuf (Request);
49
+ const auto RPCRequest = serializeRequest<ClangdRequestT, RequestT> (Request);
38
50
grpc::ClientContext Context;
39
51
std::chrono::system_clock::time_point Deadline =
40
52
std::chrono::system_clock::now () + DeadlineWaitingTime;
@@ -48,20 +60,21 @@ class IndexClient : public clangd::SymbolIndex {
48
60
FinalResult = Reply.final_result ();
49
61
continue ;
50
62
}
51
- auto Sym = fromProtobuf (Reply.stream_result (), &Strings);
52
- if (!Sym)
63
+ auto Response =
64
+ fromProtobuf (Reply.stream_result (), &Strings, ProjectRoot);
65
+ if (!Response)
53
66
elog (" Received invalid {0}" , ReplyT::descriptor ()->name ());
54
- Callback (*Sym );
67
+ Callback (*Response );
55
68
}
56
69
SPAN_ATTACH (Tracer, " status" , Reader->Finish ().ok ());
57
70
return FinalResult;
58
71
}
59
72
60
73
public:
61
74
IndexClient (
62
- std::shared_ptr<grpc::Channel> Channel,
75
+ std::shared_ptr<grpc::Channel> Channel, llvm::StringRef ProjectRoot,
63
76
std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000 ))
64
- : Stub(remote::SymbolIndex::NewStub(Channel)),
77
+ : Stub(remote::SymbolIndex::NewStub(Channel)), ProjectRoot(ProjectRoot),
65
78
DeadlineWaitingTime (DeadlineTime) {}
66
79
67
80
void lookup (const clangd::LookupRequest &Request,
@@ -86,22 +99,26 @@ class IndexClient : public clangd::SymbolIndex {
86
99
llvm::function_ref<void (const SymbolID &, const clangd::Symbol &)>)
87
100
const {}
88
101
89
- // IndexClient does not take any space since the data is stored on the server.
102
+ // IndexClient does not take any space since the data is stored on the
103
+ // server.
90
104
size_t estimateMemoryUsage () const { return 0 ; }
91
105
92
106
private:
93
107
std::unique_ptr<remote::SymbolIndex::Stub> Stub;
108
+ std::string ProjectRoot;
94
109
// Each request will be terminated if it takes too long.
95
110
std::chrono::milliseconds DeadlineWaitingTime;
96
111
};
97
112
98
113
} // namespace
99
114
100
- std::unique_ptr<clangd::SymbolIndex> getClient (llvm::StringRef Address) {
115
+ std::unique_ptr<clangd::SymbolIndex> getClient (llvm::StringRef Address,
116
+ llvm::StringRef ProjectRoot) {
101
117
const auto Channel =
102
118
grpc::CreateChannel (Address.str (), grpc::InsecureChannelCredentials ());
103
119
Channel->GetState (true );
104
- return std::unique_ptr<clangd::SymbolIndex>(new IndexClient (Channel));
120
+ return std::unique_ptr<clangd::SymbolIndex>(
121
+ new IndexClient (Channel, ProjectRoot));
105
122
}
106
123
107
124
} // namespace remote
0 commit comments