diff --git a/src/command_line.cc b/src/command_line.cc index aab64bff..bc1d60bc 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -645,6 +645,7 @@ void RegisterMessageTypes() { MessageRegistry::instance()->Register(); MessageRegistry::instance()->Register(); MessageRegistry::instance()->Register(); + MessageRegistry::instance()->Register(); MessageRegistry::instance()->Register(); MessageRegistry::instance()->Register(); MessageRegistry::instance()->Register(); @@ -1888,6 +1889,25 @@ bool QueryDbMainLoop(Config* config, break; } + case IpcId::CqueryTextDocumentDidView: { + auto msg = message->As(); + std::string path = msg->params.textDocumentUri.GetPath(); + + WorkingFile* working_file = working_files->GetFileByFilename(path); + if (!working_file) + break; + QueryFile* file = nullptr; + if (!FindFileOrFail(db, nullopt, path, &file)) + break; + + clang_complete->NotifyView(path); + if (file->def) { + EmitInactiveLines(working_file, file->def->inactive_regions); + EmitSemanticHighlighting(db, semantic_cache, working_file, file); + } + break; + } + case IpcId::TextDocumentDidChange: { auto msg = message->As(); std::string path = msg->params.textDocument.uri.GetPath(); @@ -2834,16 +2854,6 @@ bool QueryDbMainLoop(Config* config, ipc->SendOutMessageToClient(IpcId::TextDocumentCodeLens, response); - // TODO: We need to move this to a separate request, as the user may - // have turned code lens off (ie, a custom DidView notification). - if (file && file->def) { - WorkingFile* working_file = - working_files->GetFileByFilename(file->def->path); - EmitInactiveLines(working_file, file->def->inactive_regions); - // Do not emit semantic highlighting information here, as it has not - // been updated. - } - break; } @@ -3069,6 +3079,7 @@ void LaunchStdinLoop(Config* config, case IpcId::Initialize: case IpcId::TextDocumentDidOpen: + case IpcId::CqueryTextDocumentDidView: case IpcId::TextDocumentDidChange: case IpcId::TextDocumentDidClose: case IpcId::TextDocumentDidSave: diff --git a/src/ipc.cc b/src/ipc.cc index e9b31495..d92cd5a7 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -49,6 +49,8 @@ const char* IpcIdToString(IpcId id) { case IpcId::WorkspaceSymbol: return "workspace/symbol"; + case IpcId::CqueryTextDocumentDidView: + return "$cquery/textDocumentDidView"; case IpcId::CqueryPublishInactiveRegions: return "$cquery/publishInactiveRegions"; case IpcId::CqueryPublishSemanticHighlighting: diff --git a/src/ipc.h b/src/ipc.h index c1e6824c..6ac12760 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -31,6 +31,9 @@ enum class IpcId : int { WorkspaceSymbol, // Custom notifications + // Comes from the client. Does various things, like update semantic + // highlighting. + CqueryTextDocumentDidView, CqueryPublishInactiveRegions, CqueryPublishSemanticHighlighting, diff --git a/src/language_server_api.h b/src/language_server_api.h index 73d09915..08202910 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -969,7 +969,7 @@ struct Ipc_CancelRequest : public IpcMessage { }; MAKE_REFLECT_STRUCT(Ipc_CancelRequest, id); -// Open, update, close file +// Open, view, change, close file struct Ipc_TextDocumentDidOpen : public IpcMessage { struct Params { lsTextDocumentItem textDocument; @@ -980,6 +980,17 @@ struct Ipc_TextDocumentDidOpen : public IpcMessage { }; MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument); MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen, params); +struct Ipc_CqueryTextDocumentDidView + : public IpcMessage { + struct Params { + lsDocumentUri textDocumentUri; + }; + + const static IpcId kIpcId = IpcId::CqueryTextDocumentDidView; + Params params; +}; +MAKE_REFLECT_STRUCT(Ipc_CqueryTextDocumentDidView::Params, textDocumentUri); +MAKE_REFLECT_STRUCT(Ipc_CqueryTextDocumentDidView, params); struct Ipc_TextDocumentDidChange : public IpcMessage { struct lsTextDocumentContentChangeEvent {