mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Conditionally allow reindex on didChange
This commit is contained in:
parent
4e76cdaaae
commit
bf011fef71
@ -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.
|
||||||
|
@ -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(),
|
||||||
|
@ -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,6 +45,7 @@ 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
|
||||||
|
if (!config->enableIndexOnDidChange) {
|
||||||
optional<std::string> content = ReadContent(path);
|
optional<std::string> content = ReadContent(path);
|
||||||
if (!content) {
|
if (!content) {
|
||||||
LOG_S(ERROR) << "Unable to read file content after saving " << path;
|
LOG_S(ERROR) << "Unable to read file content after saving " << path;
|
||||||
@ -54,6 +56,7 @@ struct TextDocumentDidSaveHandler
|
|||||||
*content, ICacheManager::Make(config)),
|
*content, ICacheManager::Make(config)),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clang_complete->NotifySave(path);
|
clang_complete->NotifySave(path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user