mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-23 16:15:07 +00:00
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:
parent
3c5ab61762
commit
5caf69056c
@ -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
|
||||
|
@ -13,9 +13,9 @@ using namespace ccls;
|
||||
#include <unordered_set>
|
||||
|
||||
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<In_CclsFreshenIndex> {
|
||||
struct Handler_CclsReload : BaseMessageHandler<In_CclsReload> {
|
||||
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<const QueryFile *> q;
|
||||
// |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
|
@ -236,13 +236,18 @@ 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;
|
||||
}
|
||||
|
11
src/query.cc
11
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 <typename Def>
|
||||
void DB::RemoveUsrs(SymbolKind kind, int file_id,
|
||||
const std::vector<std::pair<Usr, Def>> &to_remove) {
|
||||
|
@ -34,7 +34,7 @@ struct QueryFile {
|
||||
std::vector<IndexInclude> includes;
|
||||
// Parts of the file which are disabled.
|
||||
std::vector<Range> skipped_ranges;
|
||||
// Used by |$ccls/freshenIndex|.
|
||||
// Used by |$ccls/reload|.
|
||||
std::vector<std::string> dependencies;
|
||||
};
|
||||
|
||||
@ -155,6 +155,8 @@ struct DB {
|
||||
std::vector<QueryType> types;
|
||||
std::vector<QueryVar> vars;
|
||||
|
||||
void clear();
|
||||
|
||||
template <typename Def>
|
||||
void RemoveUsrs(SymbolKind kind, int file_id,
|
||||
const std::vector<std::pair<Usr, Def>> &to_remove);
|
||||
|
Loading…
Reference in New Issue
Block a user