Conditionally allow reindex on didChange

This commit is contained in:
Boris Staletic 2018-03-19 21:28:11 +01:00 committed by Fangrui Song
parent 4e76cdaaae
commit bf011fef71
3 changed files with 36 additions and 10 deletions

View File

@ -212,6 +212,10 @@ struct Config {
bool sort = true; bool sort = true;
} workspaceSymbol; } workspaceSymbol;
// Allow indexing on textDocument/didChange.
// May be too slow for big projects, so it is off by default.
bool enableIndexOnDidChange = false;
struct Xref { struct Xref {
// If true, |Location[]| response will include lexical container. // If true, |Location[]| response will include lexical container.
bool container = false; bool container = false;
@ -273,6 +277,8 @@ MAKE_REFLECT_STRUCT(Config,
workspaceSymbol, workspaceSymbol,
xref, xref,
enableIndexOnDidChange,
dumpAST); dumpAST);
// Expected client version. We show an error if this doesn't match. // Expected client version. We show an error if this doesn't match.

View File

@ -1,6 +1,11 @@
#include "cache_manager.h"
#include "clang_complete.h" #include "clang_complete.h"
#include "message_handler.h" #include "message_handler.h"
#include "project.h"
#include "working_files.h" #include "working_files.h"
#include "queue_manager.h"
#include <loguru/loguru.hpp>
namespace { namespace {
struct Ipc_TextDocumentDidChange struct Ipc_TextDocumentDidChange
@ -17,6 +22,18 @@ struct TextDocumentDidChangeHandler
void Run(Ipc_TextDocumentDidChange* request) override { void Run(Ipc_TextDocumentDidChange* request) override {
std::string path = request->params.textDocument.uri.GetPath(); std::string path = request->params.textDocument.uri.GetPath();
working_files->OnChange(request->params); 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);
}
}
clang_complete->NotifyEdit(path); clang_complete->NotifyEdit(path);
clang_complete->DiagnosticsUpdate( clang_complete->DiagnosticsUpdate(
std::monostate(), std::monostate(),

View File

@ -34,7 +34,8 @@ struct TextDocumentDidSaveHandler
// Send out an index request, and copy the current buffer state so we // Send out an index request, and copy the current buffer state so we
// can update the cached index contents when the index is done. // 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 // TODO: Cancel outgoing index request. Might be tricky to make
// efficient since we have to cancel. // efficient since we have to cancel.
@ -44,15 +45,17 @@ struct TextDocumentDidSaveHandler
// mutex and check to see if we should skip the current request. // mutex and check to see if we should skip the current request.
// if so, ignore that index response. // if so, ignore that index response.
// TODO: send as priority request // TODO: send as priority request
optional<std::string> content = ReadContent(path); if (!config->enableIndexOnDidChange) {
if (!content) { optional<std::string> content = ReadContent(path);
LOG_S(ERROR) << "Unable to read file content after saving " << path; if (!content) {
} else { LOG_S(ERROR) << "Unable to read file content after saving " << path;
Project::Entry entry = project->FindCompilationEntryForFile(path); } else {
QueueManager::instance()->index_request.PushBack( Project::Entry entry = project->FindCompilationEntryForFile(path);
Index_Request(entry.filename, entry.args, true /*is_interactive*/, QueueManager::instance()->index_request.PushBack(
*content, ICacheManager::Make(config)), Index_Request(entry.filename, entry.args, true /*is_interactive*/,
true); *content, ICacheManager::Make(config)),
true);
}
} }
clang_complete->NotifySave(path); clang_complete->NotifySave(path);