2018-03-19 20:28:11 +00:00
|
|
|
#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"
|
2018-03-19 20:28:11 +00:00
|
|
|
#include "project.h"
|
2017-12-29 16:29:47 +00:00
|
|
|
#include "working_files.h"
|
2018-03-19 20:28:11 +00:00
|
|
|
#include "queue_manager.h"
|
|
|
|
|
|
|
|
#include <loguru/loguru.hpp>
|
2017-12-06 03:32:33 +00:00
|
|
|
|
2017-12-06 05:03:38 +00:00
|
|
|
namespace {
|
2017-12-06 04:39:44 +00:00
|
|
|
struct Ipc_TextDocumentDidChange
|
2018-01-19 08:56:09 +00:00
|
|
|
: public NotificationMessage<Ipc_TextDocumentDidChange> {
|
2017-12-06 04:39:44 +00:00
|
|
|
const static IpcId kIpcId = IpcId::TextDocumentDidChange;
|
|
|
|
lsTextDocumentDidChangeParams params;
|
|
|
|
};
|
|
|
|
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDidChange, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDidChange);
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
struct TextDocumentDidChangeHandler
|
|
|
|
: BaseMessageHandler<Ipc_TextDocumentDidChange> {
|
|
|
|
void Run(Ipc_TextDocumentDidChange* request) override {
|
|
|
|
std::string path = request->params.textDocument.uri.GetPath();
|
|
|
|
working_files->OnChange(request->params);
|
2018-03-19 20:28:11 +00:00
|
|
|
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(
|
2018-02-22 07:13:42 +00:00
|
|
|
std::monostate(),
|
2017-12-06 03:32:33 +00:00
|
|
|
request->params.textDocument.AsTextDocumentIdentifier());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(TextDocumentDidChangeHandler);
|
2017-12-31 03:18:33 +00:00
|
|
|
} // namespace
|