@@ -1199,21 +1199,21 @@ type refSearch struct {
1199
1199
includes func (symbol * ast.Symbol ) bool
1200
1200
}
1201
1201
1202
- // type inheritKey struct {
1203
- // symbol *ast.Symbol
1204
- // parent *ast.Symbol
1205
- // }
1202
+ type inheritKey struct {
1203
+ symbol * ast.Symbol
1204
+ parent * ast.Symbol
1205
+ }
1206
1206
1207
1207
type refState struct {
1208
1208
sourceFiles []* ast.SourceFile
1209
1209
sourceFilesSet * collections.Set [string ]
1210
- specialSearchKind string // !!! none, constructor, class
1210
+ specialSearchKind string // " none", " constructor", or " class"
1211
1211
checker * checker.Checker
1212
1212
// cancellationToken CancellationToken
1213
- searchMeaning ast.SemanticMeaning
1214
- options refOptions
1215
- result []* SymbolAndEntries
1216
- // inheritsFromCache map[inheritKey]bool
1213
+ searchMeaning ast.SemanticMeaning
1214
+ options refOptions
1215
+ result []* SymbolAndEntries
1216
+ inheritsFromCache map [inheritKey ]bool
1217
1217
seenContainingTypeReferences collections.Set [* ast.Node ] // node seen tracker
1218
1218
// seenReExportRHS *collections.Set[*ast.Node] // node seen tracker
1219
1219
importTracker ImportTracker
@@ -1229,7 +1229,7 @@ func newState(sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[str
1229
1229
checker : checker ,
1230
1230
searchMeaning : searchMeaning ,
1231
1231
options : options ,
1232
- // inheritsFromCache: map[inheritKey]bool{},
1232
+ inheritsFromCache : map [inheritKey ]bool {},
1233
1233
// seenReExportRHS: &collections.Set[*ast.Node]{},
1234
1234
symbolToReferences : map [* ast.Symbol ]* SymbolAndEntries {},
1235
1235
sourceFileToSeenSymbols : map [* ast.SourceFile ]* collections.Set [* ast.Symbol ]{},
@@ -1281,7 +1281,6 @@ func (state *refState) createSearch(location *ast.Node, symbol *ast.Symbol, comi
1281
1281
}
1282
1282
1283
1283
func (state * refState ) referenceAdder (searchSymbol * ast.Symbol ) func (* ast.Node , entryKind ) {
1284
- // !!! after find all references is fully implemented, rename this to something like 'getReferenceAdder'
1285
1284
symbolAndEntries := state .symbolToReferences [searchSymbol ]
1286
1285
if symbolAndEntries == nil {
1287
1286
symbolAndEntries = NewSymbolAndEntries (definitionKindSymbol , nil , searchSymbol , nil )
@@ -1822,9 +1821,7 @@ func (state *refState) getRelatedSymbol(search *refSearch, referenceSymbol *ast.
1822
1821
},
1823
1822
func (rootSymbol * ast.Symbol ) bool {
1824
1823
return ! (len (search .parents ) != 0 && ! core .Some (search .parents , func (parent * ast.Symbol ) bool {
1825
- return false
1826
- // !!! not implemented
1827
- // return state.explicitlyInheritsFrom(rootSymbol.Parent, parent)
1824
+ return state .explicitlyInheritsFrom (rootSymbol .Parent , parent )
1828
1825
}))
1829
1826
},
1830
1827
)
@@ -1976,3 +1973,34 @@ func (state *refState) searchForName(sourceFile *ast.SourceFile, search *refSear
1976
1973
state .getReferencesInSourceFile (sourceFile , search , true /*addReferencesHere*/ )
1977
1974
}
1978
1975
}
1976
+
1977
+ func (state * refState ) explicitlyInheritsFrom (symbol * ast.Symbol , parent * ast.Symbol ) bool {
1978
+ if symbol == parent {
1979
+ return true
1980
+ }
1981
+
1982
+ // Check cache first
1983
+ key := inheritKey {symbol : symbol , parent : parent }
1984
+ if cached , ok := state .inheritsFromCache [key ]; ok {
1985
+ return cached
1986
+ }
1987
+
1988
+ // Set to false initially to prevent infinite recursion
1989
+ state .inheritsFromCache [key ] = false
1990
+
1991
+ if symbol .Declarations == nil {
1992
+ return false
1993
+ }
1994
+
1995
+ inherits := core .Some (symbol .Declarations , func (declaration * ast.Node ) bool {
1996
+ superTypeNodes := getAllSuperTypeNodes (declaration )
1997
+ return core .Some (superTypeNodes , func (typeReference * ast.TypeNode ) bool {
1998
+ typ := state .checker .GetTypeAtLocation (typeReference .AsNode ())
1999
+ return typ != nil && typ .Symbol () != nil && state .explicitlyInheritsFrom (typ .Symbol (), parent )
2000
+ })
2001
+ })
2002
+
2003
+ // Update cache with the actual result
2004
+ state .inheritsFromCache [key ] = inherits
2005
+ return inherits
2006
+ }
0 commit comments