Skip to content

Commit 4fd9972

Browse files
committed
Swap order of signature and docstrings in hover messages
Previously, the docstring appeared above the signature in hover messages. This was not ideal because it meant you had to scroll down to see the signature when the docstring is very long (which happens frequently). This commit moves the signature to the top of the hover message so you can always see it without scrolling. Fixes #284
1 parent 4fc009e commit 4fd9972

File tree

5 files changed

+90
-90
lines changed

5 files changed

+90
-90
lines changed

lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/SnapshotLsifCommand.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ object SnapshotLsifCommand {
148148
resultSetId <- lsif.next.get(o.getId).toList
149149
hoverId <- lsif.hoverEdges.get(resultSetId).toList
150150
hover <- lsif.hoverVertexes.get(hoverId).toList
151-
contents <- hover.getContents.getValue
152-
} yield contents
153-
).mkString
154-
.split("\n---\n")
155-
.last
156-
.stripPrefix("```java\n")
157-
.stripSuffix("\n```")
151+
line <- hover
152+
.getContents
153+
.getValue
154+
.linesIterator
155+
.dropWhile(!_.startsWith("```"))
156+
.drop(1)
157+
.takeWhile(_ != "```")
158+
} yield line
159+
).mkString("\n")
158160
val symInfo = SymbolInformation
159161
.newBuilder()
160162
// we cheese it a bit here, as this is less work than trying to reconstruct

lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/LsifSemanticdb.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,40 +133,37 @@ private Integer processDocumentUnsafe(
133133
String.format("no definition ID for symbol '%s'", occ.getSymbol())));
134134
}
135135

136-
// Hover
136+
// Hover 1: signature
137137
String documentation = symbolInformation.getDocumentation().getMessage();
138-
139138
StringBuilder markupContent = new StringBuilder(documentation.length());
140-
141-
if (!documentation.isEmpty()) {
142-
markupContent.append(documentation.replaceAll("\n", "\n\n"));
143-
}
144-
145139
if (symbolInformation.hasSignature()) {
146-
if (markupContent.length() != 0) markupContent.append("\n---\n");
147-
148140
String language =
149141
doc.semanticdb.getLanguage().toString().toLowerCase(Locale.ROOT).intern();
150142
String signature = new SignatureFormatter(symbolInformation, symtab).formatSymbol();
151-
152-
markupContent.ensureCapacity(
153-
markupContent.length() + signature.length() + language.length() + 8);
154143
markupContent
155144
.append("```")
156145
.append(language)
157146
.append('\n')
158147
.append(signature)
159148
.append("\n```");
160-
} else {
161-
markupContent.append(symbolInformation.getDisplayName());
162149
}
163150

164-
if (markupContent.length() != 0) {
165-
int hoverId =
166-
writer.emitHoverResult(
167-
new MarkupContent(MarkupKind.MARKDOWN, markupContent.toString()));
168-
writer.emitHoverEdge(ids.resultSet, hoverId);
151+
// Hover 2: docstring
152+
if (!documentation.isEmpty()) {
153+
if (markupContent.length() != 0) markupContent.append("\n---\n");
154+
markupContent.append(documentation.replaceAll("\n", "\n\n"));
169155
}
156+
157+
if (markupContent.length() == 0) {
158+
// Always emit a non-empty hover message to prevent Sourcegraph from falling back to
159+
// Search-Based hover messages.
160+
markupContent.append(symbolInformation.getDisplayName());
161+
}
162+
163+
int hoverId =
164+
writer.emitHoverResult(
165+
new MarkupContent(MarkupKind.MARKDOWN, markupContent.toString()));
166+
writer.emitHoverEdge(ids.resultSet, hoverId);
170167
}
171168

172169
// Overrides

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.21")
66
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")
77
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")
88
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.8-94-1cfdf0bd")
9-
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % "0.2.0")
9+
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % "0.2.1")
1010
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.6.0")
1111
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
1212
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")

