File tree Expand file tree Collapse file tree 3 files changed +65
-10
lines changed
lsif-java/src/main/scala/com/sourcegraph/lsif_java
tests/unit/src/test/scala/tests Expand file tree Collapse file tree 3 files changed +65
-10
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package com.sourcegraph.lsif_java
3
3
import scala .jdk .CollectionConverters ._
4
4
5
5
import com .sourcegraph .lsif_java .commands .CommentSyntax
6
+ import com .sourcegraph .lsif_java .commands .SnapshotLsifCommand
6
7
import com .sourcegraph .lsif_semanticdb .LsifTextDocument
7
8
import com .sourcegraph .lsif_semanticdb .SignatureFormatter
8
9
import com .sourcegraph .lsif_semanticdb .Symtab
@@ -88,11 +89,23 @@ object SemanticdbPrinters {
88
89
.append(
89
90
symtab.symbols.asScala.get(occ.getSymbol) match {
90
91
case Some (info) if occ.getRole == Role .DEFINITION =>
91
- val sig = new SignatureFormatter (info, symtab).formatSymbol()
92
- if (sig.isEmpty)
92
+ val signature : String =
93
+ if (info.hasSignature) {
94
+ new SignatureFormatter (info, symtab)
95
+ .formatSymbol()
96
+ .trim
97
+ .replace('\n ' , ' ' )
98
+ } else if (info.hasDocumentation) {
99
+ SnapshotLsifCommand
100
+ .signatureLines(info.getDocumentation.getMessage)
101
+ .mkString(" " )
102
+ } else {
103
+ " "
104
+ }
105
+ if (signature.isEmpty)
93
106
" " + info.getDisplayName
94
107
else
95
- " " + sig.trim.replace( ' \n ' , ' ' )
108
+ " " + signature
96
109
case _ =>
97
110
" "
98
111
}
Original file line number Diff line number Diff line change @@ -143,13 +143,7 @@ object SnapshotLsifCommand {
143
143
resultSetId <- lsif.next.get(o.getId).toList
144
144
hoverId <- lsif.hoverEdges.get(resultSetId).toList
145
145
hover <- lsif.hoverVertexes.get(hoverId).toList
146
- line <- hover
147
- .getContents
148
- .getValue
149
- .linesIterator
150
- .dropWhile(! _.startsWith(" ```" ))
151
- .drop(1 )
152
- .takeWhile(_ != " ```" )
146
+ line <- signatureLines(hover.getContents.getValue)
153
147
} yield line
154
148
).mkString(" \n " )
155
149
val symInfo = SymbolInformation
@@ -164,6 +158,14 @@ object SnapshotLsifCommand {
164
158
lsif.documents.values.map(_.build()).toList
165
159
}
166
160
161
+ def signatureLines (documentation : String ): Iterator [String ] = {
162
+ documentation
163
+ .linesIterator
164
+ .dropWhile(! _.startsWith(" ```" ))
165
+ .drop(1 )
166
+ .takeWhile(_ != " ```" )
167
+ }
168
+
167
169
class IndexedLsif (
168
170
val path : Path ,
169
171
val objects : mutable.Buffer [LsifObject ],
Original file line number Diff line number Diff line change 1
1
package tests
2
2
3
3
import com .sourcegraph .lsif_java .SemanticdbPrinters
4
+ import com .sourcegraph .semanticdb_javac .Semanticdb .Documentation
4
5
import com .sourcegraph .semanticdb_javac .Semanticdb .Range
6
+ import com .sourcegraph .semanticdb_javac .Semanticdb .SymbolInformation
5
7
import com .sourcegraph .semanticdb_javac .Semanticdb .SymbolOccurrence
6
8
import com .sourcegraph .semanticdb_javac .Semanticdb .SymbolOccurrence .Role
7
9
import com .sourcegraph .semanticdb_javac .Semanticdb .TextDocument
@@ -84,4 +86,42 @@ class SemanticdbPrintersSuite extends FunSuite {
84
86
)
85
87
}
86
88
89
+ test(" documentation" ) {
90
+ val doc = TextDocument
91
+ .newBuilder()
92
+ .setText(" fun main() {}\n " )
93
+ .addOccurrences(
94
+ SymbolOccurrence
95
+ .newBuilder()
96
+ .setSymbol(" main()." )
97
+ .setRange(
98
+ Range
99
+ .newBuilder()
100
+ .setStartLine(0 )
101
+ .setStartCharacter(4 )
102
+ .setEndLine(0 )
103
+ .setEndCharacter(8 )
104
+ )
105
+ .setRole(Role .DEFINITION )
106
+ )
107
+ .addSymbols(
108
+ SymbolInformation
109
+ .newBuilder()
110
+ .setSymbol(" main()." )
111
+ .setDocumentation(
112
+ Documentation
113
+ .newBuilder()
114
+ .setMessage(" ```kt\n fun main(): kotlin.Unit\n ```" )
115
+ )
116
+ )
117
+ .build()
118
+
119
+ assertNoDiff(
120
+ SemanticdbPrinters .printTextDocument(doc),
121
+ """ |fun main() {}
122
+ |// ^^^^ definition main(). fun main(): kotlin.Unit
123
+ |""" .stripMargin
124
+ )
125
+ }
126
+
87
127
}
You can’t perform that action at this time.
0 commit comments