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
This commit is contained in:
Fangrui Song 2018-09-29 20:26:55 -07:00
parent 8d61b1aadb
commit 083a629f90
5 changed files with 43 additions and 49 deletions

View File

@ -118,25 +118,27 @@ struct Config {
// that implement their own filtering and sorting logic. // that implement their own filtering and sorting logic.
bool filterAndSort = true; bool filterAndSort = true;
// Regex patterns to match include completion candidates against. They struct Include {
// receive the absolute file path. // 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<std::string> includeBlacklist; // For example, to hide all files in a /CACHE/ folder, use ".*/CACHE/.*"
std::vector<std::string> blacklist;
// Maximum path length to show in completion results. Paths longer than this // Maximum path length to show in completion results. Paths longer than
// will be elided with ".." put at the front. Set to 0 or a negative number // this will be elided with ".." put at the front. Set to 0 or a negative
// to disable eliding. // number to disable eliding.
int includeMaxPathSize = 30; int maxPathSize = 30;
// Whitelist that file paths will be tested against. If a file path does not // Whitelist that file paths will be tested against. If a file path does
// end in one of these values, it will not be considered for // not end in one of these values, it will not be considered for
// auto-completion. An example value is { ".h", ".hpp" } // auto-completion. An example value is { ".h", ".hpp" }
// //
// This is significantly faster than using a regex. // This is significantly faster than using a regex.
std::vector<std::string> includeSuffixWhitelist = {".h", ".hpp", ".hh", ".inc"}; std::vector<std::string> suffixWhitelist = {".h", ".hpp", ".hh", ".inc"};
std::vector<std::string> includeWhitelist; std::vector<std::string> whitelist;
} include;
} completion; } completion;
struct Diagnostics { struct Diagnostics {
@ -164,6 +166,9 @@ struct Config {
// Semantic highlighting // Semantic highlighting
struct Highlight { struct Highlight {
// Disable semantic highlighting for files larger than the size.
int64_t largeFileSize = 2 * 1024 * 1024;
// true: LSP line/character; false: position // true: LSP line/character; false: position
bool lsRanges = false; bool lsRanges = false;
@ -189,9 +194,6 @@ struct Config {
// - https://github.com/autozimu/LanguageClient-neovim/issues/224 // - https://github.com/autozimu/LanguageClient-neovim/issues/224
int comments = 2; int comments = 2;
// If false, the indexer will be disabled.
bool enabled = true;
// By default, all project entries will be indexed on initialization. Use // By default, all project entries will be indexed on initialization. Use
// these two options to exclude some. They can still be indexed after you // these two options to exclude some. They can still be indexed after you
// open them. // open them.
@ -215,15 +217,12 @@ struct Config {
// Whether to reparse a file if write times of its dependencies have // 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. // 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; int trackDependency = 2;
std::vector<std::string> whitelist; std::vector<std::string> whitelist;
} index; } index;
// Disable semantic highlighting for files larger than the size.
int64_t largeFileSize = 2 * 1024 * 1024;
struct WorkspaceSymbol { struct WorkspaceSymbol {
int caseSensitivity = 1; int caseSensitivity = 1;
// Maximum workspace search results. // Maximum workspace search results.
@ -246,24 +245,24 @@ MAKE_REFLECT_STRUCT(Config::Clang, excludeArgs, extraArgs, pathMappings,
MAKE_REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport, MAKE_REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport,
snippetSupport); snippetSupport);
MAKE_REFLECT_STRUCT(Config::CodeLens, localVariables); MAKE_REFLECT_STRUCT(Config::CodeLens, localVariables);
MAKE_REFLECT_STRUCT(Config::Completion::Include, blacklist, maxPathSize,
suffixWhitelist, whitelist);
MAKE_REFLECT_STRUCT(Config::Completion, caseSensitivity, detailedLabel, MAKE_REFLECT_STRUCT(Config::Completion, caseSensitivity, detailedLabel,
dropOldRequests, duplicateOptional, filterAndSort, dropOldRequests, duplicateOptional, filterAndSort, include);
includeBlacklist, includeMaxPathSize,
includeSuffixWhitelist, includeWhitelist);
MAKE_REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave, MAKE_REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave,
spellChecking, whitelist) spellChecking, whitelist)
MAKE_REFLECT_STRUCT(Config::Highlight, lsRanges, blacklist, whitelist) MAKE_REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist,
MAKE_REFLECT_STRUCT(Config::Index, blacklist, comments, enabled, whitelist)
initialBlacklist, initialWhitelist, multiVersion, MAKE_REFLECT_STRUCT(Config::Index, blacklist, comments, initialBlacklist,
multiVersionBlacklist, multiVersionWhitelist, onChange, initialWhitelist, multiVersion, multiVersionBlacklist,
threads, trackDependency, whitelist); multiVersionWhitelist, onChange, threads, trackDependency,
whitelist);
MAKE_REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort); MAKE_REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort);
MAKE_REFLECT_STRUCT(Config::Xref, container, maxNum); MAKE_REFLECT_STRUCT(Config::Xref, container, maxNum);
MAKE_REFLECT_STRUCT(Config, compilationDatabaseCommand, MAKE_REFLECT_STRUCT(Config, compilationDatabaseCommand,
compilationDatabaseDirectory, cacheDirectory, cacheFormat, compilationDatabaseDirectory, cacheDirectory, cacheFormat,
clang, client, codeLens, completion, diagnostics, highlight, clang, client, codeLens, completion, diagnostics, highlight,
index, largeFileSize, workspaceSymbol, xref); index, workspaceSymbol, xref);
extern Config *g_config; extern Config *g_config;

View File

@ -23,13 +23,11 @@ struct CompletionCandidate {
}; };
std::string ElideLongPath(const std::string &path) { 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; return path;
if ((int)path.size() <= g_config->completion.includeMaxPathSize) size_t start = path.size() - g_config->completion.include.maxPathSize;
return path;
size_t start = path.size() - g_config->completion.includeMaxPathSize;
return ".." + path.substr(start + 2); return ".." + path.substr(start + 2);
} }
@ -101,11 +99,11 @@ void IncludeComplete::Rescan() {
absolute_path_to_completion_item.clear(); absolute_path_to_completion_item.clear();
inserted_paths.clear(); inserted_paths.clear();
if (!match_ && (g_config->completion.includeWhitelist.size() || if (!match_ && (g_config->completion.include.whitelist.size() ||
g_config->completion.includeBlacklist.size())) g_config->completion.include.blacklist.size()))
match_ = match_ =
std::make_unique<GroupMatch>(g_config->completion.includeWhitelist, std::make_unique<GroupMatch>(g_config->completion.include.whitelist,
g_config->completion.includeBlacklist); g_config->completion.include.blacklist);
is_scanning = true; is_scanning = true;
std::thread([this]() { std::thread([this]() {
@ -144,7 +142,7 @@ void IncludeComplete::InsertCompletionItem(const std::string &absolute_path,
} }
void IncludeComplete::AddFile(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; return;
if (match_ && !match_->IsMatch(absolute_path)) if (match_ && !match_->IsMatch(absolute_path))
return; return;
@ -174,7 +172,7 @@ void IncludeComplete::InsertIncludesFromDirectory(std::string directory,
directory, true /*recursive*/, false /*add_folder_to_path*/, directory, true /*recursive*/, false /*add_folder_to_path*/,
[&](const std::string &path) { [&](const std::string &path) {
if (!include_cpp && if (!include_cpp &&
!EndsWithAny(path, g_config->completion.includeSuffixWhitelist)) !EndsWithAny(path, g_config->completion.include.suffixWhitelist))
return; return;
if (match_ && !match_->IsMatch(directory + path)) if (match_ && !match_->IsMatch(directory + path))
return; return;

View File

@ -1230,9 +1230,6 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs,
const std::vector<const char *> &args, const std::vector<const char *> &args,
const std::vector<std::pair<std::string, std::string>> &remapped, bool &ok) { const std::vector<std::pair<std::string, std::string>> &remapped, bool &ok) {
ok = true; ok = true;
if (!g_config->index.enabled)
return {};
auto PCH = std::make_shared<PCHContainerOperations>(); auto PCH = std::make_shared<PCHContainerOperations>();
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem(); llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
std::shared_ptr<CompilerInvocation> CI = BuildCompilerInvocation(args, FS); std::shared_ptr<CompilerInvocation> CI = BuildCompilerInvocation(args, FS);

View File

@ -121,7 +121,7 @@ void EmitSemanticHighlighting(DB *db, WorkingFile *wfile, QueryFile *file) {
static GroupMatch match(g_config->highlight.whitelist, static GroupMatch match(g_config->highlight.whitelist,
g_config->highlight.blacklist); g_config->highlight.blacklist);
assert(file->def); 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)) !match.IsMatch(file->def->path))
return; return;

View File

@ -283,7 +283,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
path_to_index, entry.args, remapped, ok); path_to_index, entry.args, remapped, ok);
if (!ok) { if (!ok) {
if (g_config->index.enabled && request.id.Valid()) { if (request.id.Valid()) {
Out_Error out; Out_Error out;
out.id = request.id; out.id = request.id;
out.error.code = lsErrorCodes::InternalError; out.error.code = lsErrorCodes::InternalError;