diff --git a/src/config.h b/src/config.h index b9b30b65..f06397a5 100644 --- a/src/config.h +++ b/src/config.h @@ -158,6 +158,15 @@ struct Config { std::vector whitelist; } diagnostics; + // Semantic highlighting + struct Highlight { + // Like index.{whitelist,blacklist}, don't publish semantic highlighting to + // blacklisted files. + std::vector blacklist; + + std::vector 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, diff --git a/src/diagnostics_engine.cc b/src/diagnostics_engine.cc index 2c2fa92f..199a1aae 100644 --- a/src/diagnostics_engine.cc +++ b/src/diagnostics_engine.cc @@ -6,10 +6,10 @@ void DiagnosticsEngine::Init(Config* config) { frequencyMs_ = config->diagnostics.frequencyMs; - match_ = MakeUnique(config->diagnostics.whitelist, config->diagnostics.blacklist); + match_ = MakeUnique(config->diagnostics.whitelist, + config->diagnostics.blacklist); } - void DiagnosticsEngine::Publish(WorkingFiles* working_files, std::string path, std::vector diagnostics) { diff --git a/src/message_handler.cc b/src/message_handler.cc index 61e3da25..35ceae77 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -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); diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 27352ffc..2b8453af 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -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 { Timer time; diag_engine->Init(config); + semantic_cache->Init(config); // Open up / load the project. project->Load(config, config->extraClangArguments, diff --git a/src/semantic_highlight_symbol_cache.cc b/src/semantic_highlight_symbol_cache.cc index 60536f34..f3a55790 100644 --- a/src/semantic_highlight_symbol_cache.cc +++ b/src/semantic_highlight_symbol_cache.cc @@ -60,6 +60,11 @@ SemanticHighlightSymbolCache::Entry::GetMapForSymbol_(SymbolKind kind) { SemanticHighlightSymbolCache::SemanticHighlightSymbolCache() : cache_(kCacheSize) {} +void SemanticHighlightSymbolCache::Init(Config* config) { + match_ = MakeUnique(config->highlight.whitelist, + config->highlight.blacklist); +} + std::shared_ptr SemanticHighlightSymbolCache::GetCacheForFile(const std::string& path) { return cache_.Get( diff --git a/src/semantic_highlight_symbol_cache.h b/src/semantic_highlight_symbol_cache.h index 3a33f421..f540ecb9 100644 --- a/src/semantic_highlight_symbol_cache.h +++ b/src/semantic_highlight_symbol_cache.h @@ -1,6 +1,7 @@ #pragma once #include "lru_cache.h" +#include "match.h" #include "query.h" #include @@ -34,8 +35,9 @@ struct SemanticHighlightSymbolCache { constexpr static int kCacheSize = 10; LruCache cache_; uint32_t next_stable_id_ = 0; + std::unique_ptr match_; SemanticHighlightSymbolCache(); - + void Init(Config*); std::shared_ptr GetCacheForFile(const std::string& path); };