Skip to content

Commit 005ec35

Browse files
committed
Tweak the docstring format
1 parent 3794e99 commit 005ec35

File tree

8 files changed

+54
-84
lines changed

8 files changed

+54
-84
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package snapshots
22
// ^^^^^^^^^ reference snapshots/
33

44
class Class constructor(private var banana: Int, apple: String) :
5-
// ^^^^^ definition snapshots/Class# class Class : kotlin.Throwable
6-
// ^^^^^^^^^^^ definition snapshots/Class#`<init>`(). constructor Class(banana: kotlin.Int, apple: kotlin.String)
7-
// ^^^^^^ definition snapshots/Class#banana. var banana: kotlin.Int
8-
// ^^^^^^ definition snapshots/Class#getBanana(). var banana: kotlin.Int
9-
// ^^^^^^ definition snapshots/Class#setBanana(). var banana: kotlin.Int
5+
// ^^^^^ definition snapshots/Class# public final class Class : kotlin.Throwable
6+
// ^^^^^^^^^^^ definition snapshots/Class#`<init>`(). public constructor Class(banana: kotlin.Int, apple: kotlin.String)
7+
// ^^^^^^ definition snapshots/Class#banana. private final var banana: kotlin.Int
8+
// ^^^^^^ definition snapshots/Class#getBanana(). private final var banana: kotlin.Int
9+
// ^^^^^^ definition snapshots/Class#setBanana(). private final var banana: kotlin.Int
1010
// ^^^^^^ definition snapshots/Class#`<init>`().(banana) value-parameter banana: kotlin.Int
1111
// ^^^ reference kotlin/Int#
1212
// ^^^^^ definition snapshots/Class#`<init>`().(apple) value-parameter apple: kotlin.String
@@ -23,25 +23,25 @@ class Class constructor(private var banana: Int, apple: String) :
2323
}
2424

2525
val asdf =
26-
// ^^^^ definition snapshots/Class#asdf. val asdf: kotlin.Any
27-
// ^^^^ definition snapshots/Class#getAsdf(). val asdf: kotlin.Any
26+
// ^^^^ definition snapshots/Class#asdf. public final val asdf: kotlin.Any
27+
// ^^^^ definition snapshots/Class#getAsdf(). public final val asdf: kotlin.Any
2828
object {
2929
fun doStuff() = Unit
30-
// ^^^^^^^ definition local0 fun doStuff(): kotlin.Unit
30+
// ^^^^^^^ definition local0 public final fun doStuff()
3131
// ^^^^ reference kotlin/Unit#
3232
}
3333

3434
constructor() : this(1, "")
35-
//^^^^^^^^^^^ definition snapshots/Class#`<init>`(+1). constructor Class()
35+
//^^^^^^^^^^^ definition snapshots/Class#`<init>`(+1). public constructor Class()
3636

3737
constructor(banana: Int) : this(banana, "")
38-
//^^^^^^^^^^^ definition snapshots/Class#`<init>`(+2). constructor Class(banana: kotlin.Int)
38+
//^^^^^^^^^^^ definition snapshots/Class#`<init>`(+2). public constructor Class(banana: kotlin.Int)
3939
// ^^^^^^ definition snapshots/Class#`<init>`(+2).(banana) value-parameter banana: kotlin.Int
4040
// ^^^ reference kotlin/Int#
4141
// ^^^^^^ reference snapshots/Class#`<init>`(+2).(banana)
4242

