From 79373ba48681b31085d412b2d8d8646be605110d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 29 Sep 2018 20:26:55 -0700 Subject: [PATCH] Rename some initialization options * Delete index.enabled which can be achieved with index.blacklist: ['.'] * Move completion.include* to completion.include.* * move largeFileSize to highlight.largeFileSize --- src/config.h | 65 ++++++++++++++++++++--------------------- src/include_complete.cc | 20 ++++++------- src/indexer.cc | 3 -- src/message_handler.cc | 2 +- src/pipeline.cc | 2 +- 5 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/config.h b/src/config.h index 4ff79a92..8889f94b 100644 --- a/src/config.h +++ b/src/config.h @@ -130,25 +130,27 @@ struct Config { // that implement their own filtering and sorting logic. bool filterAndSort = true; - // Regex patterns to match include completion candidates against. They - // receive the absolute file path. - // - // For example, to hide all files in a /CACHE/ folder, use ".*/CACHE/.*" - std::vector includeBlacklist; + struct Include { + // Regex patterns to match include completion candidates against. They + // receive the absolute file path. + // + // For example, to hide all files in a /CACHE/ folder, use ".*/CACHE/.*" + std::vector blacklist; - // Maximum path length to show in completion results. Paths longer than this - // will be elided with ".." put at the front. Set to 0 or a negative number - // to disable eliding. - int includeMaxPathSize = 30; + // Maximum path length to show in completion results. Paths longer than + // this will be elided with ".." put at the front. Set to 0 or a negative + // number to disable eliding. + int maxPathSize = 30; - // Whitelist that file paths will be tested against. If a file path does not - // end in one of these values, it will not be considered for - // auto-completion. An example value is { ".h", ".hpp" } - // - // This is significantly faster than using a regex. - std::vector includeSuffixWhitelist = {".h", ".hpp", ".hh", ".inc"}; + // Whitelist that file paths will be tested against. If a file path does + // not end in one of these values, it will not be considered for + // auto-completion. An example value is { ".h", ".hpp" } + // + // This is significantly faster than using a regex. + std::vector suffixWhitelist = {".h", ".hpp", ".hh", ".inc"}; - std::vector includeWhitelist; + std::vector whitelist; + } include; } completion; struct Diagnostics { @@ -176,6 +178,9 @@ struct Config { // Semantic highlighting struct Highlight { + // Disable semantic highlighting for files larger than the size. + int64_t largeFileSize = 2 * 1024 * 1024; + // true: LSP line/character; false: position bool lsRanges = false; @@ -201,9 +206,6 @@ struct Config { // - https://github.com/autozimu/LanguageClient-neovim/issues/224 int comments = 2; - // 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. @@ -227,15 +229,12 @@ struct Config { // Whether to reparse a file if write times of its dependencies have // changed. The file will always be reparsed if its own write time changes. - // 0: no, 1: only after initial load of project, 2: yes + // 0: no, 1: only during initial load of project, 2: yes int trackDependency = 2; std::vector whitelist; } index; - // Disable semantic highlighting for files larger than the size. - int64_t largeFileSize = 2 * 1024 * 1024; - struct WorkspaceSymbol { int caseSensitivity = 1; // Maximum workspace search results. @@ -258,24 +257,24 @@ MAKE_REFLECT_STRUCT(Config::Clang, excludeArgs, extraArgs, pathMappings, MAKE_REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport, snippetSupport); MAKE_REFLECT_STRUCT(Config::CodeLens, localVariables); +MAKE_REFLECT_STRUCT(Config::Completion::Include, blacklist, maxPathSize, + suffixWhitelist, whitelist); MAKE_REFLECT_STRUCT(Config::Completion, caseSensitivity, detailedLabel, - dropOldRequests, duplicateOptional, filterAndSort, - includeBlacklist, includeMaxPathSize, - includeSuffixWhitelist, includeWhitelist); + dropOldRequests, duplicateOptional, filterAndSort, include); 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, - initialBlacklist, initialWhitelist, multiVersion, - multiVersionBlacklist, multiVersionWhitelist, onChange, - threads, trackDependency, whitelist); +MAKE_REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist, + whitelist) +MAKE_REFLECT_STRUCT(Config::Index, blacklist, comments, initialBlacklist, + initialWhitelist, multiVersion, multiVersionBlacklist, + multiVersionWhitelist, onChange, threads, trackDependency, + whitelist); MAKE_REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort); MAKE_REFLECT_STRUCT(Config::Xref, container, maxNum); MAKE_REFLECT_STRUCT(Config, compilationDatabaseCommand, compilationDatabaseDirectory, cacheDirectory, cacheFormat, - clang, client, codeLens, completion, diagnostics, highlight, - index, largeFileSize, workspaceSymbol, xref); + index, workspaceSymbol, xref); extern Config *g_config; diff --git a/src/include_complete.cc b/src/include_complete.cc index 779b04b0..e634e189 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -35,13 +35,11 @@ struct CompletionCandidate { }; std::string ElideLongPath(const std::string &path) { - if (g_config->completion.includeMaxPathSize <= 0) + if (g_config->completion.include.maxPathSize <= 0 || + (int)path.size() <= g_config->completion.include.maxPathSize) return path; - if ((int)path.size() <= g_config->completion.includeMaxPathSize) - return path; - - size_t start = path.size() - g_config->completion.includeMaxPathSize; + size_t start = path.size() - g_config->completion.include.maxPathSize; return ".." + path.substr(start + 2); } @@ -113,11 +111,11 @@ void IncludeComplete::Rescan() { absolute_path_to_completion_item.clear(); inserted_paths.clear(); - if (!match_ && (g_config->completion.includeWhitelist.size() || - g_config->completion.includeBlacklist.size())) + if (!match_ && (g_config->completion.include.whitelist.size() || + g_config->completion.include.blacklist.size())) match_ = - std::make_unique(g_config->completion.includeWhitelist, - g_config->completion.includeBlacklist); + std::make_unique(g_config->completion.include.whitelist, + g_config->completion.include.blacklist); is_scanning = true; std::thread([this]() { @@ -156,7 +154,7 @@ void IncludeComplete::InsertCompletionItem(const std::string &absolute_path, } void IncludeComplete::AddFile(const std::string &absolute_path) { - if (!EndsWithAny(absolute_path, g_config->completion.includeSuffixWhitelist)) + if (!EndsWithAny(absolute_path, g_config->completion.include.suffixWhitelist)) return; if (match_ && !match_->IsMatch(absolute_path)) return; @@ -186,7 +184,7 @@ void IncludeComplete::InsertIncludesFromDirectory(std::string directory, directory, true /*recursive*/, false /*add_folder_to_path*/, [&](const std::string &path) { if (!include_cpp && - !EndsWithAny(path, g_config->completion.includeSuffixWhitelist)) + !EndsWithAny(path, g_config->completion.include.suffixWhitelist)) return; if (match_ && !match_->IsMatch(directory + path)) return; diff --git a/src/indexer.cc b/src/indexer.cc index 9299b4aa..ccc5b64f 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1245,9 +1245,6 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs, const std::vector &args, const std::vector> &remapped, bool &ok) { ok = true; - if (!g_config->index.enabled) - return {}; - auto PCH = std::make_shared(); llvm::IntrusiveRefCntPtr FS = vfs::getRealFileSystem(); std::shared_ptr CI = BuildCompilerInvocation(args, FS); diff --git a/src/message_handler.cc b/src/message_handler.cc index e1721976..98ef5dde 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -133,7 +133,7 @@ void EmitSemanticHighlighting(DB *db, WorkingFile *wfile, QueryFile *file) { static GroupMatch match(g_config->highlight.whitelist, g_config->highlight.blacklist); assert(file->def); - if (wfile->buffer_content.size() > g_config->largeFileSize || + if (wfile->buffer_content.size() > g_config->highlight.largeFileSize || !match.IsMatch(file->def->path)) return; diff --git a/src/pipeline.cc b/src/pipeline.cc index ed01feeb..f4e5cc1f 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -295,7 +295,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, path_to_index, entry.args, remapped, ok); if (!ok) { - if (g_config->index.enabled && request.id.Valid()) { + if (request.id.Valid()) { Out_Error out; out.id = request.id; out.error.code = lsErrorCodes::InternalError;