From bf011fef71ad60d04cb2924fc92d04bd2d9d4354 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Mon, 19 Mar 2018 21:28:11 +0100 Subject: [PATCH] Conditionally allow reindex on didChange --- src/config.h | 6 ++++++ src/messages/text_document_did_change.cc | 17 +++++++++++++++++ src/messages/text_document_did_save.cc | 23 +++++++++++++---------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/config.h b/src/config.h index 9ca7ab5b..9030a903 100644 --- a/src/config.h +++ b/src/config.h @@ -212,6 +212,10 @@ struct Config { bool sort = true; } workspaceSymbol; + // Allow indexing on textDocument/didChange. + // May be too slow for big projects, so it is off by default. + bool enableIndexOnDidChange = false; + struct Xref { // If true, |Location[]| response will include lexical container. bool container = false; @@ -272,6 +276,8 @@ MAKE_REFLECT_STRUCT(Config, index, workspaceSymbol, xref, + + enableIndexOnDidChange, dumpAST); diff --git a/src/messages/text_document_did_change.cc b/src/messages/text_document_did_change.cc index 90e6dc9c..d32f2097 100644 --- a/src/messages/text_document_did_change.cc +++ b/src/messages/text_document_did_change.cc @@ -1,6 +1,11 @@ +#include "cache_manager.h" #include "clang_complete.h" #include "message_handler.h" +#include "project.h" #include "working_files.h" +#include "queue_manager.h" + +#include namespace { struct Ipc_TextDocumentDidChange @@ -17,6 +22,18 @@ struct TextDocumentDidChangeHandler void Run(Ipc_TextDocumentDidChange* request) override { std::string path = request->params.textDocument.uri.GetPath(); working_files->OnChange(request->params); + if (config->enableIndexOnDidChange) { + optional 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); + } + } clang_complete->NotifyEdit(path); clang_complete->DiagnosticsUpdate( std::monostate(), diff --git a/src/messages/text_document_did_save.cc b/src/messages/text_document_did_save.cc index f7629287..3635d767 100644 --- a/src/messages/text_document_did_save.cc +++ b/src/messages/text_document_did_save.cc @@ -34,7 +34,8 @@ struct TextDocumentDidSaveHandler // Send out an index request, and copy the current buffer state so we // can update the cached index contents when the index is done. // - // We also do not index if there is already an index request. + // We also do not index if there is already an index request or if + // the client requested indexing on didChange instead. // // TODO: Cancel outgoing index request. Might be tricky to make // efficient since we have to cancel. @@ -44,15 +45,17 @@ struct TextDocumentDidSaveHandler // mutex and check to see if we should skip the current request. // if so, ignore that index response. // TODO: send as priority request - optional 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); + if (!config->enableIndexOnDidChange) { + optional 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); + } } clang_complete->NotifySave(path);