tsl-devkit/lsp-server/src/language/symbol/store.hpp

31 lines
703 B
C++

#pragma once
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#include "./types.hpp"
namespace lsp::language::symbol
{
class SymbolStore
{
public:
SymbolId Add(Symbol def);
bool Remove(SymbolId id);
void Clear();
const Symbol* Get(SymbolId id) const;
std::vector<std::reference_wrapper<const Symbol>> GetAll() const;
std::vector<SymbolId> FindByName(const std::string& name) const;
private:
SymbolId next_id_ = 1;
std::unordered_map<SymbolId, Symbol> definitions_;
std::unordered_map<std::string, std::vector<SymbolId>> by_name_;
};
} // namespace lsp::language::symbol