diff options
author | George Fraser <george@fivetran.com> | 2019-01-01 16:38:37 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2019-01-01 16:38:37 -0800 |
commit | 6260e5e63a30f348f1f2e5dad08038a4ba4447ce (patch) | |
tree | 056cf1354051221f2ac3cf8f25955935a1c978b2 | |
parent | c1e61a96093a879bcb907f69787223127d53027f (diff) | |
download | java-language-server-6260e5e63a30f348f1f2e5dad08038a4ba4447ce.zip |
Fallback to ? references
-rw-r--r-- | TODOS.md | 8 | ||||
-rw-r--r-- | src/main/java/org/javacs/JavaLanguageServer.java | 29 |
2 files changed, 16 insertions, 21 deletions
@@ -17,10 +17,4 @@ - Go-to-implementation for overridden methods ## Polish -- Show warning for unused local var, unused private method -- Use cached codelens during parse errors to prevent things from jumping around, or codelens-on-save -- Suppress references codelens for inherited methods -- Don't remove imports when there's an unresolved reference to that name - -## JShell -- Support .jshell extension as "scratch pad"
\ No newline at end of file +- Show warning for unused local var, unused private method
\ No newline at end of file diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java index c025c00..2acfc0a 100644 --- a/src/main/java/org/javacs/JavaLanguageServer.java +++ b/src/main/java/org/javacs/JavaLanguageServer.java @@ -1152,31 +1152,32 @@ class JavaLanguageServer extends LanguageServer { var uri = URI.create(uriString); var line = data.get(2).getAsInt() + 1; var character = data.get(3).getAsInt() + 1; - // Find the element being referenced - // TODO only update code lenses when file is saved, then return these lenses from cache + // Update command + var title = countReferencesTitle(uri, line, character); + var arguments = new JsonArray(); + arguments.add(uri.toString()); + arguments.add(line - 1); + arguments.add(character - 1); + unresolved.command = new Command(title, command, arguments); + + return unresolved; + } + + private String countReferencesTitle(URI uri, int line, int character) { updateHoverCache(uri, contents(uri).content); var el = hoverCache.element(line, character); if (el.isEmpty()) { LOG.warning(String.format("No element to resolve code lens at %s(%d,%d)", uri.getPath(), line, character)); - // TODO this causes <<MISSING COMMAND>> to appear - return unresolved; + return "? references"; } var ptr = new Ptr(el.get()); // Update cache if necessary updateCacheCountReferences(uri); // Read reference count from cache var count = cacheCountReferences.getOrDefault(ptr, 0); - // Update command - String title; - if (count == 1) title = "1 reference"; - else title = String.format("%d references", count); - var arguments = new JsonArray(); - arguments.add(uri.toString()); - arguments.add(line - 1); - arguments.add(character - 1); - unresolved.command = new Command(title, command, arguments); - return unresolved; + if (count == 1) return "1 reference"; + return String.format("%d references", count); } @Override |