summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-31 21:51:29 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-31 21:51:29 -0800
commitfffcb11d28323f8db3686ae66a28cea47f57ff8a (patch)
treedb483438170e149df1fe2682dad13880ee60c44d /src
parentc1a2ec0e932a4d0c35012bee5e9844b1ce8d3332 (diff)
downloadjava-language-server-fffcb11d28323f8db3686ae66a28cea47f57ff8a.zip
Logs
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/javacs/CompileFile.java19
-rw-r--r--src/main/java/org/javacs/JavaLanguageServer.java10
-rw-r--r--src/main/java/org/javacs/Ptr.java2
3 files changed, 26 insertions, 5 deletions
diff --git a/src/main/java/org/javacs/CompileFile.java b/src/main/java/org/javacs/CompileFile.java
index 0b423ed..6d82132 100644
--- a/src/main/java/org/javacs/CompileFile.java
+++ b/src/main/java/org/javacs/CompileFile.java
@@ -61,7 +61,7 @@ public class CompileFile {
LOG.info("...found nothing");
return Optional.empty();
}
- LOG.info(String.format("...found tree `%s`", path.getLeaf()));
+ LOG.info(String.format("...found tree `%s`", showTree(path)));
// Then, convert the path to an element
var el = trees.getElement(path);
@@ -73,6 +73,23 @@ public class CompileFile {
return Optional.of(el);
}
+ private String showTree(TreePath path) {
+ var leaf = path.getLeaf();
+ if (leaf instanceof MethodTree) {
+ var method = (MethodTree) leaf;
+ return method.getName() + "(...)";
+ }
+ if (leaf instanceof ClassTree) {
+ var cls = (ClassTree) leaf;
+ return "class " + cls.getSimpleName();
+ }
+ if (leaf instanceof BlockTree) {
+ var block = (BlockTree) leaf;
+ return String.format("{ ...%d lines... }", block.getStatements().size());
+ }
+ return leaf.toString();
+ }
+
public Optional<TreePath> path(Element e) {
return Optional.ofNullable(trees.getPath(e));
}
diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java
index aedf4d9..c6a18e6 100644
--- a/src/main/java/org/javacs/JavaLanguageServer.java
+++ b/src/main/java/org/javacs/JavaLanguageServer.java
@@ -969,15 +969,18 @@ class JavaLanguageServer extends LanguageServer {
private Map<Ptr, Integer> cacheCountReferences = Collections.emptyMap();
private URI cacheCountReferencesFile = URI.create("file:///NONE");
+ private int cacheCountReferencesVersion = -1;
private void updateCacheCountReferences(URI current) {
- if (cacheCountReferencesFile.equals(current)) return;
+ if (cacheCountReferencesFile.equals(current) && cacheCountReferencesVersion == contents(current).version)
+ return;
LOG.info(String.format("Update cached reference count to %s...", current));
- var content = contents(current).content;
+ var contents = contents(current);
try (var progress = new Progress()) {
- cacheCountReferences = countReferences(current, content, progress);
+ cacheCountReferences = countReferences(current, contents.content, progress);
}
cacheCountReferencesFile = current;
+ cacheCountReferencesVersion = contents.version;
}
private Map<URI, Index> index = new HashMap<>();
@@ -1104,6 +1107,7 @@ class JavaLanguageServer extends LanguageServer {
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;
}
var ptr = new Ptr(el.get());
diff --git a/src/main/java/org/javacs/Ptr.java b/src/main/java/org/javacs/Ptr.java
index 14a18c5..71d1b6c 100644
--- a/src/main/java/org/javacs/Ptr.java
+++ b/src/main/java/org/javacs/Ptr.java
@@ -49,7 +49,7 @@ public class Ptr {
e = e.getEnclosingElement();
}
var name = reverseAndJoin(rev, ".");
- if (!name.matches("(\\w+\\.)*(\\w+|<init>)(\\(.*\\))?"))
+ if (!name.matches("(\\w+\\.)*(<.*>)?(\\w+|<init>)(\\(.*\\))?"))
LOG.warning(String.format("`%s` doesn't look like a name", name));
this.path = name;
}