Skip to content

Commit 1987d46

Browse files
committed
emit overridden_symbols for Go to Implementations
1 parent 582c898 commit 1987d46

File tree

3 files changed

+66
-50
lines changed

3 files changed

+66
-50
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import kotlin.contracts.ExperimentalContracts
99
import org.jetbrains.kotlin.analyzer.AnalysisResult
1010
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
1111
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
12-
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
1312
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
1413
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
1514
import org.jetbrains.kotlin.com.intellij.openapi.project.Project
@@ -18,8 +17,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
1817
import org.jetbrains.kotlin.psi.*
1918
import org.jetbrains.kotlin.resolve.BindingTrace
2019
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
21-
import org.jetbrains.kotlin.utils.rethrow
22-
import java.io.StringWriter
2320

2421
@ExperimentalContracts
2522
class Analyzer(
@@ -31,7 +28,9 @@ class Analyzer(
3128

3229
private val messageCollector =
3330
CompilerConfiguration()
34-
.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false))
31+
.get(
32+
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
33+
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false))
3534

3635
override fun analysisCompleted(
3736
project: Project,
@@ -83,22 +82,22 @@ class Analyzer(
8382

8483
private fun handleException(e: Exception) {
8584
val writer =
86-
PrintWriter(
87-
object : Writer() {
88-
val buf = StringBuffer()
89-
override fun close() =
90-
messageCollector.report(
91-
CompilerMessageSeverity.EXCEPTION, buf.toString())
92-
override fun flush() = Unit
93-
override fun write(data: CharArray, offset: Int, len: Int) {
94-
buf.append(data, offset, len)
95-
}
96-
},
97-
false)
98-
writer.println("Exception in semanticdb-kotlin compiler plugin:")
99-
e.printStackTrace(writer)
100-
writer.println(
101-
"Please report a bug to https://github.com/sourcegraph/lsif-kotlin with the stack trace above.")
102-
writer.close()
85+
PrintWriter(
86+
object : Writer() {
87+
val buf = StringBuffer()
88+
override fun close() =
89+
messageCollector.report(CompilerMessageSeverity.EXCEPTION, buf.toString())
90+
91+
override fun flush() = Unit
92+
override fun write(data: CharArray, offset: Int, len: Int) {
93+
buf.append(data, offset, len)
94+
}
95+
},
96+
false)
97+
writer.println("Exception in semanticdb-kotlin compiler plugin:")
98+
e.printStackTrace(writer)
99+
writer.println(
100+
"Please report a bug to https://github.com/sourcegraph/lsif-kotlin with the stack trace above.")
101+
writer.close()
103102
}
104103
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ import org.jetbrains.kotlin.backend.common.serialization.metadata.findKDocString
1313
import org.jetbrains.kotlin.com.intellij.lang.java.JavaLanguage
1414
import org.jetbrains.kotlin.com.intellij.navigation.NavigationItem
1515
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
16+
import org.jetbrains.kotlin.descriptors.ClassDescriptor
1617
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
1718
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
1819
import org.jetbrains.kotlin.idea.KotlinLanguage
20+
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc.fqnString
1921
import org.jetbrains.kotlin.psi.KtConstructor
2022
import org.jetbrains.kotlin.psi.KtFile
2123
import org.jetbrains.kotlin.psi.KtPropertyAccessor
2224
import org.jetbrains.kotlin.renderer.DescriptorRenderer
25+
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
2326

2427
@ExperimentalContracts
2528
class SemanticdbTextDocumentBuilder(
@@ -56,10 +59,24 @@ class SemanticdbTextDocumentBuilder(
5659
descriptor: DeclarationDescriptor,
5760
element: PsiElement
5861
): Semanticdb.SymbolInformation {
62+
val supers =
63+
when (descriptor) {
64+
is ClassDescriptor ->
65+
descriptor
66+
.getAllSuperClassifiers()
67+
// first is the class itself
68+
.drop(1)
69+
.filter { it.fqnString == "kotlin.Any" || it.fqnString == "java.lang.Object" }
70+
.flatMap { cache[it] }
71+
.map { it.toString() }
72+
.asIterable()
73+
else -> emptyList<String>().asIterable()
74+
}
5975
return SymbolInformation {
6076
this.symbol = symbol.toString()
6177
this.displayName = displayName(element)
6278
this.documentation = semanticdbDocumentation(descriptor)
79+
this.addAllOverriddenSymbols(supers)
6380
this.language =
6481
when (element.language) {
6582
is KotlinLanguage -> Semanticdb.Language.KOTLIN

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -596,40 +596,40 @@ class SemanticdbSymbolsTest {
596596
@TestFactory
597597
fun kdoc() =
598598
listOf(
599-
ExpectedSymbols(
600-
"empty kdoc line",
601-
SourceFile.testKt(
602-
"""
599+
ExpectedSymbols(
600+
"empty kdoc line",
601+
SourceFile.testKt(
602+
"""
603603
|/**
604604
|
605605
|hello world
606606
|* test content
607607
|*/
608608
|val x = ""
609609
|""".trimMargin()),
610-
semanticdb = SemanticdbData(
611-
expectedSymbols =
612-
listOf(
613-
SymbolInformation {
614-
symbol = "TestKt#x."
615-
displayName = "x"
616-
language = Language.KOTLIN
617-
documentation {
618-
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
619-
format = Format.MARKDOWN
620-
}
621-
},
622-
SymbolInformation {
623-
symbol = "TestKt#getX()."
624-
displayName = "x"
625-
language = Language.KOTLIN
626-
documentation {
627-
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
628-
format = Format.MARKDOWN
629-
}
630-
}
631-
)
632-
)
633-
)
634-
).mapCheckExpectedSymbols()
610+
semanticdb =
611+
SemanticdbData(
612+
expectedSymbols =
613+
listOf(
614+
SymbolInformation {
615+
symbol = "TestKt#x."
616+
displayName = "x"
617+
language = Language.KOTLIN
618+
documentation {
619+
message =
620+
"```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
621+
format = Format.MARKDOWN
622+
}
623+
},
624+
SymbolInformation {
625+
symbol = "TestKt#getX()."
626+
displayName = "x"
627+
language = Language.KOTLIN
628+
documentation {
629+
message =
630+
"```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
631+
format = Format.MARKDOWN
632+
}
633+
}))))
634+
.mapCheckExpectedSymbols()
635635
}

0 commit comments

Comments
 (0)