Skip to content

Commit 09d1d97

Browse files
nicolas-guichardantonsviridov-src
authored andcommitted
Children of local symbols are local symbols
This was caught by Searchfox's scip-indexer, which would error out: ``` [ERROR scip_indexer] InvalidLocalSymbol("local 84getCurrentIndex().") ```
1 parent b0c8eb3 commit 09d1d97

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

semanticdb-kotlinc/src/main/kotlin/com/sourcegraph/semanticdb_kotlinc/SymbolsCache.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class GlobalSymbolsCache(testing: Boolean = false) : Iterable<Symbol> {
9393
if (symbol.fir.isLocalMember) return locals + symbol
9494

9595
val owner = getParentSymbol(symbol, locals)
96+
97+
if (owner.isLocal()) return locals + symbol
98+
9699
val semanticdbDescriptor = semanticdbDescriptor(symbol)
97100

98101
return Symbol.createGlobal(owner, semanticdbDescriptor)

semanticdb-kotlinc/src/test/kotlin/com/sourcegraph/semanticdb_kotlinc/test/AnalyzerTest.kt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,113 @@ class AnalyzerTest {
192192
}
193193
}
194194

195+
@Test
196+
fun `local classes`(@TempDir path: Path) {
197+
val document =
198+
compileSemanticdb(
199+
path,
200+
"""
201+
package sample
202+
203+
fun foo() {
204+
class LocalClass {
205+
fun localClassMethod() {}
206+
}
207+
}
208+
""")
209+
210+
val occurrences =
211+
arrayOf(
212+
SymbolOccurrence {
213+
role = Role.DEFINITION
214+
symbol = "sample/foo()."
215+
range {
216+
startLine = 2
217+
startCharacter = 4
218+
endLine = 2
219+
endCharacter = 7
220+
}
221+
},
222+
// LocalClass
223+
SymbolOccurrence {
224+
role = Role.DEFINITION
225+
symbol = "local0"
226+
range {
227+
startLine = 3
228+
startCharacter = 8
229+
endLine = 3
230+
endCharacter = 18
231+
}
232+
},
233+
// LocalClass constructor
234+
SymbolOccurrence {
235+
role = Role.DEFINITION
236+
symbol = "local1"
237+
range {
238+
startLine = 3
239+
startCharacter = 8
240+
endLine = 3
241+
endCharacter = 18
242+
}
243+
},
244+
// localClassMethod
245+
SymbolOccurrence {
246+
role = Role.DEFINITION
247+
symbol = "local2"
248+
range {
249+
startLine = 4
250+
startCharacter = 8
251+
endLine = 4
252+
endCharacter = 24
253+
}
254+
},
255+
)
256+
assertSoftly(document.occurrencesList) {
257+
withClue(this) { occurrences.forEach(::shouldContain) }
258+
}
259+
260+
val symbols =
261+
arrayOf(
262+
SymbolInformation {
263+
symbol = "sample/foo()."
264+
displayName = "foo"
265+
language = KOTLIN
266+
documentation {
267+
message = "```kotlin\npublic final fun foo(): Unit\n```"
268+
format = Semanticdb.Documentation.Format.MARKDOWN
269+
}
270+
},
271+
SymbolInformation {
272+
symbol = "local0"
273+
displayName = "LocalClass"
274+
language = KOTLIN
275+
documentation {
276+
message = "```kotlin\nlocal final class LocalClass : Any\n```"
277+
format = Semanticdb.Documentation.Format.MARKDOWN
278+
}
279+
},
280+
SymbolInformation {
281+
symbol = "local1"
282+
displayName = "LocalClass"
283+
language = KOTLIN
284+
documentation {
285+
message = "```kotlin\npublic constructor(): LocalClass\n```"
286+
format = Semanticdb.Documentation.Format.MARKDOWN
287+
}
288+
},
289+
SymbolInformation {
290+
symbol = "local2"
291+
displayName = "localClassMethod"
292+
language = KOTLIN
293+
documentation {
294+
message = "```kotlin\npublic final fun localClassMethod(): Unit\n```"
295+
format = Semanticdb.Documentation.Format.MARKDOWN
296+
}
297+
},
298+
)
299+
assertSoftly(document.symbolsList) { withClue(this) { symbols.forEach(::shouldContain) } }
300+
}
301+
195302
@Test
196303
fun overrides(@TempDir path: Path) {
197304
val document =

0 commit comments

Comments
 (0)