summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeigh McCulloch <leigh@mcchouse.com>2019-03-06 06:24:26 +0000
committerLeigh McCulloch <leigh@mcchouse.com>2019-03-06 06:30:09 +0000
commit6506f8ff47385f04d5f6f3ca47538405f5e77b47 (patch)
tree80577311aecb706fafa8940bf14776bea2d60c20
parenta9ff189c2707a9101bbfb65c5dbce0e470e0b74a (diff)
downloadjava-language-server-6506f8ff47385f04d5f6f3ca47538405f5e77b47.zip
Display docs correctly in hover
What === Display docs are plaintext in hover, instead of inside a GitHub markdown fenced markdown code block. Why === Hover text can be made up of multiple MarkedStrings where a MarkedString is either plaintext, or a codeblock for a code language. Docs are usually intended to be displayed as plaintext (in markdown), with the code blocks included alongside it. The docs shouldn't be returned as one of the code blocks. Reference === https://microsoft.github.io/language-server-protocol/specification#textDocument_hover
-rw-r--r--src/main/java/org/javacs/JavaLanguageServer.java10
-rw-r--r--src/main/java/org/javacs/lsp/MarkedString.java34
2 files changed, 40 insertions, 4 deletions
diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java
index 2d2e3bc..9d5b33d 100644
--- a/src/main/java/org/javacs/JavaLanguageServer.java
+++ b/src/main/java/org/javacs/JavaLanguageServer.java
@@ -641,16 +641,18 @@ class JavaLanguageServer extends LanguageServer {
var el = activeFileCache.element(line, column);
if (!el.isPresent()) return Optional.empty();
- // Add code hover message
var result = new ArrayList<MarkedString>();
- var code = hoverCode(el.get());
- result.add(new MarkedString("java", code));
+
// Add docs hover message
var docs = hoverDocs(el.get());
if (docs.isPresent()) {
- result.add(new MarkedString("markdown", docs.get()));
+ result.add(new MarkedString(docs.get()));
}
+ // Add code hover message
+ var code = hoverCode(el.get());
+ result.add(new MarkedString("java", code));
+
return Optional.of(new Hover(result));
}
diff --git a/src/main/java/org/javacs/lsp/MarkedString.java b/src/main/java/org/javacs/lsp/MarkedString.java
index d042d78..280225b 100644
--- a/src/main/java/org/javacs/lsp/MarkedString.java
+++ b/src/main/java/org/javacs/lsp/MarkedString.java
@@ -1,12 +1,46 @@
package org.javacs.lsp;
+import java.io.IOException;
+
+import com.google.gson.annotations.JsonAdapter;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+import com.google.gson.stream.JsonWriter;
+import com.google.gson.TypeAdapter;
+
+@JsonAdapter(MarkedString.Adapter.class)
public class MarkedString {
public String language, value;
public MarkedString() {}
+ public MarkedString(String value) {
+ this.value = value;
+ }
+
public MarkedString(String language, String value) {
this.language = language;
this.value = value;
}
+
+ public static class Adapter extends TypeAdapter<MarkedString> {
+ @Override
+ public void write(JsonWriter out, MarkedString markedString) throws IOException {
+ if (markedString.language == null) {
+ out.value(markedString.value);
+ } else {
+ out.beginObject();
+ out.name("language");
+ out.value(markedString.language);
+ out.name("value");
+ out.value(markedString.value);
+ out.endObject();
+ }
+ }
+
+ @Override
+ public MarkedString read(JsonReader reader) throws IOException {
+ throw new UnsupportedOperationException("Deserializing MarkedString's is unsupported.");
+ }
+ }
}