12 #include "llvm/ADT/StringExtras.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/Support/Error.h" 15 #include "llvm/Support/raw_ostream.h" 39 return OS <<
"(none)";
46 return OS <<
"unknown";
47 constexpr
static char Sigils[] =
"ADSM4567";
48 for (
unsigned I = 0; I <
sizeof(Sigils); ++I)
49 if (static_cast<uint8_t>(O) & 1u << I)
62 return OS << llvm::StringRef(s).rtrim(
'|');
78 auto It = std::lower_bound(
79 Symbols.begin(), Symbols.end(), ID,
81 if (It != Symbols.end() && It->ID == ID)
88 visitStrings(S, [&](llvm::StringRef &V) { V = Strings.save(V); });
95 own(Symbols.back(), UniqueStrings);
97 auto &Copy = Symbols[R.first->second] = S;
98 own(Copy, UniqueStrings);
103 Symbols = {Symbols.begin(), Symbols.end()};
108 llvm::BumpPtrAllocator NewArena;
109 llvm::UniqueStringSaver
Strings(NewArena);
110 for (
auto &S : Symbols)
112 return SymbolSlab(std::move(NewArena), std::move(Symbols));
117 return OS <<
"Unknown";
118 static const std::vector<const char *>
Messages = {
"Decl",
"Def",
"Ref"};
119 bool VisitedOnce =
false;
120 for (
unsigned I = 0; I < Messages.size(); ++I) {
121 if (static_cast<uint8_t>(K) & 1u << I) {
138 M.back().Location.FileURI =
139 UniqueStrings.save(M.back().Location.FileURI).data();
145 std::vector<std::pair<SymbolID, llvm::ArrayRef<Ref>>>
Result;
146 Result.reserve(Refs.size());
148 for (
auto &Sym : Refs) {
149 auto &SymRefs = Sym.second;
152 SymRefs.erase(std::unique(SymRefs.begin(), SymRefs.end()), SymRefs.end());
154 NumRefs += SymRefs.size();
156 std::uninitialized_copy(SymRefs.begin(), SymRefs.end(),
Array);
157 Result.emplace_back(Sym.first, llvm::ArrayRef<Ref>(
Array, SymRefs.size()));
159 return RefSlab(std::move(Result), std::move(
Arena), NumRefs);
164 std::shared_ptr<SymbolIndex> Pin;
166 std::lock_guard<std::mutex> Lock(Mutex);
167 Pin = std::move(this->Index);
168 this->Index = std::move(Index);
171 std::shared_ptr<SymbolIndex> SwapIndex::snapshot()
const {
172 std::lock_guard<std::mutex> Lock(Mutex);
177 llvm::json::ObjectMapper O(Parameters);
180 O && O.map(
"Query", Request.
Query) && O.map(
"Scopes", Request.
Scopes) &&
181 O.map(
"AnyScope", Request.
AnyScope) && O.map(
"Limit", Limit) &&
184 if (OK && Limit <= std::numeric_limits<uint32_t>::max())
185 Request.
Limit = Limit;
190 return llvm::json::Object{
191 {
"Query", Request.
Query},
192 {
"Scopes", llvm::json::Array{Request.
Scopes}},
194 {
"Limit", Request.
Limit},
201 llvm::function_ref<
void(
const Symbol &)> CB)
const {
202 return snapshot()->fuzzyFind(R, CB);
205 llvm::function_ref<
void(
const Symbol &)> CB)
const {
206 return snapshot()->lookup(R, CB);
209 llvm::function_ref<
void(
const Ref &)> CB)
const {
210 return snapshot()->refs(R, CB);
213 return snapshot()->estimateMemoryUsage();
llvm::json::Value toJSON(const FuzzyFindRequest &Request)
bool AnyScope
If set to true, allow symbols from any scope.
void lookup(const LookupRequest &, llvm::function_ref< void(const Symbol &)>) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol...
void setColumn(uint32_t Column)
bool RestrictForCodeCompletion
If set to true, only symbols for completion support will be considered.
void log(Logger::Level, const llvm::formatv_object_base &)
void setLine(uint32_t Line)
std::vector< Symbol >::const_iterator const_iterator
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
const_iterator find(const SymbolID &SymID) const
void insert(const Symbol &S)
std::vector< std::string > Scopes
If this is non-empty, symbols must be in at least one of the scopes (e.g.
llvm::BumpPtrAllocator Arena
Whether or not this symbol is meant to be used for the code completion.
static constexpr uint32_t MaxColumn
void refs(const RefsRequest &, llvm::function_ref< void(const Ref &)>) const override
Finds all occurrences (e.g.
std::string Query
A query string for the fuzzy find.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request)
std::vector< llvm::StringRef > Strings
static void own(Symbol &S, llvm::UniqueStringSaver &Strings)
static constexpr uint32_t MaxLine
Position Start
The symbol range, using half-open range [Start, End).
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< std::string > ProximityPaths
Contextually relevant files (e.g.
bool fuzzyFind(const FuzzyFindRequest &, llvm::function_ref< void(const Symbol &)>) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning...
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
void insert(const SymbolID &ID, const Ref &S)
llvm::Optional< uint32_t > Limit
The number of top candidates to return.
Indicates if the symbol is deprecated.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
void reset(std::unique_ptr< SymbolIndex >)
void visitStrings(Symbol &S, const Callback &CB)
float quality(const Symbol &S)
const SymbolIndex * Index