ccls/src/messages/text_document_did_change.cc

48 lines
1.6 KiB
C++
Raw Normal View History

#include "cache_manager.h"
2017-12-29 16:29:47 +00:00
#include "clang_complete.h"
2017-12-06 03:32:33 +00:00
#include "message_handler.h"
#include "project.h"
2017-12-29 16:29:47 +00:00
#include "working_files.h"
#include "queue_manager.h"
#include <loguru/loguru.hpp>
2017-12-06 03:32:33 +00:00
namespace {
MethodType kMethodType = "textDocument/didChange";
struct In_TextDocumentDidChange : public NotificationMessage {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
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; }
2017-12-06 04:39:44 +00:00
void Run(In_TextDocumentDidChange* request) override {
2017-12-06 03:32:33 +00:00
std::string path = request->params.textDocument.uri.GetPath();
working_files->OnChange(request->params);
if (config->enableIndexOnDidChange) {
optional<std::string> content = ReadContent(path);
if (!content) {
LOG_S(ERROR) << "Unable to read file content after saving " << path;
} else {
Project::Entry entry = project->FindCompilationEntryForFile(path);
QueueManager::instance()->index_request.PushBack(
Index_Request(entry.filename, entry.args, true /*is_interactive*/,
*content, ICacheManager::Make(config)),
true);
}
}
2017-12-06 03:32:33 +00:00
clang_complete->NotifyEdit(path);
clang_complete->DiagnosticsUpdate(
std::monostate(),
2017-12-06 03:32:33 +00:00
request->params.textDocument.AsTextDocumentIdentifier());
}
};
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidChange);
} // namespace