4343
fun run() {
44-
// ^^^ definition snapshots/Class#run(). fun run(): kotlin.Unit
44+
// ^^^ definition snapshots/Class#run(). public final fun run()
4545
println(Class::class)
4646
// ^^^^^^^ reference kotlin/io/ConsoleKt#println(+1).
4747
// ^^^^^ reference snapshots/Class#

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package snapshots
22
// ^^^^^^^^^ reference snapshots/
33

44
class CompanionOwner {
5-
// ^^^^^^^^^^^^^^ definition snapshots/CompanionOwner# class CompanionOwner
6-
// ^^^^^^^^^^^^^^ definition snapshots/CompanionOwner#`<init>`(). constructor CompanionOwner()
5+
// ^^^^^^^^^^^^^^ definition snapshots/CompanionOwner# public final class CompanionOwner
6+
// ^^^^^^^^^^^^^^ definition snapshots/CompanionOwner#`<init>`(). public constructor CompanionOwner()
77
companion object {
8-
// ^^^^^^^^^ definition snapshots/CompanionOwner#Companion# companion object
8+
// ^^^^^^^^^ definition snapshots/CompanionOwner#Companion# public companion object
99
fun create(): CompanionOwner = CompanionOwner()
10-
// ^^^^^^ definition snapshots/CompanionOwner#Companion#create(). fun create(): snapshots.CompanionOwner
10+
// ^^^^^^ definition snapshots/CompanionOwner#Companion#create(). public final fun create(): snapshots.CompanionOwner
1111
// ^^^^^^^^^^^^^^ reference snapshots/CompanionOwner#
1212
// ^^^^^^^^^^^^^^ reference snapshots/CompanionOwner#`<init>`().
1313
}
1414
fun create(): Int = CompanionOwner.create().hashCode()
15-
// ^^^^^^ definition snapshots/CompanionOwner#create(). fun create(): kotlin.Int
15+
// ^^^^^^ definition snapshots/CompanionOwner#create(). public final fun create(): kotlin.Int
1616
// ^^^ reference kotlin/Int#
1717
// ^^^^^^^^^^^^^^ reference snapshots/CompanionOwner#Companion#
1818
// ^^^^^^ reference snapshots/CompanionOwner#Companion#create().

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import java.io.Serializable
77
// ^^^^^^^^^^^^ reference java/io/Serializable#
88

99
abstract class DocstringSuperclass
10-
// ^^^^^^^^^^^^^^^^^^^ definition snapshots/DocstringSuperclass# class DocstringSuperclass
11-
// ^^^^^^^^^^^^^^^^^^^ definition snapshots/DocstringSuperclass#`<init>`(). constructor DocstringSuperclass()
10+
// ^^^^^^^^^^^^^^^^^^^ definition snapshots/DocstringSuperclass# public abstract class DocstringSuperclass
11+
// ^^^^^^^^^^^^^^^^^^^ definition snapshots/DocstringSuperclass#`<init>`(). public constructor DocstringSuperclass()
1212
/** Example class docstring. */
1313
class Docstrings : DocstringSuperclass(), Serializable {
14-
// ^^^^^^^^^^ definition snapshots/Docstrings# class Docstrings : snapshots.DocstringSuperclass, java.io.Serializable
15-
// ^^^^^^^^^^ definition snapshots/Docstrings#`<init>`(). constructor Docstrings()
14+
// ^^^^^^^^^^ definition snapshots/Docstrings# public final class Docstrings : snapshots.DocstringSuperclass, java.io.Serializable
15+
// ^^^^^^^^^^ definition snapshots/Docstrings#`<init>`(). public constructor Docstrings()
1616
// ^^^^^^^^^^^^^^^^^^^ reference snapshots/DocstringSuperclass#`<init>`().
1717
// ^^^^^^^^^^^^ reference java/io/Serializable#
1818
}
1919

2020
/** Example method docstring. */
2121
fun docstrings() { }
22-
// ^^^^^^^^^^ definition snapshots/DocstringsKt#docstrings(). fun docstrings(): kotlin.Unit
22+
// ^^^^^^^^^^ definition snapshots/DocstringsKt#docstrings(). public fun docstrings()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package snapshots
22
// ^^^^^^^^^ reference snapshots/
33

44
fun sampleText(x: String = "") {
5-
// ^^^^^^^^^^ definition snapshots/FunctionsKt#sampleText(). fun sampleText(x: kotlin.String = ...): kotlin.Unit
5+
// ^^^^^^^^^^ definition snapshots/FunctionsKt#sampleText(). public fun sampleText(x: kotlin.String = ...)
66
// ^ definition snapshots/FunctionsKt#sampleText().(x) value-parameter x: kotlin.String = ...
77
// ^^^^^^ reference kotlin/String#
88
println(x)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package snapshots
22
// ^^^^^^^^^ reference snapshots/
33

44
val x = arrayListOf<String>().forEachIndexed { i, s -> println("$i $s") }
5-
// ^ definition snapshots/LambdasKt#x. val x: kotlin.Unit
6-
// ^ definition snapshots/LambdasKt#getX(). val x: kotlin.Unit
5+
// ^ definition snapshots/LambdasKt#x. public val x: kotlin.Unit
6+
// ^ definition snapshots/LambdasKt#getX(). public val x: kotlin.Unit
77
// ^^^^^^^^^^^ reference kotlin/collections/CollectionsKt#arrayListOf().
88
// ^^^^^^ reference kotlin/String#
99
// ^^^^^^^^^^^^^^ reference kotlin/collections/CollectionsKt#forEachIndexed(+9).
@@ -14,15 +14,15 @@ val x = arrayListOf<String>().forEachIndexed { i, s -> println("$i $s") }
1414
// ^ reference local1
1515

1616
val y = "fdsa".run { this.toByteArray() }
17-
// ^ definition snapshots/LambdasKt#y. val y: kotlin.ByteArray
18-
// ^ definition snapshots/LambdasKt#getY(). val y: kotlin.ByteArray
17+
// ^ definition snapshots/LambdasKt#y. public val y: kotlin.ByteArray
18+
// ^ definition snapshots/LambdasKt#getY(). public val y: kotlin.ByteArray
1919
// ^^^ reference kotlin/StandardKt#run(+1).
2020
// ^^^^ reference
2121
// ^^^^^^^^^^^ reference kotlin/text/StringsKt#toByteArray().
2222

2323
val z = y.let { it.size }
24-
// ^ definition snapshots/LambdasKt#z. val z: kotlin.Int
25-
// ^ definition snapshots/LambdasKt#getZ(). val z: kotlin.Int
24+
// ^ definition snapshots/LambdasKt#z. public val z: kotlin.Int
25+
// ^ definition snapshots/LambdasKt#getZ(). public val z: kotlin.Int
2626
// ^ reference snapshots/LambdasKt#y.
2727
// ^ reference snapshots/LambdasKt#getY().
2828
// ^^^ reference kotlin/StandardKt#let().

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import java.lang.RuntimeException
77
// ^^^^^^^^^^^^^^^^ reference java/lang/RuntimeException#
88

99
object ObjectKt {
10-
// ^^^^^^^^ definition snapshots/ObjectKt# object ObjectKt
10+
// ^^^^^^^^ definition snapshots/ObjectKt# public object ObjectKt
1111
fun fail(message: String?): Nothing {
12-
// ^^^^ definition snapshots/ObjectKt#fail(). fun fail(message: kotlin.String?): kotlin.Nothing
12+
// ^^^^ definition snapshots/ObjectKt#fail(). public final fun fail(message: kotlin.String?): kotlin.Nothing
1313
// ^^^^^^^ definition snapshots/ObjectKt#fail().(message) value-parameter message: kotlin.String?
1414
// ^^^^^^ reference kotlin/String#
1515
// ^^^^^^^ reference kotlin/Nothing#

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ class SemanticdbTextDocumentBuilder(
111111
descriptor: DeclarationDescriptor
112112
): Semanticdb.Documentation = Documentation {
113113
format = Semanticdb.Documentation.Format.MARKDOWN
114-
val signature = DescriptorRenderer.COMPACT.render(descriptor)
114+
val signature =
115+
DescriptorRenderer.COMPACT_WITH_MODIFIERS
116+
.withOptions {
117+
withSourceFileForTopLevel = true
118+
unitReturnType = false
119+
}
120+
.render(descriptor)
115121
val kdoc =
116122
when (descriptor) {
117123
is DeclarationDescriptorWithSource -> descriptor.findKDocString() ?: ""
@@ -141,6 +147,7 @@ class SemanticdbTextDocumentBuilder(
141147
start++
142148
}
143149
var end = if (line.endsWith("*/")) line.length - 3 else line.length - 1
150+
end = maxOf(start, end)
144151
while (end > start && Character.isWhitespace(line[end])) {
145152
end--
146153
}

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

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.tschuchort.compiletesting.KotlinCompilation
88
import com.tschuchort.compiletesting.PluginOption
99
import com.tschuchort.compiletesting.SourceFile
1010
import io.kotest.assertions.assertSoftly
11+
import io.kotest.assertions.fail
1112
import io.kotest.assertions.withClue
1213
import io.kotest.matchers.collections.shouldContain
1314
import io.kotest.matchers.shouldBe
@@ -567,62 +568,24 @@ class AnalyzerTest {
567568
import java.io.Serializable
568569
abstract class DocstringSuperclass
569570
570-
/** Example class docstring. */
571+
/** Example class docstring */
571572
class Docstrings: DocstringSuperclass(), Serializable
572573
573-
/** Example method docstring. */
574+
/**
575+
* Example method docstring
576+
*
577+
**/
574578
inline fun docstrings(msg: String): Int { return msg.length }
575579
""".trimIndent())
576-
val obtainedSymbols =
577-
document
578-
.symbolsList
579-
.map { "----------\n${it.symbol}\n${it.documentation.message}" }
580-
.joinToString("\n")
581-
val expectedSymbols =
582-
"""
583-
----------
584-
sample/DocstringSuperclass#
585-
```kt
586-
class DocstringSuperclass
587-
```
588-
----------
589-
sample/DocstringSuperclass#`<init>`().
590-
```kt
591-
constructor DocstringSuperclass()
592-
```
593-
----------
594-
sample/Docstrings#
595-
```kt
596-
class Docstrings : sample.DocstringSuperclass, java.io.Serializable
597-
```
598-
599-
----
600-
601-
Example class docstring
602-
----------
603-
sample/Docstrings#`<init>`().
604-
```kt
605-
constructor Docstrings()
606-
```
607-
608-
----
609-
610-
Example class docstring
611-
----------
612-
sample/TestKt#docstrings().
613-
```kt
614-
inline fun docstrings(msg: kotlin.String): kotlin.Int
615-
```
616-
617-
----
618-
619-
Example method docstring
620-
----------
621-
sample/TestKt#docstrings().(msg)
622-
```kt
623-
value-parameter msg: kotlin.String
624-
```
625-
""".trim()
626-
assertEquals(expectedSymbols, obtainedSymbols)
580+
document.assertDocumentation("sample/Docstrings#", "Example class docstring")
581+
document.assertDocumentation("sample/TestKt#docstrings().", "Example method docstring")
582+
}
583+
584+
private fun TextDocument.assertDocumentation(symbol: String, expectedDocumentation: String) {
585+
val markdown =
586+
this.symbolsList.find { it.symbol == symbol }?.documentation?.message
587+
?: fail("no documentation for symbol $symbol")
588+
val obtainedDocumentation = markdown.split("----").last().trim()
589+
assertEquals(expectedDocumentation, obtainedDocumentation)
627590
}
628591
}

0 commit comments

Comments
 (0)