diff options
author | Sam McCall <sam.mccall@gmail.com> | 2019-12-16 15:58:03 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2019-12-16 15:58:51 +0100 |
commit | a0ff8cd631add513423fc2d8afa49e9650d01fe3 (patch) | |
tree | 2e249130fcb354cb5257ba5ee2092282e883f065 /clang-tools-extra/clangd/XRefs.cpp | |
parent | 8f876d5105507f874c0fb86bc779c9853eab3fe2 (diff) | |
download | bcm5719-llvm-a0ff8cd631add513423fc2d8afa49e9650d01fe3.tar.gz bcm5719-llvm-a0ff8cd631add513423fc2d8afa49e9650d01fe3.zip |
[clangd] Reapply b60896fad926 Fall back to selecting token-before-cursor if token-after-cursor fails.
This reverts commit 8f876d5105507f874c0fb86bc779c9853eab3fe2.
Diffstat (limited to 'clang-tools-extra/clangd/XRefs.cpp')
-rw-r--r-- | clang-tools-extra/clangd/XRefs.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index b16e7080aa6..170637b596d 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -131,15 +131,16 @@ SymbolLocation getPreferredLocation(const Location &ASTLoc, std::vector<const Decl *> getDeclAtPosition(ParsedAST &AST, SourceLocation Pos, DeclRelationSet Relations) { - FileID FID; - unsigned Offset; - std::tie(FID, Offset) = AST.getSourceManager().getDecomposedSpellingLoc(Pos); - SelectionTree Selection(AST.getASTContext(), AST.getTokens(), Offset); + unsigned Offset = AST.getSourceManager().getDecomposedSpellingLoc(Pos).second; std::vector<const Decl *> Result; - if (const SelectionTree::Node *N = Selection.commonAncestor()) { - auto Decls = targetDecl(N->ASTNode, Relations); - Result.assign(Decls.begin(), Decls.end()); - } + SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), Offset, + Offset, [&](SelectionTree ST) { + if (const SelectionTree::Node *N = + ST.commonAncestor()) + llvm::copy(targetDecl(N->ASTNode, Relations), + std::back_inserter(Result)); + return !Result.empty(); + }); return Result; } |