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.
This commit is contained in:
Fangrui Song 2018-09-11 23:31:06 -07:00
parent 3c5ab61762
commit 5caf69056c
5 changed files with 45 additions and 17 deletions

View File

@ -212,10 +212,10 @@ target_sources(ccls PRIVATE
src/messages/ccls_callHierarchy.cc src/messages/ccls_callHierarchy.cc
src/messages/ccls_callers.cc src/messages/ccls_callers.cc
src/messages/ccls_fileInfo.cc src/messages/ccls_fileInfo.cc
src/messages/ccls_freshenIndex.cc
src/messages/ccls_inheritanceHierarchy.cc src/messages/ccls_inheritanceHierarchy.cc
src/messages/ccls_memberHierarchy.cc src/messages/ccls_memberHierarchy.cc
src/messages/ccls_navigate.cc src/messages/ccls_navigate.cc
src/messages/ccls_reload.cc
src/messages/ccls_vars.cc src/messages/ccls_vars.cc
src/messages/exit.cc src/messages/exit.cc
src/messages/initialize.cc src/messages/initialize.cc

View File

@ -13,9 +13,9 @@ using namespace ccls;
#include <unordered_set> #include <unordered_set>
namespace { 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; } MethodType GetMethodType() const override { return kMethodType; }
struct Params { struct Params {
bool dependencies = true; bool dependencies = true;
@ -24,15 +24,28 @@ struct In_CclsFreshenIndex : public NotificationInMessage {
}; };
Params params; Params params;
}; };
MAKE_REFLECT_STRUCT(In_CclsFreshenIndex::Params, dependencies, whitelist, MAKE_REFLECT_STRUCT(In_CclsReload::Params, dependencies, whitelist,
blacklist); blacklist);
MAKE_REFLECT_STRUCT(In_CclsFreshenIndex, params); MAKE_REFLECT_STRUCT(In_CclsReload, params);
REGISTER_IN_MESSAGE(In_CclsFreshenIndex); REGISTER_IN_MESSAGE(In_CclsReload);
struct Handler_CclsFreshenIndex : BaseMessageHandler<In_CclsFreshenIndex> { struct Handler_CclsReload : BaseMessageHandler<In_CclsReload> {
MethodType GetMethodType() const override { return kMethodType; } MethodType GetMethodType() const override { return kMethodType; }
void Run(In_CclsFreshenIndex *request) override { void Run(In_CclsReload *request) override {
GroupMatch matcher(request->params.whitelist, request->params.blacklist); const auto &params = 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<const QueryFile *> q; std::queue<const QueryFile *> q;
// |need_index| stores every filename ever enqueued. // |need_index| stores every filename ever enqueued.
@ -77,10 +90,7 @@ struct Handler_CclsFreshenIndex : BaseMessageHandler<In_CclsFreshenIndex> {
} }
} }
} }
// Send index requests for every file.
project->Index(working_files, lsRequestId());
} }
}; };
REGISTER_MESSAGE_HANDLER(Handler_CclsFreshenIndex); REGISTER_MESSAGE_HANDLER(Handler_CclsReload);
} // namespace } // namespace

View File

@ -236,13 +236,18 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get()); IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
on_indexed->PushBack(std::move(update), on_indexed->PushBack(std::move(update),
request.mode != IndexMode::NonInteractive); request.mode != IndexMode::NonInteractive);
std::lock_guard lock(vfs->mutex);
vfs->state[path_to_index].loaded = true;
} }
for (const auto &dep : dependencies) for (const auto &dep : dependencies) {
if (vfs->Mark(dep.first().str(), 0, 2) && std::string path = dep.first().str();
(prev = RawCacheLoad(dep.first().str()))) { if (vfs->Mark(path, 0, 2) && (prev = RawCacheLoad(path))) {
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get()); IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
on_indexed->PushBack(std::move(update), on_indexed->PushBack(std::move(update),
request.mode != IndexMode::NonInteractive); request.mode != IndexMode::NonInteractive);
std::lock_guard lock(vfs->mutex);
vfs->state[path].loaded = true;
}
} }
return true; return true;
} }

View File

@ -136,6 +136,17 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile *previous, IndexFile *current) {
return r; 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 <typename Def> template <typename Def>
void DB::RemoveUsrs(SymbolKind kind, int file_id, void DB::RemoveUsrs(SymbolKind kind, int file_id,
const std::vector<std::pair<Usr, Def>> &to_remove) { const std::vector<std::pair<Usr, Def>> &to_remove) {

View File

@ -34,7 +34,7 @@ struct QueryFile {
std::vector<IndexInclude> includes; std::vector<IndexInclude> includes;
// Parts of the file which are disabled. // Parts of the file which are disabled.
std::vector<Range> skipped_ranges; std::vector<Range> skipped_ranges;
// Used by |$ccls/freshenIndex|. // Used by |$ccls/reload|.
std::vector<std::string> dependencies; std::vector<std::string> dependencies;
}; };
@ -155,6 +155,8 @@ struct DB {
std::vector<QueryType> types; std::vector<QueryType> types;
std::vector<QueryVar> vars; std::vector<QueryVar> vars;
void clear();
template <typename Def> template <typename Def>
void RemoveUsrs(SymbolKind kind, int file_id, void RemoveUsrs(SymbolKind kind, int file_id,
const std::vector<std::pair<Usr, Def>> &to_remove); const std::vector<std::pair<Usr, Def>> &to_remove);