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; std::vector<std::string> whitelist;
} diagnostics; } 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 { struct Index {
// Attempt to convert calls of make* functions to constructors based on // Attempt to convert calls of make* functions to constructors based on
// hueristics. // hueristics.
@ -229,6 +238,9 @@ MAKE_REFLECT_STRUCT(Config::Diagnostics,
frequencyMs, frequencyMs,
onParse, onParse,
whitelist) whitelist)
MAKE_REFLECT_STRUCT(Config::Highlight,
blacklist,
whitelist)
MAKE_REFLECT_STRUCT(Config::Index, MAKE_REFLECT_STRUCT(Config::Index,
attributeMakeCallsToCtor, attributeMakeCallsToCtor,
blacklist, blacklist,
@ -258,6 +270,7 @@ MAKE_REFLECT_STRUCT(Config,
codeLens, codeLens,
completion, completion,
diagnostics, diagnostics,
highlight,
index, index,
workspaceSymbol, workspaceSymbol,
xref, xref,

View File

@ -6,10 +6,10 @@
void DiagnosticsEngine::Init(Config* config) { void DiagnosticsEngine::Init(Config* config) {
frequencyMs_ = config->diagnostics.frequencyMs; 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, void DiagnosticsEngine::Publish(WorkingFiles* working_files,
std::string path, std::string path,
std::vector<lsDiagnostic> diagnostics) { std::vector<lsDiagnostic> diagnostics) {

View File

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

View File

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

View File

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

View File

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