From 5caf69056c0a015ce5bbfcae7d9608f2d966bf88 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 11 Sep 2018 23:31:06 -0700 Subject: [PATCH] Make $ccls/reload reset DB and reload cached index files $ccls/reload is renamed from $ccls/freshenIndex This is useful when DB (merged index) diverges from backing IndexFile. Also fix a semantic highlighting bug. --- CMakeLists.txt | 2 +- .../{ccls_freshenIndex.cc => ccls_reload.cc} | 34 ++++++++++++------- src/pipeline.cc | 11 ++++-- src/query.cc | 11 ++++++ src/query.h | 4 ++- 5 files changed, 45 insertions(+), 17 deletions(-) rename src/messages/{ccls_freshenIndex.cc => ccls_reload.cc} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9574aad8..01eead6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,10 +212,10 @@ target_sources(ccls PRIVATE src/messages/ccls_callHierarchy.cc src/messages/ccls_callers.cc src/messages/ccls_fileInfo.cc - src/messages/ccls_freshenIndex.cc src/messages/ccls_inheritanceHierarchy.cc src/messages/ccls_memberHierarchy.cc src/messages/ccls_navigate.cc + src/messages/ccls_reload.cc src/messages/ccls_vars.cc src/messages/exit.cc src/messages/initialize.cc diff --git a/src/messages/ccls_freshenIndex.cc b/src/messages/ccls_reload.cc similarity index 73% rename from src/messages/ccls_freshenIndex.cc rename to src/messages/ccls_reload.cc index 0efe0098..4d441d5e 100644 --- a/src/messages/ccls_freshenIndex.cc +++ b/src/messages/ccls_reload.cc @@ -13,9 +13,9 @@ using namespace ccls; #include namespace { -MethodType kMethodType = "$ccls/freshenIndex"; +MethodType kMethodType = "$ccls/reload"; -struct In_CclsFreshenIndex : public NotificationInMessage { +struct In_CclsReload : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { bool dependencies = true; @@ -24,15 +24,28 @@ struct In_CclsFreshenIndex : public NotificationInMessage { }; Params params; }; -MAKE_REFLECT_STRUCT(In_CclsFreshenIndex::Params, dependencies, whitelist, +MAKE_REFLECT_STRUCT(In_CclsReload::Params, dependencies, whitelist, blacklist); -MAKE_REFLECT_STRUCT(In_CclsFreshenIndex, params); -REGISTER_IN_MESSAGE(In_CclsFreshenIndex); +MAKE_REFLECT_STRUCT(In_CclsReload, params); +REGISTER_IN_MESSAGE(In_CclsReload); -struct Handler_CclsFreshenIndex : BaseMessageHandler { +struct Handler_CclsReload : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CclsFreshenIndex *request) override { - GroupMatch matcher(request->params.whitelist, request->params.blacklist); + void Run(In_CclsReload *request) override { + const auto ¶ms = request->params; + // Send index requests for every file. + if (params.whitelist.empty() && params.blacklist.empty()) { + { + std::lock_guard lock(vfs->mutex); + vfs->state.clear(); + } + db->clear(); + project->Index(working_files, lsRequestId()); + return; + } + + // TODO + GroupMatch matcher(params.whitelist, params.blacklist); std::queue q; // |need_index| stores every filename ever enqueued. @@ -77,10 +90,7 @@ struct Handler_CclsFreshenIndex : BaseMessageHandler { } } } - - // Send index requests for every file. - project->Index(working_files, lsRequestId()); } }; -REGISTER_MESSAGE_HANDLER(Handler_CclsFreshenIndex); +REGISTER_MESSAGE_HANDLER(Handler_CclsReload); } // namespace diff --git a/src/pipeline.cc b/src/pipeline.cc index 181f552a..49259d63 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -236,14 +236,19 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get()); on_indexed->PushBack(std::move(update), request.mode != IndexMode::NonInteractive); + std::lock_guard lock(vfs->mutex); + vfs->state[path_to_index].loaded = true; } - for (const auto &dep : dependencies) - if (vfs->Mark(dep.first().str(), 0, 2) && - (prev = RawCacheLoad(dep.first().str()))) { + for (const auto &dep : dependencies) { + std::string path = dep.first().str(); + if (vfs->Mark(path, 0, 2) && (prev = RawCacheLoad(path))) { IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get()); on_indexed->PushBack(std::move(update), request.mode != IndexMode::NonInteractive); + std::lock_guard lock(vfs->mutex); + vfs->state[path].loaded = true; } + } return true; } diff --git a/src/query.cc b/src/query.cc index 6d15965a..374c0d15 100644 --- a/src/query.cc +++ b/src/query.cc @@ -136,6 +136,17 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile *previous, IndexFile *current) { return r; } +void DB::clear() { + files.clear(); + name2file_id.clear(); + func_usr.clear(); + type_usr.clear(); + var_usr.clear(); + funcs.clear(); + types.clear(); + vars.clear(); +} + template void DB::RemoveUsrs(SymbolKind kind, int file_id, const std::vector> &to_remove) { diff --git a/src/query.h b/src/query.h index 1eaa6499..7241e177 100644 --- a/src/query.h +++ b/src/query.h @@ -34,7 +34,7 @@ struct QueryFile { std::vector includes; // Parts of the file which are disabled. std::vector skipped_ranges; - // Used by |$ccls/freshenIndex|. + // Used by |$ccls/reload|. std::vector dependencies; }; @@ -155,6 +155,8 @@ struct DB { std::vector types; std::vector vars; + void clear(); + template void RemoveUsrs(SymbolKind kind, int file_id, const std::vector> &to_remove);