File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
main/kotlin/com/sourcegraph/semanticdb_kotlinc
test/kotlin/com/sourcegraph/semanticdb_kotlinc/test Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -248,6 +248,12 @@ open class AnalyzerCheckers(session: FirSession) : FirAdditionalCheckersExtensio
248248 val ktFile = context.containingFile?.sourceFile ? : return
249249 val visitor = visitors[ktFile]
250250 visitor?.visitNamedFunction(declaration, getIdentifier(source), context)
251+
252+ val klass = declaration.returnTypeRef.toClassLikeSymbol(context.session)
253+ val klassSource = declaration.returnTypeRef.source
254+ if (klass != null && klassSource != null && klassSource.kind !is KtFakeSourceElementKind ) {
255+ visitor?.visitClassReference(klass, getIdentifier(klassSource), context)
256+ }
251257 }
252258 }
253259
@@ -297,6 +303,12 @@ open class AnalyzerCheckers(session: FirSession) : FirAdditionalCheckersExtensio
297303 val ktFile = context.containingFile?.sourceFile ? : return
298304 val visitor = visitors[ktFile]
299305 visitor?.visitParameter(declaration, getIdentifier(source), context)
306+
307+ val klass = declaration.returnTypeRef.toClassLikeSymbol(context.session)
308+ val klassSource = declaration.returnTypeRef.source
309+ if (klass != null && klassSource != null && klassSource.kind !is KtFakeSourceElementKind ) {
310+ visitor?.visitClassReference(klass, getIdentifier(klassSource), context)
311+ }
300312 }
301313 }
302314
Original file line number Diff line number Diff line change @@ -444,6 +444,65 @@ class AnalyzerTest {
444444 assertSoftly(document.symbolsList) { withClue(this ) { symbols.forEach(::shouldContain) } }
445445 }
446446
447+ @Test
448+ fun `function return type` (@TempDir path : Path ) {
449+ val document =
450+ compileSemanticdb(
451+ path,
452+ """
453+ package sample
454+
455+ fun foo(arg: Int): Boolean = true
456+ """ )
457+
458+ val occurrences =
459+ arrayOf(
460+ SymbolOccurrence {
461+ role = Role .DEFINITION
462+ symbol = " sample/foo()."
463+ range {
464+ startLine = 2
465+ startCharacter = 4
466+ endLine = 2
467+ endCharacter = 7
468+ }
469+ },
470+ SymbolOccurrence {
471+ role = Role .DEFINITION
472+ symbol = " sample/foo().(arg)"
473+ range {
474+ startLine = 2
475+ startCharacter = 8
476+ endLine = 2
477+ endCharacter = 11
478+ }
479+ },
480+ SymbolOccurrence {
481+ role = Role .REFERENCE
482+ symbol = " kotlin/Int#"
483+ range {
484+ startLine = 2
485+ startCharacter = 13
486+ endLine = 2
487+ endCharacter = 16
488+ }
489+ },
490+ SymbolOccurrence {
491+ role = Role .REFERENCE
492+ symbol = " kotlin/Boolean#"
493+ range {
494+ startLine = 2
495+ startCharacter = 19
496+ endLine = 2
497+ endCharacter = 26
498+ }
499+ },
500+ )
501+ assertSoftly(document.occurrencesList) {
502+ withClue(this ) { occurrences.forEach(::shouldContain) }
503+ }
504+ }
505+
447506 @Test
448507 fun `exception test` (@TempDir path : Path ) {
449508 val buildPath = File (path.resolve(" build" ).toString()).apply { mkdir() }
You can’t perform that action at this time.
0 commit comments