@@ -60,8 +60,7 @@ package final class CheckedIndex {
60
60
private var checker : IndexOutOfDateChecker
61
61
private let index : IndexStoreDB
62
62
63
- /// Maps the USR of a symbol’s container the name of that container as well as the name of all containers the
64
- /// container might itself be contained in.
63
+ /// Maps the USR of a symbol to its name and the name of all its containers, from outermost to innermost.
65
64
///
66
65
/// It is important that we cache this because we might find a lot of symbols in the same container for eg. workspace
67
66
/// symbols (eg. consider many symbols in the same C++ namespace). If we didn't cache this value, then we would need
@@ -256,21 +255,26 @@ package final class CheckedIndex {
256
255
}
257
256
} . sorted ( ) . first
258
257
259
- if let container {
260
- if let cached = containerNamesCache [ container. symbol. usr] {
261
- return cached
262
- }
263
- let result : [ String ]
264
- if let containerDefinition = primaryDefinitionOrDeclarationOccurrence ( ofUSR: container. symbol. usr) {
265
- result = self . containerNames ( of: containerDefinition) + [ container. symbol. name]
266
- } else {
267
- result = [ container. symbol. name]
268
- }
269
- containerNamesCache [ container. symbol. usr] = result
270
- return result
271
- } else {
258
+ guard var containerSymbol = container? . symbol else {
272
259
return [ ]
273
260
}
261
+ if let cached = containerNamesCache [ containerSymbol. usr] {
262
+ return cached
263
+ }
264
+
265
+ if containerSymbol. kind == . extension,
266
+ let extendedSymbol = self . occurrences ( relatedToUSR: containerSymbol. usr, roles: . extendedBy) . first? . symbol
267
+ {
268
+ containerSymbol = extendedSymbol
269
+ }
270
+ let result : [ String ]
271
+ if let containerDefinition = primaryDefinitionOrDeclarationOccurrence ( ofUSR: containerSymbol. usr) {
272
+ result = self . containerNames ( of: containerDefinition) + [ containerSymbol. name]
273
+ } else {
274
+ result = [ containerSymbol. name]
275
+ }
276
+ containerNamesCache [ containerSymbol. usr] = result
277
+ return result
274
278
}
275
279
}
276
280
0 commit comments