diff options
-rw-r--r-- | snippets/java.json | 10 | ||||
-rw-r--r-- | src/main/java/org/javacs/JavaCompilerService.java | 19 | ||||
-rw-r--r-- | src/main/java/org/javacs/JavaTextDocumentService.java | 10 |
3 files changed, 21 insertions, 18 deletions
diff --git a/snippets/java.json b/snippets/java.json index 5456168..86f7424 100644 --- a/snippets/java.json +++ b/snippets/java.json @@ -2,9 +2,9 @@ "Array For Loop": { "prefix": "fora", "body": [ - "for (int ${1:i} = 0; ${1:i} < ${2:array}.length; ${1:i}++) {", - "\t${3:type} ${4:each} = ${2:array}[${1:i}];", - "\t$0", + "for (var ${1:i} = 0; ${1:i} < ${2:array}.length; ${1:i}++) {", + " var ${3:each} = ${2:array}[${1:i}];", + " $0", "}" ], "description": "Array For Loop" @@ -12,8 +12,8 @@ "For Comprehension": { "prefix": "for", "body": [ - "for (${1:Type} ${2:each} : ${3:collection}) {", - "\t$0", + "for (var ${1:each} : ${2:collection}) {", + " $0", "}" ], "description": "For Comprehension" diff --git a/src/main/java/org/javacs/JavaCompilerService.java b/src/main/java/org/javacs/JavaCompilerService.java index 1935459..5e2b721 100644 --- a/src/main/java/org/javacs/JavaCompilerService.java +++ b/src/main/java/org/javacs/JavaCompilerService.java @@ -768,8 +768,6 @@ public class JavaCompilerService { result = new ArrayList<>(); var id = (IdentifierTree) node.getAnnotationType(); var partialName = Objects.toString(id.getName(), ""); - // Add @Override, @Test, other simple class names - completeScopeIdentifiers(partialName); // Add @Override ... snippet if ("Override".startsWith(partialName)) { // TODO filter out already-implemented methods using thisMethods @@ -777,12 +775,14 @@ public class JavaCompilerService { var mods = method.getModifiers(); if (mods.contains(Modifier.STATIC) || mods.contains(Modifier.PRIVATE)) continue; - var label = "Override " + ShortTypePrinter.printMethod(method); + var label = "@Override " + ShortTypePrinter.printMethod(method); var snippet = "Override\n" + new TemplatePrinter().printMethod(method) + " {\n $0\n}"; var override = Completion.ofSnippet(label, snippet); result.add(override); } } + // Add @Override, @Test, other simple class names + completeScopeIdentifiers(partialName); } else { super.visitAnnotation(node, nothing); } @@ -796,9 +796,8 @@ public class JavaCompilerService { if (containsCursor(node) && result == null) { LOG.info("...completing identifiers"); result = new ArrayList<>(); - // Does a candidate completion match the name in `node`? - var partialName = Objects.toString(node.getName(), ""); - // Add keywords + + // Add snippets if (insideClass == 0) { // If no package declaration is present, suggest package [inferred name]; if (parse.getPackage() == null) { @@ -819,7 +818,12 @@ public class JavaCompilerService { name = name.substring(0, name.length() - ".java".length()); result.add(Completion.ofSnippet("class " + name, "class " + name + " {\n $0\n}")); } - // Add keywords + } + // Add identifiers + var partialName = Objects.toString(node.getName(), ""); + completeScopeIdentifiers(partialName); + // Add keywords + if (insideClass == 0) { for (var k : TOP_LEVEL_KEYWORDS) { if (k.startsWith(partialName)) { result.add(Completion.ofKeyword(k)); @@ -840,7 +844,6 @@ public class JavaCompilerService { } } } - completeScopeIdentifiers(partialName); } return null; } diff --git a/src/main/java/org/javacs/JavaTextDocumentService.java b/src/main/java/org/javacs/JavaTextDocumentService.java index a5e44e6..b53978a 100644 --- a/src/main/java/org/javacs/JavaTextDocumentService.java +++ b/src/main/java/org/javacs/JavaTextDocumentService.java @@ -92,28 +92,28 @@ class JavaTextDocumentService implements TextDocumentService { i.setKind(completionItemKind(c.element)); // Detailed name will be resolved later, using docs to fill in method names if (!(c.element instanceof ExecutableElement)) i.setDetail(c.element.toString()); - i.setSortText(1 + i.getLabel()); + i.setSortText(2 + i.getLabel()); } else if (c.packagePart != null) { i.setLabel(c.packagePart.name); i.setKind(CompletionItemKind.Module); i.setDetail(c.packagePart.fullName); - i.setSortText(1 + i.getLabel()); + i.setSortText(2 + i.getLabel()); } else if (c.keyword != null) { i.setLabel(c.keyword); i.setKind(CompletionItemKind.Keyword); i.setDetail("keyword"); - i.setSortText(1 + i.getLabel()); + i.setSortText(3 + i.getLabel()); } else if (c.notImportedClass != null) { i.setLabel(Parser.lastName(c.notImportedClass)); i.setKind(CompletionItemKind.Class); i.setDetail(c.notImportedClass); - i.setSortText(1 + i.getLabel()); + i.setSortText(4 + i.getLabel()); } else if (c.snippet != null) { i.setLabel(c.snippet.label); i.setKind(CompletionItemKind.Snippet); i.setInsertText(c.snippet.snippet); i.setInsertTextFormat(InsertTextFormat.Snippet); - i.setSortText(0 + i.getLabel()); + i.setSortText(1 + i.getLabel()); } else throw new RuntimeException(c + " is not valid"); result.add(i); |