@@ -132,14 +132,20 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
132
132
llvm::DenseMap<DeclAccessorPair, NameAndUSR> accessorNameAndUSRCache;
133
133
StringScratchSpace stringStorage;
134
134
135
- bool getNameAndUSR (ValueDecl *D, StringRef &name, StringRef &USR) {
136
- auto &result = nameAndUSRCache[D];
135
+ bool getNameAndUSR (ValueDecl *D, ExtensionDecl *ExtD,
136
+ StringRef &name, StringRef &USR) {
137
+ auto &result = nameAndUSRCache[ExtD ? (Decl*)ExtD : D];
137
138
if (result.USR .empty ()) {
138
139
SmallString<128 > storage;
139
140
{
140
141
llvm::raw_svector_ostream OS (storage);
141
- if (ide::printDeclUSR (D, OS))
142
- return true ;
142
+ if (ExtD) {
143
+ if (ide::printExtensionUSR (ExtD, OS))
144
+ return true ;
145
+ } else {
146
+ if (ide::printDeclUSR (D, OS))
147
+ return true ;
148
+ }
143
149
result.USR = stringStorage.copyString (OS.str ());
144
150
}
145
151
@@ -190,7 +196,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
190
196
191
197
if (SymInfo.Kind == SymbolKind::Unknown)
192
198
return true ;
193
- if (getNameAndUSR (D, Name, USR))
199
+ if (getNameAndUSR (D, /* ExtD= */ nullptr , Name, USR))
194
200
return true ;
195
201
196
202
Info.Relations .push_back (IndexRelation (RelationRoles, D, SymInfo, Name, USR));
@@ -361,6 +367,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
361
367
362
368
bool initIndexSymbol (ValueDecl *D, SourceLoc Loc, bool IsRef,
363
369
IndexSymbol &Info);
370
+ bool initIndexSymbol (ExtensionDecl *D, ValueDecl *ExtendedD, SourceLoc Loc,
371
+ IndexSymbol &Info);
364
372
bool initFuncDeclIndexSymbol (FuncDecl *D, IndexSymbol &Info);
365
373
bool initFuncRefIndexSymbol (Expr *CurrentE, Expr *ParentE, ValueDecl *D,
366
374
SourceLoc Loc, IndexSymbol &Info);
@@ -720,11 +728,9 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
720
728
return true ;
721
729
722
730
IndexSymbol Info;
723
- if (initIndexSymbol (NTD, Loc, /* IsRef= */ false , Info))
731
+ if (initIndexSymbol (D, NTD, Loc , Info))
724
732
return true ;
725
733
726
- Info.symInfo = getSymbolInfoForDecl (D);
727
-
728
734
if (!startEntity (D, Info))
729
735
return false ;
730
736
@@ -857,7 +863,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
857
863
else
858
864
Info.roles |= (unsigned )SymbolRole::Definition;
859
865
860
- if (getNameAndUSR (D, Info.name , Info.USR ))
866
+ if (getNameAndUSR (D, /* ExtD= */ nullptr , Info.name , Info.USR ))
861
867
return true ;
862
868
863
869
std::tie (Info.line , Info.column ) = getLineCol (Loc);
@@ -868,6 +874,25 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
868
874
return false ;
869
875
}
870
876
877
+ bool IndexSwiftASTWalker::initIndexSymbol (ExtensionDecl *ExtD, ValueDecl *ExtendedD,
878
+ SourceLoc Loc, IndexSymbol &Info) {
879
+ assert (ExtD && ExtendedD);
880
+ Info.decl = ExtendedD;
881
+ Info.symInfo = getSymbolInfoForDecl (ExtD);
882
+ if (Info.symInfo .Kind == SymbolKind::Unknown)
883
+ return true ;
884
+
885
+ Info.roles |= (unsigned )SymbolRole::Definition;
886
+
887
+ if (getNameAndUSR (ExtendedD, ExtD, Info.name , Info.USR ))
888
+ return true ;
889
+
890
+ std::tie (Info.line , Info.column ) = getLineCol (Loc);
891
+ if (auto Group = ExtD->getGroupName ())
892
+ Info.group = Group.getValue ();
893
+ return false ;
894
+ }
895
+
871
896
static NominalTypeDecl *getNominalParent (ValueDecl *D) {
872
897
Type Ty = D->getDeclContext ()->getDeclaredTypeOfContext ();
873
898
if (!Ty)
0 commit comments