@@ -189,15 +189,21 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
189
189
return false ;
190
190
}
191
191
192
- bool addRelation (IndexSymbol &Info, SymbolRoleSet RelationRoles, ValueDecl *D) {
192
+ bool addRelation (IndexSymbol &Info, SymbolRoleSet RelationRoles, Decl *D) {
193
193
assert (D);
194
194
StringRef Name, USR;
195
195
SymbolInfo SymInfo = getSymbolInfoForDecl (D);
196
196
197
197
if (SymInfo.Kind == SymbolKind::Unknown)
198
198
return true ;
199
- if (getNameAndUSR (D, /* ExtD=*/ nullptr , Name, USR))
200
- return true ;
199
+ if (auto *ExtD = dyn_cast<ExtensionDecl>(D)) {
200
+ NominalTypeDecl *NTD = ExtD->getExtendedType ()->getAnyNominal ();
201
+ if (getNameAndUSR (NTD, ExtD, Name, USR))
202
+ return true ;
203
+ } else {
204
+ if (getNameAndUSR (cast<ValueDecl>(D), /* ExtD=*/ nullptr , Name, USR))
205
+ return true ;
206
+ }
201
207
202
208
Info.Relations .push_back (IndexRelation (RelationRoles, D, SymInfo, Name, USR));
203
209
Info.roles |= RelationRoles;
@@ -339,9 +345,9 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
339
345
bool startEntity (Decl *D, IndexSymbol &Info);
340
346
bool startEntityDecl (ValueDecl *D);
341
347
342
- bool reportRelatedRef (ValueDecl *D, SourceLoc Loc, SymbolRoleSet Relations, ValueDecl *Related);
343
- bool reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, ValueDecl *Related);
344
- bool reportInheritedTypeRefs (ArrayRef<TypeLoc> Inherited, ValueDecl *Inheritee);
348
+ bool reportRelatedRef (ValueDecl *D, SourceLoc Loc, SymbolRoleSet Relations, Decl *Related);
349
+ bool reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related);
350
+ bool reportInheritedTypeRefs (ArrayRef<TypeLoc> Inherited, Decl *Inheritee);
345
351
NominalTypeDecl *getTypeLocAsNominalTypeDecl (const TypeLoc &Ty);
346
352
347
353
bool reportPseudoGetterDecl (VarDecl *D) {
@@ -609,7 +615,7 @@ bool IndexSwiftASTWalker::startEntityDecl(ValueDecl *D) {
609
615
return startEntity (D, Info);
610
616
}
611
617
612
- bool IndexSwiftASTWalker::reportRelatedRef (ValueDecl *D, SourceLoc Loc, SymbolRoleSet Relations, ValueDecl *Related) {
618
+ bool IndexSwiftASTWalker::reportRelatedRef (ValueDecl *D, SourceLoc Loc, SymbolRoleSet Relations, Decl *Related) {
613
619
if (!shouldIndex (D))
614
620
return true ;
615
621
@@ -628,15 +634,15 @@ bool IndexSwiftASTWalker::reportRelatedRef(ValueDecl *D, SourceLoc Loc, SymbolRo
628
634
return !Cancelled;
629
635
}
630
636
631
- bool IndexSwiftASTWalker::reportInheritedTypeRefs (ArrayRef<TypeLoc> Inherited, ValueDecl *Inheritee) {
637
+ bool IndexSwiftASTWalker::reportInheritedTypeRefs (ArrayRef<TypeLoc> Inherited, Decl *Inheritee) {
632
638
for (auto Base : Inherited) {
633
639
if (!reportRelatedTypeRef (Base, (SymbolRoleSet) SymbolRole::RelationBaseOf, Inheritee))
634
640
return false ;
635
641
}
636
642
return true ;
637
643
}
638
644
639
- bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, ValueDecl *Related) {
645
+ bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related) {
640
646
641
647
if (IdentTypeRepr *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr ())) {
642
648
auto Comps = T->getComponentRange ();
@@ -718,7 +724,10 @@ IndexSwiftASTWalker::getTypeLocAsNominalTypeDecl(const TypeLoc &Ty) {
718
724
}
719
725
720
726
bool IndexSwiftASTWalker::reportExtension (ExtensionDecl *D) {
721
- SourceLoc Loc = D->getExtendedTypeLoc ().getSourceRange ().Start ;
727
+ // Use the 'End' token of the range, in case it is a compound name, e.g.
728
+ // extension A.B {}
729
+ // we want the location of 'B' token.
730
+ SourceLoc Loc = D->getExtendedTypeLoc ().getSourceRange ().End ;
722
731
if (!D->getExtendedType ())
723
732
return true ;
724
733
NominalTypeDecl *NTD = D->getExtendedType ()->getAnyNominal ();
@@ -734,11 +743,10 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
734
743
if (!startEntity (D, Info))
735
744
return false ;
736
745
737
- // FIXME: make extensions their own entity
738
746
if (!reportRelatedRef (NTD, Loc, (SymbolRoleSet)SymbolRole::RelationExtendedBy,
739
- NTD ))
747
+ D ))
740
748
return false ;
741
- if (!reportInheritedTypeRefs (D->getInherited (), NTD ))
749
+ if (!reportInheritedTypeRefs (D->getInherited (), D ))
742
750
return false ;
743
751
744
752
return true ;
0 commit comments