10#include "clang/Index/IndexSymbol.h"
11#include "llvm/ADT/StringExtras.h"
12#include "llvm/Support/Regex.h"
20 size_t Pos = QName.rfind(
"::");
21 if (
Pos == llvm::StringRef::npos) {
25 Sym.
Name = QName.substr(
Pos + 2);
26 Sym.
Scope = QName.substr(0,
Pos + 2);
31static std::string
replace(llvm::StringRef Haystack, llvm::StringRef Needle,
32 llvm::StringRef Repl) {
33 llvm::SmallVector<llvm::StringRef> Parts;
34 Haystack.split(Parts, Needle);
35 return llvm::join(Parts, Repl);
41 llvm::StringRef USRFormat, llvm::StringRef
Signature) {
43 std::string
USR =
"c:";
44 size_t Pos = QName.rfind(
"::");
45 if (
Pos == llvm::StringRef::npos) {
49 Sym.
Name = QName.substr(
Pos + 2);
50 Sym.
Scope = QName.substr(0,
Pos + 2);
53 USR += llvm::Regex(
"^.*$").sub(USRFormat, Sym.
Name);
63 return sym(
Name, index::SymbolKind::Function,
"@F@\\0#");
67 return sym(
Name, index::SymbolKind::Class,
"@S@\\0");
71 return sym(
Name, index::SymbolKind::Enum,
"@E@\\0");
75 return sym(
Name, index::SymbolKind::EnumConstant,
"@\\0");
79 return sym(
Name, index::SymbolKind::Variable,
"@\\0");
83 return sym(
Name, index::SymbolKind::Namespace,
"@N@\\0");
87 return sym(
Name, index::SymbolKind::Concept,
"@CT@\\0");
91 return sym(
Name, index::SymbolKind::Macro,
"@macro@\\0", ArgList);
95 llvm::StringRef USRPrefix) {
97 std::string
USR = USRPrefix.str() +
Name.str();
102 Sym.
SymInfo.Lang = index::SymbolLanguage::ObjC;
109 return objcSym(
Name, index::SymbolKind::Class,
"objc(cs)");
113 std::string USRPrefix = (
"objc(cy)" +
Name +
"@").str();
114 return objcSym(CategoryName, index::SymbolKind::Extension, USRPrefix);
118 return objcSym(
Name, index::SymbolKind::Protocol,
"objc(pl)");
123 for (llvm::StringRef QName : QualifiedNames)
125 return std::move(Slab).build();
129 std::vector<std::string> Names;
130 for (
int I = Begin; I <= End; I++)
131 Names.push_back(std::to_string(I));
141 std::vector<std::string> Matches;
146 *Incomplete = IsIncomplete;
152 llvm::ArrayRef<SymbolID> IDs) {
154 Req.
IDs.insert(IDs.begin(), IDs.end());
155 std::vector<std::string>
Results;
llvm::SmallString< 256U > Name
std::vector< CodeCompletionResult > Results
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
virtual bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const =0
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
virtual void lookup(const LookupRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const =0
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
An immutable symbol container that stores a set of symbols.
static std::string replace(llvm::StringRef Haystack, llvm::StringRef Needle, llvm::StringRef Repl)
Symbol objcProtocol(llvm::StringRef Name)
Symbol objcClass(llvm::StringRef Name)
Symbol func(llvm::StringRef Name)
Symbol cls(llvm::StringRef Name)
Symbol objcCategory(llvm::StringRef Name, llvm::StringRef CategoryName)
Symbol conceptSym(llvm::StringRef Name)
Symbol sym(llvm::StringRef QName, index::SymbolKind Kind, llvm::StringRef USRFormat, llvm::StringRef Signature)
Symbol ns(llvm::StringRef Name)
Symbol objcSym(llvm::StringRef Name, index::SymbolKind Kind, llvm::StringRef USRPrefix)
std::vector< std::string > match(const SymbolIndex &I, const FuzzyFindRequest &Req, bool *Incomplete)
Symbol symbol(llvm::StringRef QName)
Symbol enm(llvm::StringRef Name)
Symbol macro(llvm::StringRef Name, llvm::StringRef ArgList)
SymbolSlab generateSymbols(std::vector< std::string > QualifiedNames)
std::string getQualifiedName(const Symbol &Sym)
std::vector< std::string > lookup(const SymbolIndex &I, llvm::ArrayRef< SymbolID > IDs)
Symbol enmConstant(llvm::StringRef Name)
SymbolSlab generateNumSymbols(int Begin, int End)
Symbol var(llvm::StringRef Name)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::DenseSet< SymbolID > IDs
The class presents a C++ symbol, e.g.
@ IndexedForCodeCompletion
Whether or not this symbol is meant to be used for the code completion.
index::SymbolInfo SymInfo
The symbol information, like symbol kind.
llvm::StringRef Name
The unqualified name of the symbol, e.g. "bar" (for ns::bar).
llvm::StringRef Scope
The containing namespace. e.g. "" (global), "ns::" (top-level namespace).
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list.
llvm::StringRef TemplateSpecializationArgs
Argument list in human-readable format, will be displayed to help disambiguate between different spec...
SymbolID ID
The ID of the symbol.
SymbolOrigin Origin
Where this symbol came from. Usually an index provides a constant value.