Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ object SnapshotLsifCommand {
resultSetId <- lsif.next.get(o.getId).toList
hoverId <- lsif.hoverEdges.get(resultSetId).toList
hover <- lsif.hoverVertexes.get(hoverId).toList
contents <- hover.getContents.getValue
} yield contents
).mkString
.split("\n---\n")
.last
.stripPrefix("```java\n")
.stripSuffix("\n```")
line <- hover
.getContents
.getValue
.linesIterator
.dropWhile(!_.startsWith("```"))
.drop(1)
.takeWhile(_ != "```")
} yield line
).mkString("\n")
val symInfo = SymbolInformation
.newBuilder()
// we cheese it a bit here, as this is less work than trying to reconstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,40 +133,37 @@ private Integer processDocumentUnsafe(
String.format("no definition ID for symbol '%s'", occ.getSymbol())));
}

// Hover
// Hover 1: signature
String documentation = symbolInformation.getDocumentation().getMessage();

StringBuilder markupContent = new StringBuilder(documentation.length());

if (!documentation.isEmpty()) {
markupContent.append(documentation.replaceAll("\n", "\n\n"));
}

if (symbolInformation.hasSignature()) {
if (markupContent.length() != 0) markupContent.append("\n---\n");

String language =
doc.semanticdb.getLanguage().toString().toLowerCase(Locale.ROOT).intern();
String signature = new SignatureFormatter(symbolInformation, symtab).formatSymbol();

markupContent.ensureCapacity(
markupContent.length() + signature.length() + language.length() + 8);
markupContent
.append("```")
.append(language)
.append('\n')
.append(signature)
.append("\n```");
} else {
markupContent.append(symbolInformation.getDisplayName());
}

if (markupContent.length() != 0) {
int hoverId =
writer.emitHoverResult(
new MarkupContent(MarkupKind.MARKDOWN, markupContent.toString()));
writer.emitHoverEdge(ids.resultSet, hoverId);
// Hover 2: docstring
if (!documentation.isEmpty()) {
if (markupContent.length() != 0) markupContent.append("\n---\n");
markupContent.append(documentation.replaceAll("\n", "\n\n"));
}

if (markupContent.length() == 0) {
// Always emit a non-empty hover message to prevent Sourcegraph from falling back to
// Search-Based hover messages.
markupContent.append(symbolInformation.getDisplayName());
}

int hoverId =
writer.emitHoverResult(
new MarkupContent(MarkupKind.MARKDOWN, markupContent.toString()));
writer.emitHoverEdge(ids.resultSet, hoverId);
}

// Overrides
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.21")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.8-94-1cfdf0bd")
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % "0.2.0")
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % "0.2.1")
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.6.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
Expand Down
72 changes: 36 additions & 36 deletions tests/snapshots/src/main/generated/index-semanticdb/multifile
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,39 @@ public class Example2 {
│project(2)│
╰───┬┬─────╯
││
╭────────────────────────────╯╰───────────────────────╮
v
╭──────────────────────────────╮ ╭──────────────────╮
│document example/Example2.java│ │referenceResult(9)│
╰────────┬────────────────────╰────┬────────────╯
│ │^
────────────────────────────────────────────────────┼───────╯ ││
│ │
v v
╭────────────────────────╮
│range(58) 3:9 'Example1'│
╰─────────────┬──────────╯ ││
│ ╭───────────────────────────────────────────────────┼───────────┼╯
│ ╰──────────────────────────╮
v │ │
╭────────┴───╮ │
│resultSet(4)│ │
╰───┬───┬──┬─╯ │
│ │ ^│ │
╭────────────╯ │ ││ │
│ │ ││ │
v │ ││ v
╭───────────────────╮ │ ││ ╭──────────────────────────────╮
│definitionResult(7)│ │ ││ │document example/Example1.java│
╰─────────┬─────────╯ │ ││ ╰───────────────┬──────────────╯
│ │ ││ │
│ │ ││ ╰────────────────────────────────╮ │
│ │ ╰┼─────────────────────────────────────────────────────────────────────────────╮ │ │
╰────────────────┼──┼────────────────────────────────────────────────────────────────────────╮ │ │ │
╰──┼────────────────────────────────────────────────────╮ │ │ │ │
│ │ │ │ │
v v v │ v v
╭────────────────────────────────────────────────────────────────────────────╮ ╭────────────────────────╮ ╭──────────┴──────────────╮
│hoverResult(15) Example1 docstring \n---\n```java\npublic class Example1\n```│ │export example/Example1#│ │range(11) 3:13 'Example1'│
╰────────────────────────────────────────────────────────────────────────────╯ ╰────────────────────────╯ ╰─────────────────────────╯
╭─────────────────────────────╯│
v
╭──────────────────────────────╮ ╭──────────────────╮
│document example/Example2.java│ │referenceResult(9)│
╰────────┬────────────────────╯ ╰────┬────────────╯
╰───────────────────────╮^ │
│ │ │ ╰─────────────────────────
╭────────────────────────────────────────────────────┼────╯
v v │ │
╭────────────────────────╮
│range(58) 3:9 'Example1'│
───────────────────────╯ │ │ │
╭───────────────────────────────────────────────────┼─────────╯
v │ │ │
╭────────┴───╮ │ │
│resultSet(4)│ │ │
╰───┬───┬──┬─╯ │ │
│ │ ^│ │ │
╭────────────╯ │ ││ │ │
│ │ ││ │ │
v │ ││ v │
╭───────────────────╮ │ ││ ╭──────────────────────────────╮ │
│definitionResult(7)│ │ ││ │document example/Example1.java│ │
╰─────────┬─────────╯ │ ││ ╰───────────────┬──────────────╯ │
│ │ ││ │ │
│ │ ││ ╰────────────────────────────────╮ │
│ │ ╰┼─────────────────────────────────────────────────────────────────────────────╮ │ │
╰────────────────┼──┼────────────────────────────────────────────────────────────────────────╮ │ │ │
╰──┼────────────────────────────────────────────────────╮ │ │ │ │
│ │ │ │ │ │
v v v │ v v
╭────────────────────────────────────────────────────────────────────────────╮ ╭────────────────────────╮ ╭──────────┴──────────────╮
│hoverResult(15) ```java\npublic class Example1\n```\n---\nExample1 docstring│ │export example/Example1#│ │range(11) 3:13 'Example1'│
╰────────────────────────────────────────────────────────────────────────────╯ ╰────────────────────────╯ ╰─────────────────────────╯
Loading