summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-10-01 19:33:51 -0700
committerGeorge Fraser <george@fivetran.com>2018-10-01 19:36:40 -0700
commitafd13d3988a8581f91666374e8684751caf9da97 (patch)
tree69b34eff8f59c335279b7c557b2e2fc799a4402e
parent6fbc9923a9570482d3fe1fc806788c8036b05f76 (diff)
downloadjava-language-server-afd13d3988a8581f91666374e8684751caf9da97.zip
Fix import static completions
-rw-r--r--TODOS.md1
-rw-r--r--src/main/java/org/javacs/Pruner.java13
-rw-r--r--src/test/java/org/javacs/CompletionsTest.java8
-rw-r--r--src/test/test-project/workspace/src/org/javacs/example/AutocompleteImportStatic.java3
4 files changed, 24 insertions, 1 deletions
diff --git a/TODOS.md b/TODOS.md
index 82f7cfd..f63e0aa 100644
--- a/TODOS.md
+++ b/TODOS.md
@@ -1,7 +1,6 @@
# Todo
## Bugs
-- import static foo.? doesn't auto-complete
- Workspace root as source path crashes compiler
- Nested source roots don't make sense
- @Override snippets include duplicates
diff --git a/src/main/java/org/javacs/Pruner.java b/src/main/java/org/javacs/Pruner.java
index ff81b7c..b029bbd 100644
--- a/src/main/java/org/javacs/Pruner.java
+++ b/src/main/java/org/javacs/Pruner.java
@@ -80,6 +80,19 @@ class Pruner {
}
@Override
+ public Void visitImport(ImportTree node, Void aVoid) {
+ // Erase 'static' keyword so autocomplete works better
+ if (containsCursor(node) && node.isStatic()) {
+ var start = (int) sourcePositions.getStartPosition(root, node);
+ start = contents.indexOf("static", start);
+ var end = start + "static".length();
+ erase(start, end);
+ }
+
+ return super.visitImport(node, aVoid);
+ }
+
+ @Override
public Void visitBlock(BlockTree node, Void aVoid) {
if (containsCursor(node)) {
super.visitBlock(node, aVoid);
diff --git a/src/test/java/org/javacs/CompletionsTest.java b/src/test/java/org/javacs/CompletionsTest.java
index 12e7010..585efdf 100644
--- a/src/test/java/org/javacs/CompletionsTest.java
+++ b/src/test/java/org/javacs/CompletionsTest.java
@@ -792,4 +792,12 @@ public class CompletionsTest extends CompletionsBase {
assertThat(suggestions, hasItem(containsString("implements")));
}
+
+ @Test
+ public void importStaticPackage() {
+ var file = "/org/javacs/example/AutocompleteImportStatic.java";
+ var suggestions = insertText(file, 3, 20);
+
+ assertThat(suggestions, hasItem(containsString("util")));
+ }
}
diff --git a/src/test/test-project/workspace/src/org/javacs/example/AutocompleteImportStatic.java b/src/test/test-project/workspace/src/org/javacs/example/AutocompleteImportStatic.java
new file mode 100644
index 0000000..4fa93ec
--- /dev/null
+++ b/src/test/test-project/workspace/src/org/javacs/example/AutocompleteImportStatic.java
@@ -0,0 +1,3 @@
+package org.javacs.example;
+
+import static java. \ No newline at end of file