Add initialization options highlight.{blacklist,whitelist}

This commit is contained in:
Fangrui Song 2018-03-09 00:23:32 -08:00
parent ce6b7363c6
commit 3995a9d5b8
6 changed files with 27 additions and 3 deletions

View File

@ -158,6 +158,15 @@ struct Config {
std::vector<std::string> whitelist;
} diagnostics;
// Semantic highlighting
struct Highlight {
// Like index.{whitelist,blacklist}, don't publish semantic highlighting to
// blacklisted files.
std::vector<std::string> blacklist;
std::vector<std::string> whitelist;
} highlight;
struct Index {
// Attempt to convert calls of make* functions to constructors based on
// hueristics.
@ -229,6 +238,9 @@ MAKE_REFLECT_STRUCT(Config::Diagnostics,
frequencyMs,
onParse,
whitelist)
MAKE_REFLECT_STRUCT(Config::Highlight,
blacklist,
whitelist)
MAKE_REFLECT_STRUCT(Config::Index,
attributeMakeCallsToCtor,
blacklist,
@ -258,6 +270,7 @@ MAKE_REFLECT_STRUCT(Config,
codeLens,
completion,
diagnostics,
highlight,
index,
workspaceSymbol,
xref,

View File

@ -6,10 +6,10 @@
void DiagnosticsEngine::Init(Config* config) {
frequencyMs_ = config->diagnostics.frequencyMs;
match_ = MakeUnique<GroupMatch>(config->diagnostics.whitelist, config->diagnostics.blacklist);
match_ = MakeUnique<GroupMatch>(config->diagnostics.whitelist,
config->diagnostics.blacklist);
}
void DiagnosticsEngine::Publish(WorkingFiles* working_files,
std::string path,
std::vector<lsDiagnostic> diagnostics) {

View File

@ -122,6 +122,8 @@ void EmitSemanticHighlighting(QueryDatabase* db,
WorkingFile* working_file,
QueryFile* file) {
assert(file->def);
if (!semantic_cache->match_->IsMatch(file->def->path))
return;
auto semantic_cache_for_file =
semantic_cache->GetCacheForFile(file->def->path);

View File

@ -6,6 +6,7 @@
#include "platform.h"
#include "project.h"
#include "queue_manager.h"
#include "semantic_highlight_symbol_cache.h"
#include "serializers/json.h"
#include "timer.h"
#include "working_files.h"
@ -583,6 +584,7 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
Timer time;
diag_engine->Init(config);
semantic_cache->Init(config);
// Open up / load the project.
project->Load(config, config->extraClangArguments,

View File

@ -60,6 +60,11 @@ SemanticHighlightSymbolCache::Entry::GetMapForSymbol_(SymbolKind kind) {
SemanticHighlightSymbolCache::SemanticHighlightSymbolCache()
: cache_(kCacheSize) {}
void SemanticHighlightSymbolCache::Init(Config* config) {
match_ = MakeUnique<GroupMatch>(config->highlight.whitelist,
config->highlight.blacklist);
}
std::shared_ptr<SemanticHighlightSymbolCache::Entry>
SemanticHighlightSymbolCache::GetCacheForFile(const std::string& path) {
return cache_.Get(

View File

@ -1,6 +1,7 @@
#pragma once
#include "lru_cache.h"
#include "match.h"
#include "query.h"
#include <optional.h>
@ -34,8 +35,9 @@ struct SemanticHighlightSymbolCache {
constexpr static int kCacheSize = 10;
LruCache<std::string, Entry> cache_;
uint32_t next_stable_id_ = 0;
std::unique_ptr<GroupMatch> match_;
SemanticHighlightSymbolCache();
void Init(Config*);
std::shared_ptr<Entry> GetCacheForFile(const std::string& path);
};