diff --git a/src/config.h b/src/config.h index 04d10c06..2219a8a1 100644 --- a/src/config.h +++ b/src/config.h @@ -204,6 +204,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; @@ -259,7 +265,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 c2c44b0c..70802538 100644 --- a/src/project.cc +++ b/src/project.cc @@ -433,28 +433,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 e5582a40..125b2af0 100644 --- a/src/project.h +++ b/src/project.h @@ -67,9 +67,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); };