@@ -183,6 +183,12 @@ getDeclAtPositionWithRelations(ParsedAST &AST, SourceLocation Pos,
183
183
if (const SelectionTree::Node *N = ST.commonAncestor ()) {
184
184
if (NodeKind)
185
185
*NodeKind = N->ASTNode .getNodeKind ();
186
+ // Attributes don't target decls, look at the
187
+ // thing it's attached to.
188
+ // We still report the original NodeKind!
189
+ // This makes the `override` hack work.
190
+ if (N->ASTNode .get <Attr>() && N->Parent )
191
+ N = N->Parent ;
186
192
llvm::copy_if (allTargetDecls (N->ASTNode , AST.getHeuristicResolver ()),
187
193
std::back_inserter (Result),
188
194
[&](auto &Entry) { return !(Entry.second & ~Relations); });
@@ -343,7 +349,7 @@ std::vector<LocatedSymbol> findImplementors(llvm::DenseSet<SymbolID> IDs,
343
349
std::vector<LocatedSymbol>
344
350
locateASTReferent (SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
345
351
ParsedAST &AST, llvm::StringRef MainFilePath,
346
- const SymbolIndex *Index, ASTNodeKind * NodeKind) {
352
+ const SymbolIndex *Index, ASTNodeKind & NodeKind) {
347
353
const SourceManager &SM = AST.getSourceManager ();
348
354
// Results follow the order of Symbols.Decls.
349
355
std::vector<LocatedSymbol> Result;
@@ -376,7 +382,7 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
376
382
DeclRelationSet Relations =
377
383
DeclRelation::TemplatePattern | DeclRelation::Alias;
378
384
auto Candidates =
379
- getDeclAtPositionWithRelations (AST, CurLoc, Relations, NodeKind);
385
+ getDeclAtPositionWithRelations (AST, CurLoc, Relations, & NodeKind);
380
386
llvm::DenseSet<SymbolID> VirtualMethods;
381
387
for (const auto &E : Candidates) {
382
388
const NamedDecl *D = E.first ;
@@ -392,13 +398,8 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
392
398
}
393
399
}
394
400
// Special case: void foo() ^override: jump to the overridden method.
395
- const InheritableAttr *Attr = D->getAttr <OverrideAttr>();
396
- if (!Attr)
397
- Attr = D->getAttr <FinalAttr>();
398
- if (Attr && TouchedIdentifier &&
399
- SM.getSpellingLoc (Attr->getLocation ()) ==
400
- TouchedIdentifier->location ()) {
401
- LocateASTReferentMetric.record (1 , " method-to-base" );
401
+ if (NodeKind.isSame (ASTNodeKind::getFromNodeKind<OverrideAttr>()) ||
402
+ NodeKind.isSame (ASTNodeKind::getFromNodeKind<FinalAttr>())) {
402
403
// We may be overridding multiple methods - offer them all.
403
404
for (const NamedDecl *ND : CMD->overridden_methods ())
404
405
AddResultDecl (ND);
@@ -800,7 +801,7 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
800
801
801
802
ASTNodeKind NodeKind;
802
803
auto ASTResults = locateASTReferent (*CurLoc, TouchedIdentifier, AST,
803
- *MainFilePath, Index, & NodeKind);
804
+ *MainFilePath, Index, NodeKind);
804
805
if (!ASTResults.empty ())
805
806
return ASTResults;
806
807
@@ -816,9 +817,8 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
816
817
Word->Text );
817
818
return {*std::move (Macro)};
818
819
}
819
- ASTResults =
820
- locateASTReferent (NearbyIdent->location (), NearbyIdent, AST,
821
- *MainFilePath, Index, /* NodeKind=*/ nullptr );
820
+ ASTResults = locateASTReferent (NearbyIdent->location (), NearbyIdent, AST,
821
+ *MainFilePath, Index, NodeKind);
822
822
if (!ASTResults.empty ()) {
823
823
log (" Found definition heuristically using nearby identifier {0}" ,
824
824
NearbyIdent->text (SM));
@@ -1987,4 +1987,4 @@ llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
1987
1987
}
1988
1988
1989
1989
} // namespace clangd
1990
- } // namespace clang
1990
+ } // namespace clang
0 commit comments