Skip to content

Commit

Permalink
Context-aware Java snippets
Browse files Browse the repository at this point in the history
Closes redhat-developer#782

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jan 31, 2023
1 parent 05e23f9 commit 2876f24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
],
"description": "Quarkus test resource class",
"context": {
"type": "io.quarkus.test.junit.QuarkusTest"
"type": "io.quarkus.test.junit.QuarkusTest",
"contentType": "class"
}
},
"Quarkus - new native test resource class": {
Expand All @@ -44,7 +45,8 @@
],
"description": "Quarkus native test resource class",
"context": {
"type": "io.quarkus.test.junit.SubstrateTest"
"type": "io.quarkus.test.junit.SubstrateTest",
"contentType": "class"
}
},
"Quarkus - new integration test resource class": {
Expand All @@ -62,7 +64,8 @@
],
"description": "Quarkus integration test resource class",
"context": {
"type": "io.quarkus.test.junit.QuarkusIntegrationTest"
"type": "io.quarkus.test.junit.QuarkusIntegrationTest",
"contentType": "class"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.Test;

import org.eclipse.lsp4mp.ls.java.JavaTextDocumentSnippetRegistry;
import org.eclipse.lsp4mp.commons.JavaCursorContextKind;
import org.eclipse.lsp4mp.commons.JavaCursorContextResult;
import org.eclipse.lsp4mp.commons.ProjectLabelInfoEntry;
import org.eclipse.lsp4mp.ls.commons.snippets.ISnippetContext;
import org.eclipse.lsp4mp.ls.commons.snippets.Snippet;
Expand Down Expand Up @@ -60,6 +62,12 @@ public void javaSnippets() {
Arrays.asList("io.quarkus.test.junit.QuarkusTest"));
boolean match2 = ((SnippetContextForJava) context).isMatch(new JavaSnippetCompletionContext(projectInfo2, null));
Assert.assertTrue("Project has io.quarkus.test.junit.QuarkusTest type", match2);

boolean match3 = ((SnippetContextForJava) context).isMatch(new JavaSnippetCompletionContext(projectInfo2, new JavaCursorContextResult(JavaCursorContextKind.BEFORE_CLASS, "aaaa")));
Assert.assertFalse("Cursor is not in an empty file", match3);

boolean match4 = ((SnippetContextForJava) context).isMatch(new JavaSnippetCompletionContext(projectInfo2, new JavaCursorContextResult(JavaCursorContextKind.IN_EMPTY_FILE, "aaaa")));
Assert.assertTrue("Cursor is in an empty file", match4);
}

private static Optional<Snippet> findByPrefix(String prefix, SnippetRegistry registry) {
Expand Down

0 comments on commit 2876f24

Please sign in to comment.