tests/snapshots/src/main/generated/index-semanticdb/multifile

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,39 @@ public class Example2 {
2828
│project(2)│
2929
╰───┬┬─────╯
3030
││
31-
╭────────────────────────────╯╰───────────────────────╮
32-
33-
v
34-
╭──────────────────────────────╮ ╭──────────────────╮
35-
│document example/Example2.java│ │referenceResult(9)│
36-
╰────────┬────────────────────╰────┬────────────╯
37-
│ │^
38-
────────────────────────────────────────────────────┼───────╯ ││
39-
│ │
40-
v v
41-
╭────────────────────────╮
42-
│range(58) 3:9 'Example1'│
43-
╰─────────────┬──────────╯ ││
44-
│ ╭───────────────────────────────────────────────────┼───────────┼╯
45-
│ ╰──────────────────────────╮
46-
v │ │
47-
╭────────┴───╮ │
48-
│resultSet(4)│ │
49-
╰───┬───┬──┬─╯ │
50-
│ │ ^│ │
51-
╭────────────╯ │ ││ │
52-
│ │ ││ │
53-
v │ ││ v
54-
╭───────────────────╮ │ ││ ╭──────────────────────────────╮
55-
│definitionResult(7)│ │ ││ │document example/Example1.java│
56-
╰─────────┬─────────╯ │ ││ ╰───────────────┬──────────────╯
57-
│ │ ││ │
58-
│ │ ││ ╰────────────────────────────────╮ │
59-
│ │ ╰┼─────────────────────────────────────────────────────────────────────────────╮ │ │
60-
╰────────────────┼──┼────────────────────────────────────────────────────────────────────────╮ │ │ │
61-
╰──┼────────────────────────────────────────────────────╮ │ │ │ │
62-
│ │ │ │ │
63-
v v v │ v v
64-
╭────────────────────────────────────────────────────────────────────────────╮ ╭────────────────────────╮ ╭──────────┴──────────────╮
65-
│hoverResult(15) Example1 docstring \n---\n```java\npublic class Example1\n```│ │export example/Example1#│ │range(11) 3:13 'Example1'│
66-
╰────────────────────────────────────────────────────────────────────────────╯ ╰────────────────────────╯ ╰─────────────────────────╯
31+
╭─────────────────────────────╯│
32+
33+
v
34+
╭──────────────────────────────╮ ╭──────────────────╮
35+
│document example/Example2.java│ │referenceResult(9)│
36+
╰────────┬────────────────────╯ ╰────┬────────────╯
37+
╰───────────────────────╮^ │
38+
│ │ │ ╰─────────────────────────
39+
╭────────────────────────────────────────────────────┼────╯
40+
41+
v v │ │
42+
╭────────────────────────╮
43+
│range(58) 3:9 'Example1'│
44+
───────────────────────╯ │ │ │
45+
╭───────────────────────────────────────────────────┼─────────╯
46+
v │ │ │
47+
╭────────┴───╮ │ │
48+
│resultSet(4)│ │ │
49+
╰───┬───┬──┬─╯ │ │
50+
│ │ ^│ │ │
51+
╭────────────╯ │ ││ │ │
52+
│ │ ││ │ │
53+
v │ ││ v │
54+
╭───────────────────╮ │ ││ ╭──────────────────────────────╮ │
55+
│definitionResult(7)│ │ ││ │document example/Example1.java│ │
56+
╰─────────┬─────────╯ │ ││ ╰───────────────┬──────────────╯ │
57+
│ │ ││ │ │
58+
│ │ ││ ╰────────────────────────────────╮ │
59+
│ │ ╰┼─────────────────────────────────────────────────────────────────────────────╮ │ │
60+
╰────────────────┼──┼────────────────────────────────────────────────────────────────────────╮ │ │ │
61+
╰──┼────────────────────────────────────────────────────╮ │ │ │ │
62+
│ │ │ │ │ │
63+
v v v │ v v
64+
╭────────────────────────────────────────────────────────────────────────────╮ ╭────────────────────────╮ ╭──────────┴──────────────╮
65+
│hoverResult(15) ```java\npublic class Example1\n```\n---\nExample1 docstring│ │export example/Example1#│ │range(11) 3:13 'Example1'│
66+
╰────────────────────────────────────────────────────────────────────────────╯ ╰────────────────────────╯ ╰─────────────────────────╯

0 commit comments

Comments
 (0)