2017-12-06 03:32:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "lru_cache.h"
|
|
|
|
#include "query.h"
|
|
|
|
|
2017-12-29 16:29:10 +00:00
|
|
|
#include <optional.h>
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
// Caches symbols for a single file for semantic highlighting to provide
|
|
|
|
// relatively stable ids. Only supports xxx files at a time.
|
|
|
|
struct SemanticHighlightSymbolCache {
|
|
|
|
struct Entry {
|
2017-12-22 15:29:13 +00:00
|
|
|
SemanticHighlightSymbolCache* all_caches_ = nullptr;
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
// The path this cache belongs to.
|
|
|
|
std::string path;
|
|
|
|
// Detailed symbol name to stable id.
|
|
|
|
using TNameToId = std::unordered_map<std::string, int>;
|
|
|
|
TNameToId detailed_type_name_to_stable_id;
|
|
|
|
TNameToId detailed_func_name_to_stable_id;
|
|
|
|
TNameToId detailed_var_name_to_stable_id;
|
|
|
|
|
2017-12-22 15:29:13 +00:00
|
|
|
Entry(SemanticHighlightSymbolCache* all_caches, const std::string& path);
|
2017-12-06 03:32:33 +00:00
|
|
|
|
2017-12-22 15:29:13 +00:00
|
|
|
optional<int> TryGetStableId(SymbolKind kind,
|
|
|
|
const std::string& detailed_name);
|
2017-12-06 03:32:33 +00:00
|
|
|
int GetStableId(SymbolKind kind, const std::string& detailed_name);
|
2017-12-22 15:29:13 +00:00
|
|
|
|
|
|
|
TNameToId* GetMapForSymbol_(SymbolKind kind);
|
2017-12-06 03:32:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constexpr static int kCacheSize = 10;
|
|
|
|
LruCache<std::string, Entry> cache_;
|
2017-12-22 15:29:13 +00:00
|
|
|
uint32_t next_stable_id_ = 0;
|
2017-12-06 03:32:33 +00:00
|
|
|
|
|
|
|
SemanticHighlightSymbolCache();
|
|
|
|
|
|
|
|
std::shared_ptr<Entry> GetCacheForFile(const std::string& path);
|
|
|
|
};
|