Skip to content

Commit e1d754c

Browse files
committed
Update snapshot tests with new implementation relationships
1 parent 1924867 commit e1d754c

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

semanticdb-kotlinc/minimized/src/generatedSnapshots/resources/semanticdb-kotlinc/minimized/src/main/kotlin/snapshots/Class.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package snapshots
44
class Class constructor(private var banana: Int, apple: String) :
55
// ^^^^^ definition semanticdb maven . . snapshots/Class#
66
// documentation ```kt\npublic final class Class : kotlin.Throwable\n```
7+
// relationship is_reference is_implementation semanticdb maven . . kotlin/Throwable#
78
// ^^^^^^^^^^^ definition semanticdb maven . . snapshots/Class#`<init>`().
89
// documentation ```kt\npublic constructor Class(banana: kotlin.Int, apple: kotlin.String)\n```
910
// ^^^^^^ definition semanticdb maven . . snapshots/Class#`<init>`().(banana)

semanticdb-kotlinc/minimized/src/generatedSnapshots/resources/semanticdb-kotlinc/minimized/src/main/kotlin/snapshots/Docstrings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ abstract class DocstringSuperclass
1515
class Docstrings : DocstringSuperclass(), Serializable {
1616
// ^^^^^^^^^^ definition semanticdb maven . . snapshots/Docstrings#
1717
// documentation ```kt\npublic final class Docstrings : snapshots.DocstringSuperclass, java.io.Serializable\n```\n\n----\n\n Example class docstring.
18+
// relationship is_reference is_implementation semanticdb maven . . snapshots/DocstringSuperclass#
1819
// ^^^^^^^^^^ definition semanticdb maven . . snapshots/Docstrings#`<init>`().
1920
// documentation ```kt\npublic constructor Docstrings()\n```\n\n----\n\n Example class docstring.
2021
// ^^^^^^^^^^^^^^^^^^^ reference semanticdb maven . . snapshots/DocstringSuperclass#`<init>`().

semanticdb-kotlinc/minimized/src/generatedSnapshots/resources/semanticdb-kotlinc/minimized/src/main/kotlin/snapshots/Implementations.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ package snapshots
44
class Overrides : AutoCloseable {
55
// ^^^^^^^^^ definition semanticdb maven . . snapshots/Overrides#
66
// documentation ```kt\npublic final class Overrides : java.lang.AutoCloseable\n```
7+
// relationship is_reference is_implementation semanticdb maven jdk 8 java/lang/AutoCloseable#
78
// ^^^^^^^^^ definition semanticdb maven . . snapshots/Overrides#`<init>`().
89
// documentation ```kt\npublic constructor Overrides()\n```
910
// ^^^^^^^^^^^^^ reference semanticdb maven jdk 8 java/lang/AutoCloseable#
1011
override fun close() {
1112
// ^^^^^ definition semanticdb maven . . snapshots/Overrides#close().
1213
// documentation ```kt\npublic open fun close()\n```
14+
// relationship is_reference is_implementation semanticdb maven jdk 8 java/lang/AutoCloseable#close().
1315
TODO("Not yet implemented")
1416
// ^^^^ reference semanticdb maven . . kotlin/StandardKt#TODO(+1).
1517
}
@@ -32,6 +34,7 @@ interface Animal {
3234
open class Bird : Animal {
3335
// ^^^^ definition semanticdb maven . . snapshots/Bird#
3436
// documentation ```kt\npublic open class Bird : snapshots.Animal\n```
37+
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#
3538
// ^^^^ definition semanticdb maven . . snapshots/Bird#`<init>`().
3639
// documentation ```kt\npublic constructor Bird()\n```
3740
// ^^^^^^ reference semanticdb maven . . snapshots/Animal#
@@ -46,13 +49,16 @@ open class Bird : Animal {
4649
override fun sound(): String {
4750
// ^^^^^ definition semanticdb maven . . snapshots/Bird#sound().
4851
// documentation ```kt\npublic open fun sound(): kotlin.String\n```
52+
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#sound().
4953
// ^^^^^^ reference semanticdb maven . . kotlin/String#
5054
return "tweet"
5155
}
5256
}
5357
class Seagull : Bird() {
5458
// ^^^^^^^ definition semanticdb maven . . snapshots/Seagull#
5559
// documentation ```kt\npublic final class Seagull : snapshots.Bird\n```
60+
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#
61+
// relationship is_reference is_implementation semanticdb maven . . snapshots/Bird#
5662
// ^^^^^^^ definition semanticdb maven . . snapshots/Seagull#`<init>`().
5763
// documentation ```kt\npublic constructor Seagull()\n```
5864
// ^^^^ reference semanticdb maven . . snapshots/Bird#`<init>`().
@@ -66,6 +72,8 @@ class Seagull : Bird() {
6672
override fun sound(): String {
6773
// ^^^^^ definition semanticdb maven . . snapshots/Seagull#sound().
6874
// documentation ```kt\npublic open fun sound(): kotlin.String\n```
75+
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#sound().
76+
// relationship is_reference is_implementation semanticdb maven . . snapshots/Bird#sound().
6977
// ^^^^^^ reference semanticdb maven . . kotlin/String#
7078
return "squawk"
7179
}

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ 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
17-
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
18-
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
19-
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
16+
import org.jetbrains.kotlin.descriptors.*
2017
import org.jetbrains.kotlin.idea.KotlinLanguage
2118
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc.fqnString
2219
import org.jetbrains.kotlin.psi.KtConstructor
@@ -55,6 +52,27 @@ class SemanticdbTextDocumentBuilder(
5552
if (role == Role.DEFINITION) symbols.add(symbolInformation(symbol, descriptor, element))
5653
}
5754

55+
private val isIgnoredSuperClass = setOf("kotlin.Any", "java.lang.Object", "java.io.Serializable")
56+
57+
private fun functionDescriptorOverrides(descriptor: FunctionDescriptor): Iterable<String> {
58+
val result = mutableListOf<String>()
59+
val isVisited = mutableSetOf<FunctionDescriptor>()
60+
val queue = ArrayDeque<FunctionDescriptor>()
61+
queue.add(descriptor)
62+
while (!queue.isEmpty()) {
63+
val current = queue.removeFirst()
64+
if (current in isVisited) {
65+
continue
66+
}
67+
68+
isVisited.add(current)
69+
val directOverrides = current.overriddenDescriptors.flatMap { cache[it] }.map { it.toString() }
70+
result.addAll(directOverrides)
71+
queue.addAll(current.overriddenDescriptors)
72+
}
73+
return result
74+
}
75+
5876
private fun symbolInformation(
5977
symbol: Symbol,
6078
descriptor: DeclarationDescriptor,
@@ -68,20 +86,20 @@ class SemanticdbTextDocumentBuilder(
6886
// first is the class itself
6987
.drop(1)
7088
.filter {
71-
it.fqnString != "kotlin.Any" && it.fqnString != "java.lang.Object"
89+
it.fqnString !in isIgnoredSuperClass
7290
}
7391
.flatMap { cache[it] }
7492
.map { it.toString() }
7593
.asIterable()
7694
is SimpleFunctionDescriptor ->
77-
descriptor.overriddenDescriptors.flatMap { cache[it] }.map { it.toString() }
95+
functionDescriptorOverrides(descriptor)
7896
else -> emptyList<String>().asIterable()
7997
}
8098
return SymbolInformation {
8199
this.symbol = symbol.toString()
82100
this.displayName = displayName(element)
83101
this.documentation = semanticdbDocumentation(descriptor)
84-
// this.addAllOverriddenSymbols(supers)
102+
this.addAllOverriddenSymbols(supers)
85103
this.language =
86104
when (element.language) {
87105
is KotlinLanguage -> Semanticdb.Language.KOTLIN

semanticdb-kotlinc/src/snapshots/kotlin/com/sourcegraph/lsif_kotlin/Snapshot.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fun main() {
1010

1111
ScipJava.main(arrayOf(
1212
"index-semanticdb",
13+
"--no-emit-inverse-relationships",
1314
"--cwd",
1415
sourceroot.toString(),
1516
"--output",

0 commit comments

Comments
 (0)