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
33import scala .jdk .CollectionConverters ._
44
55import com .sourcegraph .lsif_java .commands .CommentSyntax
6+ import com .sourcegraph .lsif_java .commands .SnapshotLsifCommand
67import com .sourcegraph .lsif_semanticdb .LsifTextDocument
78import com .sourcegraph .lsif_semanticdb .SignatureFormatter
89import com .sourcegraph .lsif_semanticdb .Symtab
@@ -88,11 +89,23 @@ object SemanticdbPrinters {
8889 .append(
8990 symtab.symbols.asScala.get(occ.getSymbol) match {
9091 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)
93106 " " + info.getDisplayName
94107 else
95- " " + sig.trim.replace( ' \n ' , ' ' )
108+ " " + signature
96109 case _ =>
97110 " "
98111 }
Original file line number Diff line number Diff line change @@ -143,13 +143,7 @@ object SnapshotLsifCommand {
143143 resultSetId <- lsif.next.get(o.getId).toList
144144 hoverId <- lsif.hoverEdges.get(resultSetId).toList
145145 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)
153147 } yield line
154148 ).mkString(" \n " )
155149 val symInfo = SymbolInformation
@@ -164,6 +158,14 @@ object SnapshotLsifCommand {
164158 lsif.documents.values.map(_.build()).toList
165159 }
166160
161+ def signatureLines (documentation : String ): Iterator [String ] = {
162+ documentation
163+ .linesIterator
164+ .dropWhile(! _.startsWith(" ```" ))
165+ .drop(1 )
166+ .takeWhile(_ != " ```" )
167+ }
168+
167169 class IndexedLsif (
168170 val path : Path ,
169171 val objects : mutable.Buffer [LsifObject ],
Original file line number Diff line number Diff line change 11package tests
22
33import com .sourcegraph .lsif_java .SemanticdbPrinters
4+ import com .sourcegraph .semanticdb_javac .Semanticdb .Documentation
45import com .sourcegraph .semanticdb_javac .Semanticdb .Range
6+ import com .sourcegraph .semanticdb_javac .Semanticdb .SymbolInformation
57import com .sourcegraph .semanticdb_javac .Semanticdb .SymbolOccurrence
68import com .sourcegraph .semanticdb_javac .Semanticdb .SymbolOccurrence .Role
79import com .sourcegraph .semanticdb_javac .Semanticdb .TextDocument
@@ -84,4 +86,42 @@ class SemanticdbPrintersSuite extends FunSuite {
8486 )
8587 }
8688
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+
87127}
You can’t perform that action at this time.
0 commit comments