mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-27 10:02:03 +00:00
Conditionally allow reindex on didChange
This commit is contained in:
parent
7c1155392a
commit
c6ea1f1946
@ -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);
|
||||
|
||||
|
@ -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 <loguru/loguru.hpp>
|
||||
|
||||
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<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->DiagnosticsUpdate(
|
||||
std::monostate(),
|
||||
|
@ -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<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);
|
||||
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->NotifySave(path);
|
||||
|
Loading…
Reference in New Issue
Block a user