From 4420bcf76f5e7a8e6c2abbe2be9db95d715fa781 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 23 Sep 2018 18:45:41 -0700 Subject: [PATCH] Add index.initial{Blacklist,Whitelist} index.{blacklist,whitelist}: disable indexes thoroughly index.initial{Blacklist,Whitelist}: disable initial loading. will still be indexed after opening --- src/config.h | 9 ++++++++- src/project.cc | 31 ++++++++++++++----------------- src/project.h | 4 ---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/config.h b/src/config.h index 86a1d161..034012dd 100644 --- a/src/config.h +++ b/src/config.h @@ -192,6 +192,12 @@ struct Config { // If false, the indexer will be disabled. bool enabled = true; + // By default, all project entries will be indexed on initialization. Use + // these two options to exclude some. They can still be indexed after you + // open them. + std::vector initialBlacklist; + std::vector initialWhitelist; + // If not 0, a file will be indexed in each tranlation unit that includes it. int multiVersion = 0; @@ -247,7 +253,8 @@ MAKE_REFLECT_STRUCT(Config::Completion, caseSensitivity, detailedLabel, MAKE_REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave, spellChecking, whitelist) MAKE_REFLECT_STRUCT(Config::Highlight, lsRanges, blacklist, whitelist) -MAKE_REFLECT_STRUCT(Config::Index, blacklist, comments, enabled, multiVersion, +MAKE_REFLECT_STRUCT(Config::Index, blacklist, comments, enabled, + initialBlacklist, initialWhitelist, multiVersion, multiVersionBlacklist, multiVersionWhitelist, onChange, reparseForDependency, threads, whitelist); MAKE_REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort); diff --git a/src/project.cc b/src/project.cc index 47709b39..1eb3fda4 100644 --- a/src/project.cc +++ b/src/project.cc @@ -421,28 +421,25 @@ Project::FindCompilationEntryForFile(const std::string &filename) { return result; } -void Project::ForAllFilteredFiles( - std::function action) { - GroupMatch matcher(g_config->index.whitelist, g_config->index.blacklist); +void Project::Index(WorkingFiles *wfiles, lsRequestId id) { + auto &gi = g_config->index; + GroupMatch match(gi.whitelist, gi.blacklist), + match_i(gi.initialWhitelist, gi.initialBlacklist); for (int i = 0; i < entries.size(); ++i) { const Project::Entry &entry = entries[i]; - std::string failure_reason; - if (matcher.IsMatch(entry.filename, &failure_reason)) - action(i, entries[i]); - else { - LOG_V(1) << "[" << i + 1 << "/" << entries.size() << "]: Failed " - << failure_reason << "; skipping " << entry.filename; + std::string reason; + if (match.IsMatch(entry.filename, &reason) && + match_i.IsMatch(entry.filename, &reason)) { + bool interactive = wfiles->GetFileByFilename(entry.filename) != nullptr; + pipeline::Index( + entry.filename, entry.args, + interactive ? IndexMode::Normal : IndexMode::NonInteractive, id); + } else { + LOG_V(1) << "[" << i << "/" << entries.size() << "]: " << reason + << "; skip " << entry.filename; } } -} -void Project::Index(WorkingFiles *wfiles, lsRequestId id) { - ForAllFilteredFiles([&](int i, const Project::Entry &entry) { - bool interactive = wfiles->GetFileByFilename(entry.filename) != nullptr; - pipeline::Index(entry.filename, entry.args, - interactive ? IndexMode::Normal : IndexMode::NonInteractive, - id); - }); pipeline::loaded_ts = pipeline::tick; // Dummy request to indicate that project is loaded and // trigger refreshing semantic highlight for all working files. diff --git a/src/project.h b/src/project.h index b992e011..b0400fcf 100644 --- a/src/project.h +++ b/src/project.h @@ -55,9 +55,5 @@ struct Project { void SetArgsForFile(const std::vector &args, const std::string &path); - // Run |action| on every file in the project. - void - ForAllFilteredFiles(std::function action); - void Index(WorkingFiles *wfiles, lsRequestId id); };