summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/FindSymbols.cpp
diff options
context:
space:
mode:
authorNathan Ridge <zeratul976@hotmail.com>2019-06-16 02:31:37 +0000
committerNathan Ridge <zeratul976@hotmail.com>2019-06-16 02:31:37 +0000
commita552508841adf1c24530141427354039a9371be1 (patch)
treeae8490dc0bacb3e2b5955ba061aa23e13ded4123 /clang-tools-extra/clangd/FindSymbols.cpp
parentf6db53422400794e3cdafc6839160f51a3f82b8d (diff)
downloadbcm5719-llvm-a552508841adf1c24530141427354039a9371be1.tar.gz
bcm5719-llvm-a552508841adf1c24530141427354039a9371be1.zip
[clangd] Type hierarchy subtypes
Summary: This builds on the relations support added in D59407, D62459, D62471, and D62839 to implement type hierarchy subtypes. Reviewers: kadircet Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58880 llvm-svn: 363506
Diffstat (limited to 'clang-tools-extra/clangd/FindSymbols.cpp')
-rw-r--r--clang-tools-extra/clangd/FindSymbols.cpp60
1 files changed, 36 insertions, 24 deletions
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index b2bd166279e..5e806fd7932 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -39,6 +39,37 @@ struct ScoredSymbolGreater {
} // namespace
+llvm::Expected<Location> symbolToLocation(const Symbol &Sym,
+ llvm::StringRef HintPath) {
+ // Prefer the definition over e.g. a function declaration in a header
+ auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
+ auto Uri = URI::parse(CD.FileURI);
+ if (!Uri) {
+ return llvm::make_error<llvm::StringError>(
+ formatv("Could not parse URI '{0}' for symbol '{1}'.", CD.FileURI,
+ Sym.Name),
+ llvm::inconvertibleErrorCode());
+ }
+ auto Path = URI::resolve(*Uri, HintPath);
+ if (!Path) {
+ return llvm::make_error<llvm::StringError>(
+ formatv("Could not resolve path for URI '{0}' for symbol '{1}'.",
+ Uri->toString(), Sym.Name),
+ llvm::inconvertibleErrorCode());
+ }
+ Location L;
+ // Use HintPath as TUPath since there is no TU associated with this
+ // request.
+ L.uri = URIForFile::canonicalize(*Path, HintPath);
+ Position Start, End;
+ Start.line = CD.Start.line();
+ Start.character = CD.Start.column();
+ End.line = CD.End.line();
+ End.character = CD.End.column();
+ L.range = {Start, End};
+ return L;
+}
+
llvm::Expected<std::vector<SymbolInformation>>
getWorkspaceSymbols(llvm::StringRef Query, int Limit,
const SymbolIndex *const Index, llvm::StringRef HintPath) {
@@ -65,37 +96,18 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
Req.Limit ? *Req.Limit : std::numeric_limits<size_t>::max());
FuzzyMatcher Filter(Req.Query);
Index->fuzzyFind(Req, [HintPath, &Top, &Filter](const Symbol &Sym) {
- // Prefer the definition over e.g. a function declaration in a header
- auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
- auto Uri = URI::parse(CD.FileURI);
- if (!Uri) {
- log("Workspace symbol: Could not parse URI '{0}' for symbol '{1}'.",
- CD.FileURI, Sym.Name);
+ auto Loc = symbolToLocation(Sym, HintPath);
+ if (!Loc) {
+ log("Workspace symbols: {0}", Loc.takeError());
return;
}
- auto Path = URI::resolve(*Uri, HintPath);
- if (!Path) {
- log("Workspace symbol: Could not resolve path for URI '{0}' for symbol "
- "'{1}'.",
- Uri->toString(), Sym.Name);
- return;
- }
- Location L;
- // Use HintPath as TUPath since there is no TU associated with this
- // request.
- L.uri = URIForFile::canonicalize(*Path, HintPath);
- Position Start, End;
- Start.line = CD.Start.line();
- Start.character = CD.Start.column();
- End.line = CD.End.line();
- End.character = CD.End.column();
- L.range = {Start, End};
+
SymbolKind SK = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind);
std::string Scope = Sym.Scope;
llvm::StringRef ScopeRef = Scope;
ScopeRef.consume_back("::");
SymbolInformation Info = {(Sym.Name + Sym.TemplateSpecializationArgs).str(),
- SK, L, ScopeRef};
+ SK, *Loc, ScopeRef};
SymbolQualitySignals Quality;
Quality.merge(Sym);
OpenPOWER on IntegriCloud