mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
renames
This commit is contained in:
parent
c4a9590398
commit
5a2acf17ab
@ -37,7 +37,7 @@ struct IndexTranslationUnitResponse {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Rename TypedBidiMessageQueue to IpcTransport?
|
// TODO: Rename TypedBidiMessageQueue to IpcTransport?
|
||||||
using IpcMessageQueue = TypedBidiMessageQueue<lsMethodId, InMessage>;
|
using IpcMessageQueue = TypedBidiMessageQueue<lsMethodId, BaseIpcMessage>;
|
||||||
using IndexRequestQueue = ThreadedQueue<IndexTranslationUnitRequest>;
|
using IndexRequestQueue = ThreadedQueue<IndexTranslationUnitRequest>;
|
||||||
using IndexResponseQueue = ThreadedQueue<IndexTranslationUnitResponse>;
|
using IndexResponseQueue = ThreadedQueue<IndexTranslationUnitResponse>;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ bool HasOption(const std::unordered_map<std::string, std::string>& options,
|
|||||||
return options.find(option) != options.end();
|
return options.find(option) != options.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<InMessage> ParseMessage() {
|
std::unique_ptr<BaseIpcMessage> ParseMessage() {
|
||||||
int content_length = -1;
|
int content_length = -1;
|
||||||
int iteration = 0;
|
int iteration = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -134,51 +134,46 @@ std::string Join(const std::vector<std::string>& elements, std::string sep) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
struct Ipc_Quit : public IpcMessage<Ipc_Quit> {
|
||||||
struct BaseIpcMessage : public InMessage {
|
|
||||||
BaseIpcMessage() : InMessage(T::kMethod) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IpcMessage_Quit : public BaseIpcMessage<IpcMessage_Quit> {
|
|
||||||
static constexpr lsMethodId kMethod = lsMethodId::Quit;
|
static constexpr lsMethodId kMethod = lsMethodId::Quit;
|
||||||
};
|
};
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_Quit& value) {}
|
void Reflect(TVisitor& visitor, Ipc_Quit& value) {}
|
||||||
|
|
||||||
struct IpcMessage_IsAlive : public BaseIpcMessage<IpcMessage_IsAlive> {
|
struct Ipc_IsAlive : public IpcMessage<Ipc_IsAlive> {
|
||||||
static constexpr lsMethodId kMethod = lsMethodId::IsAlive;
|
static constexpr lsMethodId kMethod = lsMethodId::IsAlive;
|
||||||
};
|
};
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_IsAlive& value) {}
|
void Reflect(TVisitor& visitor, Ipc_IsAlive& value) {}
|
||||||
|
|
||||||
struct IpcMessage_OpenProject : public BaseIpcMessage<IpcMessage_OpenProject> {
|
struct Ipc_OpenProject : public IpcMessage<Ipc_OpenProject> {
|
||||||
static constexpr lsMethodId kMethod = lsMethodId::OpenProject;
|
static constexpr lsMethodId kMethod = lsMethodId::OpenProject;
|
||||||
std::string project_path;
|
std::string project_path;
|
||||||
};
|
};
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_OpenProject& value) {
|
void Reflect(TVisitor& visitor, Ipc_OpenProject& value) {
|
||||||
Reflect(visitor, value.project_path);
|
Reflect(visitor, value.project_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IpcMessage_Cout : public BaseIpcMessage<IpcMessage_Cout> {
|
struct Ipc_Cout : public IpcMessage<Ipc_Cout> {
|
||||||
static constexpr lsMethodId kMethod = lsMethodId::Cout;
|
static constexpr lsMethodId kMethod = lsMethodId::Cout;
|
||||||
std::string content;
|
std::string content;
|
||||||
|
|
||||||
IpcMessage_Cout() {}
|
Ipc_Cout() {}
|
||||||
IpcMessage_Cout(lsOutMessage& message) {
|
Ipc_Cout(lsOutMessage& message) {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
message.Send(out);
|
message.Send(out);
|
||||||
content = out.str();
|
content = out.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_Cout& value) {
|
void Reflect(TVisitor& visitor, Ipc_Cout& value) {
|
||||||
Reflect(visitor, value.content);
|
Reflect(visitor, value.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendOutMessageToClient(IpcMessageQueue* queue, lsOutMessage& response) {
|
void SendOutMessageToClient(IpcMessageQueue* queue, lsOutMessage& response) {
|
||||||
IpcMessage_Cout out(response);
|
Ipc_Cout out(response);
|
||||||
queue->SendMessage(&queue->for_client, IpcMessage_Cout::kMethod, out);
|
queue->SendMessage(&queue->for_client, Ipc_Cout::kMethod, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -186,7 +181,7 @@ void SendOutMessageToClient(IpcMessageQueue* queue, lsOutMessage& response) {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void RegisterId(IpcMessageQueue* t) {
|
void RegisterId(IpcMessageQueue* t) {
|
||||||
t->RegisterId(T::kMethod,
|
t->RegisterId(T::kMethod,
|
||||||
[](Writer& visitor, InMessage& message) {
|
[](Writer& visitor, BaseIpcMessage& message) {
|
||||||
T& m = static_cast<T&>(message);
|
T& m = static_cast<T&>(message);
|
||||||
Reflect(visitor, m);
|
Reflect(visitor, m);
|
||||||
}, [](Reader& visitor) {
|
}, [](Reader& visitor) {
|
||||||
@ -198,144 +193,30 @@ void RegisterId(IpcMessageQueue* t) {
|
|||||||
|
|
||||||
std::unique_ptr<IpcMessageQueue> BuildIpcMessageQueue(const std::string& name, size_t buffer_size) {
|
std::unique_ptr<IpcMessageQueue> BuildIpcMessageQueue(const std::string& name, size_t buffer_size) {
|
||||||
auto ipc = MakeUnique<IpcMessageQueue>(name, buffer_size);
|
auto ipc = MakeUnique<IpcMessageQueue>(name, buffer_size);
|
||||||
RegisterId<In_CancelRequest>(ipc.get());
|
RegisterId<Ipc_CancelRequest>(ipc.get());
|
||||||
RegisterId<In_InitializeRequest>(ipc.get());
|
RegisterId<Ipc_InitializeRequest>(ipc.get());
|
||||||
RegisterId<In_InitializedNotification>(ipc.get());
|
RegisterId<Ipc_InitializedNotification>(ipc.get());
|
||||||
RegisterId<In_DocumentSymbolRequest>(ipc.get());
|
RegisterId<Ipc_TextDocumentDocumentSymbol>(ipc.get());
|
||||||
RegisterId<In_DocumentCodeLensRequest>(ipc.get());
|
RegisterId<Ipc_TextDocumentCodeLens>(ipc.get());
|
||||||
RegisterId<In_DocumentCodeLensResolveRequest>(ipc.get());
|
RegisterId<Ipc_CodeLensResolve>(ipc.get());
|
||||||
RegisterId<In_WorkspaceSymbolRequest>(ipc.get());
|
RegisterId<Ipc_WorkspaceSymbol>(ipc.get());
|
||||||
RegisterId<IpcMessage_Quit>(ipc.get());
|
RegisterId<Ipc_Quit>(ipc.get());
|
||||||
RegisterId<IpcMessage_IsAlive>(ipc.get());
|
RegisterId<Ipc_IsAlive>(ipc.get());
|
||||||
RegisterId<IpcMessage_OpenProject>(ipc.get());
|
RegisterId<Ipc_OpenProject>(ipc.get());
|
||||||
RegisterId<IpcMessage_Cout>(ipc.get());
|
RegisterId<Ipc_Cout>(ipc.get());
|
||||||
return ipc;
|
return ipc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterMessageTypes() {
|
void RegisterMessageTypes() {
|
||||||
MessageRegistry::instance()->Register<In_CancelRequest>();
|
MessageRegistry::instance()->Register<Ipc_CancelRequest>();
|
||||||
MessageRegistry::instance()->Register<In_InitializeRequest>();
|
MessageRegistry::instance()->Register<Ipc_InitializeRequest>();
|
||||||
MessageRegistry::instance()->Register<In_InitializedNotification>();
|
MessageRegistry::instance()->Register<Ipc_InitializedNotification>();
|
||||||
MessageRegistry::instance()->Register<In_DocumentSymbolRequest>();
|
MessageRegistry::instance()->Register<Ipc_TextDocumentDocumentSymbol>();
|
||||||
MessageRegistry::instance()->Register<In_DocumentCodeLensRequest>();
|
MessageRegistry::instance()->Register<Ipc_TextDocumentCodeLens>();
|
||||||
MessageRegistry::instance()->Register<In_DocumentCodeLensResolveRequest>();
|
MessageRegistry::instance()->Register<Ipc_CodeLensResolve>();
|
||||||
MessageRegistry::instance()->Register<In_WorkspaceSymbolRequest>();
|
MessageRegistry::instance()->Register<Ipc_WorkspaceSymbol>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if false
|
|
||||||
struct IpcMessage_DocumentSymbolsRequest
|
|
||||||
: public BaseIpcMessage<IpcMessage_DocumentSymbolsRequest> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::DocumentSymbolsRequest;
|
|
||||||
RequestId request_id;
|
|
||||||
std::string document;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_DocumentSymbolsRequest& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(document);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_DocumentSymbolsResponse
|
|
||||||
: public BaseIpcMessage<IpcMessage_DocumentSymbolsResponse> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::DocumentSymbolsResponse;
|
|
||||||
RequestId request_id;
|
|
||||||
std::vector<lsSymbolInformation> symbols;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_DocumentSymbolsResponse& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(symbols);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_WorkspaceSymbolsRequest
|
|
||||||
: public BaseIpcMessage<IpcMessage_WorkspaceSymbolsRequest> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::WorkspaceSymbolsRequest;
|
|
||||||
RequestId request_id;
|
|
||||||
std::string query;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_WorkspaceSymbolsRequest& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(query);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_DocumentCodeLensRequest
|
|
||||||
: public BaseIpcMessage<IpcMessage_DocumentCodeLensRequest> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::DocumentCodeLensRequest;
|
|
||||||
RequestId request_id;
|
|
||||||
std::string document;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_DocumentCodeLensRequest& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(document);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_DocumentCodeLensResponse
|
|
||||||
: public BaseIpcMessage<IpcMessage_DocumentCodeLensResponse> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::DocumentCodeLensResponse;
|
|
||||||
RequestId request_id;
|
|
||||||
std::vector<TCodeLens> code_lens;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_DocumentCodeLensResponse& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(code_lens);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_CodeLensResolveRequest
|
|
||||||
: public BaseIpcMessage<IpcMessage_CodeLensResolveRequest> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::CodeLensResolveRequest;
|
|
||||||
RequestId request_id;
|
|
||||||
TCodeLens code_lens;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_CodeLensResolveRequest& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(code_lens);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_CodeLensResolveResponse
|
|
||||||
: public BaseIpcMessage<IpcMessage_CodeLensResolveResponse> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::CodeLensResolveResponse;
|
|
||||||
RequestId request_id;
|
|
||||||
TCodeLens code_lens;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_CodeLensResolveResponse& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(code_lens);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IpcMessage_WorkspaceSymbolsResponse
|
|
||||||
: public BaseIpcMessage<IpcMessage_WorkspaceSymbolsResponse> {
|
|
||||||
static constexpr IpcId kIpcId = IpcId::WorkspaceSymbolsResponse;
|
|
||||||
RequestId request_id;
|
|
||||||
std::vector<lsSymbolInformation> symbols;
|
|
||||||
};
|
|
||||||
template <typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, IpcMessage_WorkspaceSymbolsResponse& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(request_id);
|
|
||||||
REFLECT_MEMBER(symbols);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
||||||
while (true) {
|
while (true) {
|
||||||
// Try to get a request. If there isn't one, sleep for a little while.
|
// Try to get a request. If there isn't one, sleep for a little while.
|
||||||
@ -489,7 +370,7 @@ void QueryDbMainLoop(
|
|||||||
IpcMessageQueue* language_client,
|
IpcMessageQueue* language_client,
|
||||||
IndexRequestQueue* index_requests,
|
IndexRequestQueue* index_requests,
|
||||||
IndexResponseQueue* index_responses) {
|
IndexResponseQueue* index_responses) {
|
||||||
std::vector<std::unique_ptr<InMessage>> messages = language_client->GetMessages(&language_client->for_server);
|
std::vector<std::unique_ptr<BaseIpcMessage>> messages = language_client->GetMessages(&language_client->for_server);
|
||||||
for (auto& message : messages) {
|
for (auto& message : messages) {
|
||||||
// std::cerr << "Processing message " << static_cast<int>(message->ipc_id)
|
// std::cerr << "Processing message " << static_cast<int>(message->ipc_id)
|
||||||
// << std::endl;
|
// << std::endl;
|
||||||
@ -502,14 +383,13 @@ void QueryDbMainLoop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case lsMethodId::IsAlive: {
|
case lsMethodId::IsAlive: {
|
||||||
IpcMessage_IsAlive response;
|
Ipc_IsAlive response;
|
||||||
language_client->SendMessage(&language_client->for_client, response.method_id, response);
|
language_client->SendMessage(&language_client->for_client, response.method_id, response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case lsMethodId::OpenProject: {
|
case lsMethodId::OpenProject: {
|
||||||
IpcMessage_OpenProject* msg =
|
Ipc_OpenProject* msg = static_cast<Ipc_OpenProject*>(message.get());
|
||||||
static_cast<IpcMessage_OpenProject*>(message.get());
|
|
||||||
std::string path = msg->project_path;
|
std::string path = msg->project_path;
|
||||||
|
|
||||||
std::vector<CompilationEntry> entries =
|
std::vector<CompilationEntry> entries =
|
||||||
@ -531,9 +411,9 @@ void QueryDbMainLoop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case lsMethodId::TextDocumentDocumentSymbol: {
|
case lsMethodId::TextDocumentDocumentSymbol: {
|
||||||
auto msg = static_cast<In_DocumentSymbolRequest*>(message.get());
|
auto msg = static_cast<Ipc_TextDocumentDocumentSymbol*>(message.get());
|
||||||
|
|
||||||
Out_DocumentSymbolResponse response;
|
Out_TextDocumentDocumentSymbol response;
|
||||||
response.id = msg->id;
|
response.id = msg->id;
|
||||||
|
|
||||||
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
|
QueryableFile* file = FindFile(db, msg->params.textDocument.uri.GetPath());
|
||||||
@ -596,9 +476,9 @@ void QueryDbMainLoop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case lsMethodId::TextDocumentCodeLens: {
|
case lsMethodId::TextDocumentCodeLens: {
|
||||||
auto msg = static_cast<In_DocumentCodeLensRequest*>(message.get());
|
auto msg = static_cast<Ipc_TextDocumentCodeLens*>(message.get());
|
||||||
|
|
||||||
Out_DocumentCodeLensResponse response;
|
Out_TextDocumentCodeLens response;
|
||||||
response.id = msg->id;
|
response.id = msg->id;
|
||||||
|
|
||||||
lsDocumentUri file_as_uri = msg->params.textDocument.uri;
|
lsDocumentUri file_as_uri = msg->params.textDocument.uri;
|
||||||
@ -651,9 +531,9 @@ void QueryDbMainLoop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case lsMethodId::WorkspaceSymbol: {
|
case lsMethodId::WorkspaceSymbol: {
|
||||||
auto msg = static_cast<In_WorkspaceSymbolRequest*>(message.get());
|
auto msg = static_cast<Ipc_WorkspaceSymbol*>(message.get());
|
||||||
|
|
||||||
Out_WorkspaceSymbolResponse response;
|
Out_WorkspaceSymbol response;
|
||||||
response.id = msg->id;
|
response.id = msg->id;
|
||||||
|
|
||||||
|
|
||||||
@ -797,7 +677,7 @@ void QueryDbMain() {
|
|||||||
// |ipc| is connected to a server.
|
// |ipc| is connected to a server.
|
||||||
void LanguageServerStdinLoop(IpcMessageQueue* ipc) {
|
void LanguageServerStdinLoop(IpcMessageQueue* ipc) {
|
||||||
while (true) {
|
while (true) {
|
||||||
std::unique_ptr<InMessage> message = ParseMessage();
|
std::unique_ptr<BaseIpcMessage> message = ParseMessage();
|
||||||
|
|
||||||
// Message parsing can fail if we don't recognize the method.
|
// Message parsing can fail if we don't recognize the method.
|
||||||
if (!message)
|
if (!message)
|
||||||
@ -809,15 +689,15 @@ void LanguageServerStdinLoop(IpcMessageQueue* ipc) {
|
|||||||
// TODO: For simplicitly lets just proxy the initialize request like
|
// TODO: For simplicitly lets just proxy the initialize request like
|
||||||
// all other requests so that stdin loop thread becomes super simple.
|
// all other requests so that stdin loop thread becomes super simple.
|
||||||
case lsMethodId::Initialize: {
|
case lsMethodId::Initialize: {
|
||||||
auto request = static_cast<In_InitializeRequest*>(message.get());
|
auto request = static_cast<Ipc_InitializeRequest*>(message.get());
|
||||||
if (request->params.rootUri) {
|
if (request->params.rootUri) {
|
||||||
std::string project_path = request->params.rootUri->GetPath();
|
std::string project_path = request->params.rootUri->GetPath();
|
||||||
std::cerr << "Initialize in directory " << project_path
|
std::cerr << "Initialize in directory " << project_path
|
||||||
<< " with uri " << request->params.rootUri->raw_uri
|
<< " with uri " << request->params.rootUri->raw_uri
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
IpcMessage_OpenProject open_project;
|
Ipc_OpenProject open_project;
|
||||||
open_project.project_path = project_path;
|
open_project.project_path = project_path;
|
||||||
ipc->SendMessage(&ipc->for_server, IpcMessage_OpenProject::kMethod, open_project);
|
ipc->SendMessage(&ipc->for_server, Ipc_OpenProject::kMethod, open_project);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto response = Out_InitializeResponse();
|
auto response = Out_InitializeResponse();
|
||||||
@ -842,7 +722,7 @@ void LanguageServerStdinLoop(IpcMessageQueue* ipc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LanguageServerMainLoop(IpcMessageQueue* ipc) {
|
void LanguageServerMainLoop(IpcMessageQueue* ipc) {
|
||||||
std::vector<std::unique_ptr<InMessage>> messages = ipc->GetMessages(&ipc->for_client);
|
std::vector<std::unique_ptr<BaseIpcMessage>> messages = ipc->GetMessages(&ipc->for_client);
|
||||||
for (auto& message : messages) {
|
for (auto& message : messages) {
|
||||||
switch (message->method_id) {
|
switch (message->method_id) {
|
||||||
case lsMethodId::Quit: {
|
case lsMethodId::Quit: {
|
||||||
@ -852,7 +732,7 @@ void LanguageServerMainLoop(IpcMessageQueue* ipc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case lsMethodId::Cout: {
|
case lsMethodId::Cout: {
|
||||||
auto msg = static_cast<IpcMessage_Cout*>(message.get());
|
auto msg = static_cast<Ipc_Cout*>(message.get());
|
||||||
std::cout << msg->content;
|
std::cout << msg->content;
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
break;
|
break;
|
||||||
@ -869,14 +749,14 @@ void LanguageServerMainLoop(IpcMessageQueue* ipc) {
|
|||||||
|
|
||||||
bool IsQueryDbProcessRunning(IpcMessageQueue* ipc) {
|
bool IsQueryDbProcessRunning(IpcMessageQueue* ipc) {
|
||||||
// Emit an alive check. Sleep so the server has time to respond.
|
// Emit an alive check. Sleep so the server has time to respond.
|
||||||
IpcMessage_IsAlive check_alive;
|
Ipc_IsAlive check_alive;
|
||||||
SendMessage(*ipc, &ipc->for_server, check_alive);
|
SendMessage(*ipc, &ipc->for_server, check_alive);
|
||||||
|
|
||||||
// TODO: Tune this value or make it configurable.
|
// TODO: Tune this value or make it configurable.
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
// Check if we got an IsAlive message back.
|
// Check if we got an IsAlive message back.
|
||||||
std::vector<std::unique_ptr<InMessage>> messages = ipc->GetMessages(&ipc->for_client);
|
std::vector<std::unique_ptr<BaseIpcMessage>> messages = ipc->GetMessages(&ipc->for_client);
|
||||||
for (auto& message : messages) {
|
for (auto& message : messages) {
|
||||||
if (lsMethodId::IsAlive == message->method_id)
|
if (lsMethodId::IsAlive == message->method_id)
|
||||||
return true;
|
return true;
|
||||||
|
@ -142,13 +142,13 @@ const char* MethodIdToString(lsMethodId id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InMessage;
|
struct BaseIpcMessage;
|
||||||
|
|
||||||
struct MessageRegistry {
|
struct MessageRegistry {
|
||||||
static MessageRegistry* instance_;
|
static MessageRegistry* instance_;
|
||||||
static MessageRegistry* instance();
|
static MessageRegistry* instance();
|
||||||
|
|
||||||
using Allocator = std::function<std::unique_ptr<InMessage>(Reader& visitor)>;
|
using Allocator = std::function<std::unique_ptr<BaseIpcMessage>(Reader& visitor)>;
|
||||||
std::unordered_map<std::string, Allocator> allocators;
|
std::unordered_map<std::string, Allocator> allocators;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -161,7 +161,7 @@ struct MessageRegistry {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<InMessage> Parse(Reader& visitor) {
|
std::unique_ptr<BaseIpcMessage> Parse(Reader& visitor) {
|
||||||
std::string jsonrpc = visitor["jsonrpc"].GetString();
|
std::string jsonrpc = visitor["jsonrpc"].GetString();
|
||||||
if (jsonrpc != "2.0")
|
if (jsonrpc != "2.0")
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -187,17 +187,14 @@ MessageRegistry* MessageRegistry::instance() {
|
|||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InMessage {
|
struct BaseIpcMessage {
|
||||||
const lsMethodId method_id;
|
const lsMethodId method_id;
|
||||||
InMessage(lsMethodId method_id) : method_id(method_id) {}
|
BaseIpcMessage(lsMethodId method_id) : method_id(method_id) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InRequestMessage : public InMessage {
|
template <typename T>
|
||||||
InRequestMessage(lsMethodId method) : InMessage(method) {}
|
struct IpcMessage : public BaseIpcMessage {
|
||||||
};
|
IpcMessage() : BaseIpcMessage(T::kMethod) {}
|
||||||
|
|
||||||
struct InNotificationMessage : public InMessage {
|
|
||||||
InNotificationMessage(lsMethodId method) : InMessage(method) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lsOutMessage {
|
struct lsOutMessage {
|
||||||
@ -333,20 +330,6 @@ struct OutNotificationMessage : public lsOutMessage {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct In_CancelRequest : public InNotificationMessage {
|
|
||||||
static const lsMethodId kMethod = lsMethodId::CancelRequest;
|
|
||||||
|
|
||||||
RequestId id;
|
|
||||||
|
|
||||||
In_CancelRequest() : InNotificationMessage(kMethod) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename TVisitor>
|
|
||||||
void Reflect(TVisitor& visitor, In_CancelRequest& value) {
|
|
||||||
REFLECT_MEMBER_START();
|
|
||||||
REFLECT_MEMBER(id);
|
|
||||||
REFLECT_MEMBER_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1261,17 +1244,15 @@ void Reflect(TVisitor& visitor, lsInitializeResult& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct In_InitializeRequest : public InRequestMessage {
|
struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest>{
|
||||||
const static lsMethodId kMethod = lsMethodId::Initialize;
|
const static lsMethodId kMethod = lsMethodId::Initialize;
|
||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
lsInitializeParams params;
|
lsInitializeParams params;
|
||||||
|
|
||||||
In_InitializeRequest() : InRequestMessage(kMethod) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, In_InitializeRequest& value) {
|
void Reflect(TVisitor& visitor, Ipc_InitializeRequest& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
REFLECT_MEMBER(params);
|
REFLECT_MEMBER(params);
|
||||||
@ -1287,16 +1268,13 @@ struct Out_InitializeResponse : public OutResponseMessage {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct In_InitializedNotification : public InNotificationMessage {
|
struct Ipc_InitializedNotification : public IpcMessage<Ipc_InitializedNotification>{
|
||||||
const static lsMethodId kMethod = lsMethodId::Initialized;
|
const static lsMethodId kMethod = lsMethodId::Initialized;
|
||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
|
|
||||||
In_InitializedNotification() : InNotificationMessage(kMethod) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, In_InitializedNotification& value) {
|
void Reflect(TVisitor& visitor, Ipc_InitializedNotification& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
@ -1344,12 +1322,21 @@ void Reflect(TVisitor& visitor, In_InitializedNotification& value) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct Ipc_CancelRequest : public IpcMessage<Ipc_CancelRequest> {
|
||||||
|
static const lsMethodId kMethod = lsMethodId::CancelRequest;
|
||||||
|
RequestId id;
|
||||||
|
};
|
||||||
|
template<typename TVisitor>
|
||||||
|
void Reflect(TVisitor& visitor, Ipc_CancelRequest& value) {
|
||||||
|
REFLECT_MEMBER_START();
|
||||||
|
REFLECT_MEMBER(id);
|
||||||
|
REFLECT_MEMBER_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct lsDocumentSymbolParams {
|
struct lsDocumentSymbolParams {
|
||||||
lsTextDocumentIdentifier textDocument;
|
lsTextDocumentIdentifier textDocument;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, lsDocumentSymbolParams& value) {
|
void Reflect(TVisitor& visitor, lsDocumentSymbolParams& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
@ -1357,24 +1344,22 @@ void Reflect(TVisitor& visitor, lsDocumentSymbolParams& value) {
|
|||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct In_DocumentSymbolRequest : public InRequestMessage {
|
struct Ipc_TextDocumentDocumentSymbol : public IpcMessage<Ipc_TextDocumentDocumentSymbol>{
|
||||||
const static lsMethodId kMethod = lsMethodId::TextDocumentDocumentSymbol;
|
const static lsMethodId kMethod = lsMethodId::TextDocumentDocumentSymbol;
|
||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
lsDocumentSymbolParams params;
|
lsDocumentSymbolParams params;
|
||||||
|
|
||||||
In_DocumentSymbolRequest() : InRequestMessage(kMethod) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, In_DocumentSymbolRequest& value) {
|
void Reflect(TVisitor& visitor, Ipc_TextDocumentDocumentSymbol& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
REFLECT_MEMBER(params);
|
REFLECT_MEMBER(params);
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Out_DocumentSymbolResponse : public OutResponseMessage {
|
// TODO: refactor OutResponseMessage so we have a normal Reflect visitor (ie, remove 'hidden' base state)
|
||||||
|
struct Out_TextDocumentDocumentSymbol : public OutResponseMessage {
|
||||||
std::vector<lsSymbolInformation> result;
|
std::vector<lsSymbolInformation> result;
|
||||||
|
|
||||||
// OutResponseMessage:
|
// OutResponseMessage:
|
||||||
@ -1390,7 +1375,6 @@ struct Out_DocumentSymbolResponse : public OutResponseMessage {
|
|||||||
struct lsDocumentCodeLensParams {
|
struct lsDocumentCodeLensParams {
|
||||||
lsTextDocumentIdentifier textDocument;
|
lsTextDocumentIdentifier textDocument;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, lsDocumentCodeLensParams& value) {
|
void Reflect(TVisitor& visitor, lsDocumentCodeLensParams& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
@ -1431,24 +1415,22 @@ void Reflect(Reader& visitor, lsCodeLensCommandArguments& value) {
|
|||||||
|
|
||||||
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
|
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
|
||||||
|
|
||||||
struct In_DocumentCodeLensRequest : public InRequestMessage {
|
struct Ipc_TextDocumentCodeLens : public IpcMessage<Ipc_TextDocumentCodeLens>{
|
||||||
const static lsMethodId kMethod = lsMethodId::TextDocumentCodeLens;
|
const static lsMethodId kMethod = lsMethodId::TextDocumentCodeLens;
|
||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
lsDocumentCodeLensParams params;
|
lsDocumentCodeLensParams params;
|
||||||
|
|
||||||
In_DocumentCodeLensRequest() : InRequestMessage(kMethod) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, In_DocumentCodeLensRequest& value) {
|
void Reflect(TVisitor& visitor, Ipc_TextDocumentCodeLens& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
REFLECT_MEMBER(params);
|
REFLECT_MEMBER(params);
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Out_DocumentCodeLensResponse : public OutResponseMessage {
|
struct Out_TextDocumentCodeLens : public OutResponseMessage {
|
||||||
std::vector<lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>> result;
|
std::vector<lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>> result;
|
||||||
|
|
||||||
// OutResponseMessage:
|
// OutResponseMessage:
|
||||||
@ -1457,24 +1439,22 @@ struct Out_DocumentCodeLensResponse : public OutResponseMessage {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct In_DocumentCodeLensResolveRequest : public InRequestMessage {
|
struct Ipc_CodeLensResolve : public IpcMessage<Ipc_CodeLensResolve>{
|
||||||
const static lsMethodId kMethod = lsMethodId::CodeLensResolve;
|
const static lsMethodId kMethod = lsMethodId::CodeLensResolve;
|
||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
TCodeLens params;
|
TCodeLens params;
|
||||||
|
|
||||||
In_DocumentCodeLensResolveRequest() : InRequestMessage(kMethod) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, In_DocumentCodeLensResolveRequest& value) {
|
void Reflect(TVisitor& visitor, Ipc_CodeLensResolve& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
REFLECT_MEMBER(params);
|
REFLECT_MEMBER(params);
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Out_DocumentCodeLensResolveResponse : public OutResponseMessage {
|
struct Out_CodeLensResolve : public OutResponseMessage {
|
||||||
TCodeLens result;
|
TCodeLens result;
|
||||||
|
|
||||||
// OutResponseMessage:
|
// OutResponseMessage:
|
||||||
@ -1501,24 +1481,22 @@ void Reflect(TVisitor& visitor, lsWorkspaceSymbolParams& value) {
|
|||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct In_WorkspaceSymbolRequest : public InRequestMessage {
|
struct Ipc_WorkspaceSymbol : public IpcMessage<Ipc_WorkspaceSymbol >{
|
||||||
const static lsMethodId kMethod = lsMethodId::WorkspaceSymbol;
|
const static lsMethodId kMethod = lsMethodId::WorkspaceSymbol;
|
||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
lsWorkspaceSymbolParams params;
|
lsWorkspaceSymbolParams params;
|
||||||
|
|
||||||
In_WorkspaceSymbolRequest() : InRequestMessage(kMethod) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, In_WorkspaceSymbolRequest& value) {
|
void Reflect(TVisitor& visitor, Ipc_WorkspaceSymbol& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
REFLECT_MEMBER(params);
|
REFLECT_MEMBER(params);
|
||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Out_WorkspaceSymbolResponse : public OutResponseMessage {
|
struct Out_WorkspaceSymbol : public OutResponseMessage {
|
||||||
std::vector<lsSymbolInformation> result;
|
std::vector<lsSymbolInformation> result;
|
||||||
|
|
||||||
// OutResponseMessage:
|
// OutResponseMessage:
|
||||||
|
Loading…
Reference in New Issue
Block a user