mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
Merge textDocument_did{Change,Close,Open,Save}.cc
This commit is contained in:
parent
93b5fa198c
commit
ae19826411
@ -221,10 +221,7 @@ target_sources(ccls PRIVATE
|
|||||||
src/messages/textDocument_codeLens.cc
|
src/messages/textDocument_codeLens.cc
|
||||||
src/messages/textDocument_completion.cc
|
src/messages/textDocument_completion.cc
|
||||||
src/messages/textDocument_definition.cc
|
src/messages/textDocument_definition.cc
|
||||||
src/messages/textDocument_didChange.cc
|
src/messages/textDocument_did.cc
|
||||||
src/messages/textDocument_didClose.cc
|
|
||||||
src/messages/textDocument_didOpen.cc
|
|
||||||
src/messages/textDocument_didSave.cc
|
|
||||||
src/messages/textDocument_documentHighlight.cc
|
src/messages/textDocument_documentHighlight.cc
|
||||||
src/messages/textDocument_documentSymbol.cc
|
src/messages/textDocument_documentSymbol.cc
|
||||||
src/messages/textDocument_hover.cc
|
src/messages/textDocument_hover.cc
|
||||||
|
153
src/messages/textDocument_did.cc
Normal file
153
src/messages/textDocument_did.cc
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
// Copyright 2017-2018 ccls Authors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
#include "clang_complete.hh"
|
||||||
|
#include "include_complete.h"
|
||||||
|
#include "message_handler.h"
|
||||||
|
#include "pipeline.hh"
|
||||||
|
#include "project.h"
|
||||||
|
#include "working_files.h"
|
||||||
|
using namespace ccls;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
MethodType didChange = "textDocument/didChange";
|
||||||
|
MethodType didClose = "textDocument/didClose";
|
||||||
|
MethodType didOpen = "textDocument/didOpen";
|
||||||
|
MethodType didSave = "textDocument/didSave";
|
||||||
|
|
||||||
|
struct In_TextDocumentDidChange : public NotificationInMessage {
|
||||||
|
MethodType GetMethodType() const override { return didChange; }
|
||||||
|
lsTextDocumentDidChangeParams params;
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidChange, params);
|
||||||
|
REGISTER_IN_MESSAGE(In_TextDocumentDidChange);
|
||||||
|
|
||||||
|
struct Handler_TextDocumentDidChange
|
||||||
|
: BaseMessageHandler<In_TextDocumentDidChange> {
|
||||||
|
MethodType GetMethodType() const override { return didChange; }
|
||||||
|
|
||||||
|
void Run(In_TextDocumentDidChange *request) override {
|
||||||
|
const auto ¶ms = request->params;
|
||||||
|
std::string path = params.textDocument.uri.GetPath();
|
||||||
|
working_files->OnChange(params);
|
||||||
|
if (g_config->index.onChange)
|
||||||
|
pipeline::Index(path, {}, IndexMode::OnChange);
|
||||||
|
clang_complete->NotifyView(path);
|
||||||
|
if (g_config->diagnostics.onChange >= 0)
|
||||||
|
clang_complete->DiagnosticsUpdate(path, g_config->diagnostics.onChange);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidChange);
|
||||||
|
|
||||||
|
struct In_TextDocumentDidClose : public NotificationInMessage {
|
||||||
|
MethodType GetMethodType() const override { return didClose; }
|
||||||
|
struct Params {
|
||||||
|
lsTextDocumentIdentifier textDocument;
|
||||||
|
} params;
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidClose::Params, textDocument);
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidClose, params);
|
||||||
|
REGISTER_IN_MESSAGE(In_TextDocumentDidClose);
|
||||||
|
|
||||||
|
struct Handler_TextDocumentDidClose
|
||||||
|
: BaseMessageHandler<In_TextDocumentDidClose> {
|
||||||
|
MethodType GetMethodType() const override { return didClose; }
|
||||||
|
|
||||||
|
void Run(In_TextDocumentDidClose *request) override {
|
||||||
|
std::string path = request->params.textDocument.uri.GetPath();
|
||||||
|
|
||||||
|
// Clear any diagnostics for the file.
|
||||||
|
Out_TextDocumentPublishDiagnostics out;
|
||||||
|
out.params.uri = request->params.textDocument.uri;
|
||||||
|
pipeline::WriteStdout(didClose, out);
|
||||||
|
|
||||||
|
// Remove internal state.
|
||||||
|
working_files->OnClose(request->params.textDocument);
|
||||||
|
clang_complete->OnClose(path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidClose);
|
||||||
|
|
||||||
|
struct In_TextDocumentDidOpen : public NotificationInMessage {
|
||||||
|
MethodType GetMethodType() const override { return didOpen; }
|
||||||
|
|
||||||
|
struct Params {
|
||||||
|
lsTextDocumentItem textDocument;
|
||||||
|
|
||||||
|
// ccls extension
|
||||||
|
// If specified (e.g. ["clang++", "-DM", "a.cc"]), it overrides the project
|
||||||
|
// entry (e.g. loaded from compile_commands.json or .ccls).
|
||||||
|
std::vector<std::string> args;
|
||||||
|
} params;
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidOpen::Params, textDocument, args);
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidOpen, params);
|
||||||
|
REGISTER_IN_MESSAGE(In_TextDocumentDidOpen);
|
||||||
|
|
||||||
|
struct Handler_TextDocumentDidOpen
|
||||||
|
: BaseMessageHandler<In_TextDocumentDidOpen> {
|
||||||
|
MethodType GetMethodType() const override { return didOpen; }
|
||||||
|
|
||||||
|
void Run(In_TextDocumentDidOpen *request) override {
|
||||||
|
// NOTE: This function blocks code lens. If it starts taking a long time
|
||||||
|
// we will need to find a way to unblock the code lens request.
|
||||||
|
const auto ¶ms = request->params;
|
||||||
|
const std::string &path = params.textDocument.uri.GetPath();
|
||||||
|
|
||||||
|
WorkingFile *working_file = working_files->OnOpen(params.textDocument);
|
||||||
|
if (std::optional<std::string> cached_file_contents =
|
||||||
|
pipeline::LoadIndexedContent(path))
|
||||||
|
working_file->SetIndexContent(*cached_file_contents);
|
||||||
|
|
||||||
|
QueryFile *file = nullptr;
|
||||||
|
FindFileOrFail(db, project, std::nullopt, path, &file);
|
||||||
|
if (file && file->def) {
|
||||||
|
EmitSkippedRanges(working_file, file->def->skipped_ranges);
|
||||||
|
EmitSemanticHighlighting(db, working_file, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
include_complete->AddFile(working_file->filename);
|
||||||
|
std::vector<const char *> args;
|
||||||
|
for (const std::string &arg : params.args)
|
||||||
|
args.push_back(Intern(arg));
|
||||||
|
if (args.size())
|
||||||
|
project->SetArgsForFile(args, path);
|
||||||
|
|
||||||
|
// Submit new index request if it is not a header file.
|
||||||
|
if (SourceFileLanguage(path) != LanguageId::Unknown)
|
||||||
|
pipeline::Index(path, args, IndexMode::Normal);
|
||||||
|
|
||||||
|
clang_complete->NotifyView(path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidOpen);
|
||||||
|
|
||||||
|
struct In_TextDocumentDidSave : public NotificationInMessage {
|
||||||
|
MethodType GetMethodType() const override { return didSave; }
|
||||||
|
|
||||||
|
struct Params {
|
||||||
|
// The document that was saved.
|
||||||
|
lsTextDocumentIdentifier textDocument;
|
||||||
|
|
||||||
|
// Optional the content when saved. Depends on the includeText value
|
||||||
|
// when the save notifcation was requested.
|
||||||
|
// std::string text;
|
||||||
|
} params;
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidSave::Params, textDocument);
|
||||||
|
MAKE_REFLECT_STRUCT(In_TextDocumentDidSave, params);
|
||||||
|
REGISTER_IN_MESSAGE(In_TextDocumentDidSave);
|
||||||
|
|
||||||
|
struct Handler_TextDocumentDidSave
|
||||||
|
: BaseMessageHandler<In_TextDocumentDidSave> {
|
||||||
|
MethodType GetMethodType() const override { return didSave; }
|
||||||
|
|
||||||
|
void Run(In_TextDocumentDidSave *request) override {
|
||||||
|
const auto ¶ms = request->params;
|
||||||
|
const std::string &path = params.textDocument.uri.GetPath();
|
||||||
|
pipeline::Index(path, {}, IndexMode::Normal);
|
||||||
|
clang_complete->NotifySave(path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidSave);
|
||||||
|
} // namespace
|
@ -1,38 +0,0 @@
|
|||||||
// Copyright 2017-2018 ccls Authors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
#include "clang_complete.hh"
|
|
||||||
#include "message_handler.h"
|
|
||||||
#include "pipeline.hh"
|
|
||||||
#include "project.h"
|
|
||||||
#include "working_files.h"
|
|
||||||
using namespace ccls;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
MethodType kMethodType = "textDocument/didChange";
|
|
||||||
|
|
||||||
struct In_TextDocumentDidChange : public NotificationInMessage {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
lsTextDocumentDidChangeParams params;
|
|
||||||
};
|
|
||||||
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidChange, params);
|
|
||||||
REGISTER_IN_MESSAGE(In_TextDocumentDidChange);
|
|
||||||
|
|
||||||
struct Handler_TextDocumentDidChange
|
|
||||||
: BaseMessageHandler<In_TextDocumentDidChange> {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
|
|
||||||
void Run(In_TextDocumentDidChange *request) override {
|
|
||||||
const auto ¶ms = request->params;
|
|
||||||
std::string path = params.textDocument.uri.GetPath();
|
|
||||||
working_files->OnChange(params);
|
|
||||||
if (g_config->index.onChange)
|
|
||||||
pipeline::Index(path, {}, IndexMode::OnChange);
|
|
||||||
clang_complete->NotifyView(path);
|
|
||||||
if (g_config->diagnostics.onChange >= 0)
|
|
||||||
clang_complete->DiagnosticsUpdate(path, g_config->diagnostics.onChange);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidChange);
|
|
||||||
} // namespace
|
|
@ -1,41 +0,0 @@
|
|||||||
// Copyright 2017-2018 ccls Authors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
#include "clang_complete.hh"
|
|
||||||
#include "message_handler.h"
|
|
||||||
#include "pipeline.hh"
|
|
||||||
#include "working_files.h"
|
|
||||||
using namespace ccls;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
MethodType kMethodType = "textDocument/didClose";
|
|
||||||
|
|
||||||
struct In_TextDocumentDidClose : public NotificationInMessage {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
struct Params {
|
|
||||||
lsTextDocumentIdentifier textDocument;
|
|
||||||
} params;
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidClose::Params, textDocument);
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidClose, params);
|
|
||||||
REGISTER_IN_MESSAGE(In_TextDocumentDidClose);
|
|
||||||
|
|
||||||
struct Handler_TextDocumentDidClose
|
|
||||||
: BaseMessageHandler<In_TextDocumentDidClose> {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
|
|
||||||
void Run(In_TextDocumentDidClose *request) override {
|
|
||||||
std::string path = request->params.textDocument.uri.GetPath();
|
|
||||||
|
|
||||||
// Clear any diagnostics for the file.
|
|
||||||
Out_TextDocumentPublishDiagnostics out;
|
|
||||||
out.params.uri = request->params.textDocument.uri;
|
|
||||||
pipeline::WriteStdout(kMethodType, out);
|
|
||||||
|
|
||||||
// Remove internal state.
|
|
||||||
working_files->OnClose(request->params.textDocument);
|
|
||||||
clang_complete->OnClose(path);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidClose);
|
|
||||||
} // namespace
|
|
@ -1,68 +0,0 @@
|
|||||||
// Copyright 2017-2018 ccls Authors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
#include "clang_complete.hh"
|
|
||||||
#include "include_complete.h"
|
|
||||||
#include "message_handler.h"
|
|
||||||
#include "pipeline.hh"
|
|
||||||
#include "project.h"
|
|
||||||
#include "working_files.h"
|
|
||||||
using namespace ccls;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
MethodType kMethodType = "textDocument/didOpen";
|
|
||||||
|
|
||||||
struct In_TextDocumentDidOpen : public NotificationInMessage {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
|
|
||||||
struct Params {
|
|
||||||
lsTextDocumentItem textDocument;
|
|
||||||
|
|
||||||
// ccls extension
|
|
||||||
// If specified (e.g. ["clang++", "-DM", "a.cc"]), it overrides the project
|
|
||||||
// entry (e.g. loaded from compile_commands.json or .ccls).
|
|
||||||
std::vector<std::string> args;
|
|
||||||
} params;
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidOpen::Params, textDocument, args);
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidOpen, params);
|
|
||||||
REGISTER_IN_MESSAGE(In_TextDocumentDidOpen);
|
|
||||||
|
|
||||||
struct Handler_TextDocumentDidOpen
|
|
||||||
: BaseMessageHandler<In_TextDocumentDidOpen> {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
|
|
||||||
void Run(In_TextDocumentDidOpen *request) override {
|
|
||||||
// NOTE: This function blocks code lens. If it starts taking a long time
|
|
||||||
// we will need to find a way to unblock the code lens request.
|
|
||||||
const auto ¶ms = request->params;
|
|
||||||
const std::string &path = params.textDocument.uri.GetPath();
|
|
||||||
|
|
||||||
WorkingFile *working_file = working_files->OnOpen(params.textDocument);
|
|
||||||
if (std::optional<std::string> cached_file_contents =
|
|
||||||
pipeline::LoadIndexedContent(path))
|
|
||||||
working_file->SetIndexContent(*cached_file_contents);
|
|
||||||
|
|
||||||
QueryFile *file = nullptr;
|
|
||||||
FindFileOrFail(db, project, std::nullopt, path, &file);
|
|
||||||
if (file && file->def) {
|
|
||||||
EmitSkippedRanges(working_file, file->def->skipped_ranges);
|
|
||||||
EmitSemanticHighlighting(db, working_file, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
include_complete->AddFile(working_file->filename);
|
|
||||||
std::vector<const char *> args;
|
|
||||||
for (const std::string &arg : params.args)
|
|
||||||
args.push_back(Intern(arg));
|
|
||||||
if (args.size())
|
|
||||||
project->SetArgsForFile(args, path);
|
|
||||||
|
|
||||||
// Submit new index request if it is not a header file.
|
|
||||||
if (SourceFileLanguage(path) != LanguageId::Unknown)
|
|
||||||
pipeline::Index(path, args, IndexMode::Normal);
|
|
||||||
|
|
||||||
clang_complete->NotifyView(path);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidOpen);
|
|
||||||
} // namespace
|
|
@ -1,40 +0,0 @@
|
|||||||
// Copyright 2017-2018 ccls Authors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
#include "clang_complete.hh"
|
|
||||||
#include "message_handler.h"
|
|
||||||
#include "pipeline.hh"
|
|
||||||
using namespace ccls;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
MethodType kMethodType = "textDocument/didSave";
|
|
||||||
|
|
||||||
struct In_TextDocumentDidSave : public NotificationInMessage {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
|
|
||||||
struct Params {
|
|
||||||
// The document that was saved.
|
|
||||||
lsTextDocumentIdentifier textDocument;
|
|
||||||
|
|
||||||
// Optional the content when saved. Depends on the includeText value
|
|
||||||
// when the save notifcation was requested.
|
|
||||||
// std::string text;
|
|
||||||
} params;
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidSave::Params, textDocument);
|
|
||||||
MAKE_REFLECT_STRUCT(In_TextDocumentDidSave, params);
|
|
||||||
REGISTER_IN_MESSAGE(In_TextDocumentDidSave);
|
|
||||||
|
|
||||||
struct Handler_TextDocumentDidSave
|
|
||||||
: BaseMessageHandler<In_TextDocumentDidSave> {
|
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
|
||||||
|
|
||||||
void Run(In_TextDocumentDidSave *request) override {
|
|
||||||
const auto ¶ms = request->params;
|
|
||||||
const std::string &path = params.textDocument.uri.GetPath();
|
|
||||||
pipeline::Index(path, {}, IndexMode::Normal);
|
|
||||||
clang_complete->NotifySave(path);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidSave);
|
|
||||||
} // namespace
|
|
Loading…
Reference in New Issue
Block a user