diff options
-rw-r--r-- | src/main/java/org/javacs/JavaLanguageServer.java | 10 | ||||
-rw-r--r-- | src/main/java/org/javacs/lsp/MarkedString.java | 34 |
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."); + } + } } |