Add $cquery/textDocumentDidView.

This allows for more stable semantic highlighting, among other potential features. Requires custom support from the client, though.
This commit is contained in:
Jacob Dufault 2017-12-03 14:35:22 -08:00
parent 697968b15f
commit ab7ffa302a
4 changed files with 38 additions and 11 deletions

View File

@ -645,6 +645,7 @@ void RegisterMessageTypes() {
MessageRegistry::instance()->Register<Ipc_InitializedNotification>();
MessageRegistry::instance()->Register<Ipc_Exit>();
MessageRegistry::instance()->Register<Ipc_TextDocumentDidOpen>();
MessageRegistry::instance()->Register<Ipc_CqueryTextDocumentDidView>();
MessageRegistry::instance()->Register<Ipc_TextDocumentDidChange>();
MessageRegistry::instance()->Register<Ipc_TextDocumentDidClose>();
MessageRegistry::instance()->Register<Ipc_TextDocumentDidSave>();
@ -1888,6 +1889,25 @@ bool QueryDbMainLoop(Config* config,
break;
}
case IpcId::CqueryTextDocumentDidView: {
auto msg = message->As<Ipc_CqueryTextDocumentDidView>();
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<Ipc_TextDocumentDidChange>();
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:

View File

@ -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:

View File

@ -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,

View File

@ -969,7 +969,7 @@ struct Ipc_CancelRequest : public IpcMessage<Ipc_CancelRequest> {
};
MAKE_REFLECT_STRUCT(Ipc_CancelRequest, id);
// Open, update, close file
// Open, view, change, close file
struct Ipc_TextDocumentDidOpen : public IpcMessage<Ipc_TextDocumentDidOpen> {
struct Params {
lsTextDocumentItem textDocument;
@ -980,6 +980,17 @@ struct Ipc_TextDocumentDidOpen : public IpcMessage<Ipc_TextDocumentDidOpen> {
};
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen::Params, textDocument);
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidOpen, params);
struct Ipc_CqueryTextDocumentDidView
: public IpcMessage<Ipc_CqueryTextDocumentDidView> {
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<Ipc_TextDocumentDidChange> {
struct lsTextDocumentContentChangeEvent {