summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/javacs/JavaLanguageServer.java15
-rw-r--r--src/main/java/org/javacs/lsp/MarkedString.java34
2 files changed, 43 insertions, 6 deletions
diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java
index 798e71a..cbe92d0 100644
--- a/src/main/java/org/javacs/JavaLanguageServer.java
+++ b/src/main/java/org/javacs/JavaLanguageServer.java
@@ -32,6 +32,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.UUID;
+import java.util.function.Predicate;
import java.util.logging.Logger;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@@ -641,15 +642,17 @@ 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.hover", code));
+
// Add docs hover message
var docs = hoverDocs(el.get());
- if (docs.isPresent()) {
- result.add(new MarkedString("markdown", docs.get()));
- }
+ docs.filter(Predicate.not(String::isBlank)).ifPresent(doc -> {
+ result.add(new MarkedString(doc));
+ });
+
+ // 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.");
+ }
+ }
}