diff options
Diffstat (limited to 'src/test/java/org/javacs')
-rw-r--r-- | src/test/java/org/javacs/CodeLensTest.java | 45 | ||||
-rw-r--r-- | src/test/java/org/javacs/CompletionsBase.java | 30 | ||||
-rw-r--r-- | src/test/java/org/javacs/CompletionsTest.java | 55 | ||||
-rw-r--r-- | src/test/java/org/javacs/FindReferencesTest.java | 27 | ||||
-rw-r--r-- | src/test/java/org/javacs/GotoTest.java | 26 | ||||
-rw-r--r-- | src/test/java/org/javacs/JavaCompilerServiceTest.java | 2 | ||||
-rw-r--r-- | src/test/java/org/javacs/LanguageServerFixture.java | 45 | ||||
-rw-r--r-- | src/test/java/org/javacs/SearchTest.java | 37 | ||||
-rw-r--r-- | src/test/java/org/javacs/SignatureHelpTest.java | 35 | ||||
-rw-r--r-- | src/test/java/org/javacs/SymbolUnderCursorTest.java | 15 | ||||
-rw-r--r-- | src/test/java/org/javacs/lsp/LanguageServerTest.java | 18 | ||||
-rw-r--r-- | src/test/java/org/javacs/lsp/LspTest.java | 15 |
12 files changed, 146 insertions, 204 deletions
diff --git a/src/test/java/org/javacs/CodeLensTest.java b/src/test/java/org/javacs/CodeLensTest.java index 47f265d..29935c5 100644 --- a/src/test/java/org/javacs/CodeLensTest.java +++ b/src/test/java/org/javacs/CodeLensTest.java @@ -6,9 +6,6 @@ import static org.junit.Assert.*; import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; -import java.util.Objects; -import java.util.StringJoiner; -import java.util.concurrent.ExecutionException; import org.javacs.lsp.*; import org.junit.Test; @@ -18,34 +15,24 @@ public class CodeLensTest { private List<? extends CodeLens> lenses(String file) { var uri = FindResource.uri(file); - var params = new CodeLensParams(new TextDocumentIdentifier(uri.toString())); - try { - var lenses = server.getTextDocumentService().codeLens(params).get(); - var resolved = new ArrayList<CodeLens>(); - for (var lens : lenses) { - if (lens.getCommand() == null) { - var gson = new Gson(); - var data = lens.getData(); - var dataJson = gson.toJsonTree(data); - lens.setData(dataJson); - lens = server.getTextDocumentService().resolveCodeLens(lens).get(); - } - resolved.add(lens); + var params = new CodeLensParams(new TextDocumentIdentifier(uri)); + var lenses = server.codeLens(params); + var resolved = new ArrayList<CodeLens>(); + for (var lens : lenses) { + if (lens.command == null) { + var gson = new Gson(); + var data = lens.data; + lens = server.resolveCodeLens(lens); } - return resolved; - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); + resolved.add(lens); } + return resolved; } private List<String> commands(List<? extends CodeLens> lenses) { var commands = new ArrayList<String>(); for (var lens : lenses) { - var command = new StringJoiner(", "); - for (var arg : lens.getCommand().getArguments()) { - command.add(Objects.toString(arg)); - } - commands.add(command.toString()); + commands.add(String.format("%s(%s)", lens.command.command, lens.command.arguments)); } return commands; } @@ -53,8 +40,8 @@ public class CodeLensTest { private List<String> titles(List<? extends CodeLens> lenses) { var titles = new ArrayList<String>(); for (var lens : lenses) { - var line = lens.getRange().getStart().getLine() + 1; - var title = lens.getCommand().getTitle(); + var line = lens.range.start.line + 1; + var title = lens.command.title; titles.add(line + ":" + title); } return titles; @@ -66,9 +53,9 @@ public class CodeLensTest { assertThat(lenses, not(empty())); var commands = commands(lenses); - assertThat(commands, hasItem(containsString("HasTest, null"))); - assertThat(commands, hasItem(containsString("HasTest, testMethod"))); - assertThat(commands, hasItem(containsString("HasTest, otherTestMethod"))); + assertThat(commands, hasItem(containsString("\"HasTest\",null"))); + assertThat(commands, hasItem(containsString("\"HasTest\",\"testMethod\""))); + assertThat(commands, hasItem(containsString("\"HasTest\",\"otherTestMethod\""))); } @Test diff --git a/src/test/java/org/javacs/CompletionsBase.java b/src/test/java/org/javacs/CompletionsBase.java index 8ad10a8..30af123 100644 --- a/src/test/java/org/javacs/CompletionsBase.java +++ b/src/test/java/org/javacs/CompletionsBase.java @@ -2,7 +2,6 @@ package org.javacs; import com.google.gson.Gson; import java.util.*; -import java.util.concurrent.ExecutionException; import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -18,9 +17,9 @@ public class CompletionsBase { } static String itemInsertTemplate(CompletionItem i) { - var text = i.getInsertText(); + var text = i.insertText; - if (text == null) text = i.getLabel(); + if (text == null) text = i.label; assert text != null : "Either insertText or label must be defined"; @@ -37,9 +36,9 @@ public class CompletionsBase { var items = items(file, row, column); var result = new HashSet<String>(); for (var i : items) { - i.setData(new Gson().toJsonTree(i.getData())); + i.data = new Gson().toJsonTree(i.data); var resolved = resolve(i); - result.add(resolved.getDetail()); + result.add(resolved.detail); } return result; } @@ -59,9 +58,9 @@ public class CompletionsBase { } static String itemInsertText(CompletionItem i) { - var text = i.getInsertText(); + var text = i.insertText; - if (text == null) text = i.getLabel(); + if (text == null) text = i.label; assert text != null : "Either insertText or label must be defined"; @@ -76,8 +75,7 @@ public class CompletionsBase { return items.stream() .flatMap( i -> { - if (i.getDocumentation() != null) - return Stream.of(i.getDocumentation().getRight().getValue().trim()); + if (i.documentation != null) return Stream.of(i.documentation.value.trim()); else return Stream.empty(); }) .collect(Collectors.toSet()); @@ -88,20 +86,12 @@ public class CompletionsBase { protected List<? extends CompletionItem> items(String file, int row, int column) { var uri = FindResource.uri(file); var position = - new CompletionParams(new TextDocumentIdentifier(uri.toString()), new Position(row - 1, column - 1)); + new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(row - 1, column - 1)); - try { - return server.getTextDocumentService().completion(position).get().getRight().getItems(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + return server.completion(position).get().items; } protected CompletionItem resolve(CompletionItem item) { - try { - return server.getTextDocumentService().resolveCompletionItem(item).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + return server.resolveCompletionItem(item); } } diff --git a/src/test/java/org/javacs/CompletionsTest.java b/src/test/java/org/javacs/CompletionsTest.java index 864ff24..d213a74 100644 --- a/src/test/java/org/javacs/CompletionsTest.java +++ b/src/test/java/org/javacs/CompletionsTest.java @@ -215,8 +215,8 @@ public class CompletionsTest extends CompletionsBase { } private static String sortText(CompletionItem i) { - if (i.getSortText() != null) return i.getSortText(); - else return i.getLabel(); + if (i.sortText != null) return i.sortText; + else return i.label; } @Test @@ -288,9 +288,9 @@ public class CompletionsTest extends CompletionsBase { var items = items(file, 9, 17); for (var item : items) { - if ("ArrayList".equals(item.getLabel())) { - assertThat(item.getAdditionalTextEdits(), not(nullValue())); - assertThat(item.getAdditionalTextEdits(), not(empty())); + if ("ArrayList".equals(item.label)) { + assertThat(item.additionalTextEdits, not(nullValue())); + assertThat(item.additionalTextEdits, not(empty())); return; } @@ -308,8 +308,8 @@ public class CompletionsTest extends CompletionsBase { var items = items(file, 6, 10); for (var item : items) { - if ("AutocompleteMember".equals(item.getLabel())) { - assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue())); + if ("AutocompleteMember".equals(item.label)) { + assertThat(item.additionalTextEdits, either(empty()).or(nullValue())); return; } @@ -327,8 +327,8 @@ public class CompletionsTest extends CompletionsBase { var items = items(file, 11, 38); for (var item : items) { - if ("ArrayIndexOutOfBoundsException".equals(item.getLabel())) { - assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue())); + if ("ArrayIndexOutOfBoundsException".equals(item.label)) { + assertThat(item.additionalTextEdits, either(empty()).or(nullValue())); return; } @@ -346,8 +346,8 @@ public class CompletionsTest extends CompletionsBase { var items = items(file, 6, 10); for (var item : items) { - if ("AutocompleteOther".equals(item.getLabel())) { - assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue())); + if ("AutocompleteOther".equals(item.label)) { + assertThat(item.additionalTextEdits, either(empty()).or(nullValue())); return; } @@ -365,8 +365,8 @@ public class CompletionsTest extends CompletionsBase { var items = items(file, 12, 14); for (var item : items) { - if ("Arrays".equals(item.getLabel())) { - assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue())); + if ("Arrays".equals(item.label)) { + assertThat(item.additionalTextEdits, either(empty()).or(nullValue())); return; } @@ -384,8 +384,8 @@ public class CompletionsTest extends CompletionsBase { var items = items(file, 10, 26); for (var item : items) { - if ("ArrayBlockingQueue".equals(item.getLabel())) { - assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue())); + if ("ArrayBlockingQueue".equals(item.label)) { + assertThat(item.additionalTextEdits, either(empty()).or(nullValue())); return; } @@ -400,7 +400,7 @@ public class CompletionsTest extends CompletionsBase { // Static methods var items = items(file, 8, 17); - var suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet()); + var suggestions = items.stream().map(i -> i.label).collect(Collectors.toSet()); assertThat(suggestions, hasItems("add", "addAll")); } @@ -476,8 +476,8 @@ public class CompletionsTest extends CompletionsBase { // Static methods var items = items(file, 5, 18); - var suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet()); - var details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet()); + var suggestions = items.stream().map(i -> i.label).collect(Collectors.toSet()); + var details = items.stream().map(i -> i.detail).collect(Collectors.toSet()); assertThat(suggestions, hasItems("restMethod")); assertThat(details, hasItems("void (String... params)")); @@ -501,14 +501,13 @@ public class CompletionsTest extends CompletionsBase { // Static methods var items = items(file, 6, 19); - var suggestions = Lists.transform(items, i -> i.getInsertText()); + var suggestions = Lists.transform(items, i -> i.insertText); assertThat(suggestions, hasItems("ArrayList<>($0)")); for (var each : items) { - if (each.getInsertText().equals("ArrayList<>")) - assertThat( - "new ? auto-imports", each.getAdditionalTextEdits(), both(not(empty())).and(not(nullValue()))); + if (each.insertText.equals("ArrayList<>")) + assertThat("new ? auto-imports", each.additionalTextEdits, both(not(empty())).and(not(nullValue()))); } } @@ -557,17 +556,17 @@ public class CompletionsTest extends CompletionsBase { // Static methods var items = items(file, 4, 25); - var suggestions = Lists.transform(items, i -> i.getLabel()); + var suggestions = Lists.transform(items, i -> i.label); assertThat(suggestions, hasItems("OtherPackagePublic")); assertThat(suggestions, not(hasItems("OtherPackagePrivate"))); // Imports are now being managed by FixImports // for (var item : items) { - // if (item.getLabel().equals("OtherPackagePublic")) + // if (item.label.equals("OtherPackagePublic")) // assertThat( // "Don't import when completing imports", - // item.getAdditionalTextEdits(), + // item.additionalTextEdits, // either(empty()).or(nullValue())); // } } @@ -578,14 +577,14 @@ public class CompletionsTest extends CompletionsBase { // Static methods var items = items(file, 5, 14); - var suggestions = Lists.transform(items, i -> i.getLabel()); + var suggestions = Lists.transform(items, i -> i.label); assertThat(suggestions, hasItems("OtherPackagePublic")); assertThat(suggestions, not(hasItems("OtherPackagePrivate"))); // for (var item : items) { - // if (item.getLabel().equals("OtherPackagePublic")) - // assertThat("Auto-import OtherPackagePublic", item.getAdditionalTextEdits(), not(empty())); + // if (item.label.equals("OtherPackagePublic")) + // assertThat("Auto-import OtherPackagePublic", item.additionalTextEdits, not(empty())); // } } diff --git a/src/test/java/org/javacs/FindReferencesTest.java b/src/test/java/org/javacs/FindReferencesTest.java index 9356ded..e8d51c3 100644 --- a/src/test/java/org/javacs/FindReferencesTest.java +++ b/src/test/java/org/javacs/FindReferencesTest.java @@ -3,10 +3,8 @@ package org.javacs; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import java.net.URI; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; import java.util.logging.Logger; import org.javacs.lsp.*; import org.junit.Test; @@ -20,22 +18,17 @@ public class FindReferencesTest { var uri = FindResource.uri(file); var params = new ReferenceParams(); - params.setTextDocument(new TextDocumentIdentifier(uri.toString())); - params.setUri(uri.toString()); - params.setPosition(new Position(row - 1, column - 1)); - - try { - var locations = server.getTextDocumentService().references(params).get(); - var strings = new ArrayList<String>(); - for (var l : locations) { - var fileName = Parser.fileName(URI.create(l.getUri())); - var line = l.getRange().getStart().getLine(); - strings.add(String.format("%s(%d)", fileName, line + 1)); - } - return strings; - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); + params.textDocument = new TextDocumentIdentifier(uri); + params.position = new Position(row - 1, column - 1); + + var locations = server.findReferences(params); + var strings = new ArrayList<String>(); + for (var l : locations) { + var fileName = Parser.fileName(l.uri); + var line = l.range.start.line; + strings.add(String.format("%s(%d)", fileName, line + 1)); } + return strings; } @Test diff --git a/src/test/java/org/javacs/GotoTest.java b/src/test/java/org/javacs/GotoTest.java index ac60efc..74bc9dd 100644 --- a/src/test/java/org/javacs/GotoTest.java +++ b/src/test/java/org/javacs/GotoTest.java @@ -3,11 +3,9 @@ package org.javacs; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; -import java.net.URI; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; import org.javacs.lsp.*; import org.junit.Ignore; import org.junit.Test; @@ -128,30 +126,24 @@ public class GotoTest { private List<String> doGoto(String file, int row, int column) { TextDocumentIdentifier document = new TextDocumentIdentifier(); - document.setUri(FindResource.uri(file).toString()); + document.uri = FindResource.uri(file); Position position = new Position(); - position.setLine(row); - position.setCharacter(column); + position.line = row; + position.character = column; TextDocumentPositionParams p = new TextDocumentPositionParams(); - p.setTextDocument(document); - p.setPosition(position); + p.textDocument = document; + p.position = position; - // TODO extends is not coloring correctly - List<? extends Location> locations; - try { - locations = server.getTextDocumentService().definition(p).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + var locations = server.gotoDefinition(p); var strings = new ArrayList<String>(); for (var l : locations) { - var fileName = Paths.get(URI.create(l.getUri())).getFileName(); - var start = l.getRange().getStart(); - strings.add(String.format("%s:%d", fileName, start.getLine() + 1)); + var fileName = Paths.get(l.uri).getFileName(); + var start = l.range.start; + strings.add(String.format("%s:%d", fileName, start.line + 1)); } return strings; } diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java index ffcbc26..7b8d20c 100644 --- a/src/test/java/org/javacs/JavaCompilerServiceTest.java +++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java @@ -244,7 +244,7 @@ public class JavaCompilerServiceTest { var uri = r.getCompilationUnit().getSourceFile().toUri(); var fileName = Paths.get(uri).getFileName(); var range = batch.range(r).get(); - stringify.add(String.format("%s:%d", fileName, range.getStart().getLine() + 1)); + stringify.add(String.format("%s:%d", fileName, range.start.line + 1)); } assertThat(stringify, hasItem("GotoDefinition.java:3")); assertThat(stringify, not(hasItem("GotoDefinition.java:6"))); diff --git a/src/test/java/org/javacs/LanguageServerFixture.java b/src/test/java/org/javacs/LanguageServerFixture.java index 6f0a481..2c93283 100644 --- a/src/test/java/org/javacs/LanguageServerFixture.java +++ b/src/test/java/org/javacs/LanguageServerFixture.java @@ -1,8 +1,8 @@ package org.javacs; +import com.google.gson.JsonElement; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.logging.Logger; import org.javacs.lsp.*; @@ -16,53 +16,32 @@ class LanguageServerFixture { } static JavaLanguageServer getJavaLanguageServer() { - return getJavaLanguageServer(DEFAULT_WORKSPACE_ROOT, diagnostic -> LOG.info(diagnostic.getMessage())); + return getJavaLanguageServer(DEFAULT_WORKSPACE_ROOT, diagnostic -> LOG.info(diagnostic.message)); } static JavaLanguageServer getJavaLanguageServer(Path workspaceRoot, Consumer<Diagnostic> onError) { return getJavaLanguageServer( workspaceRoot, - new CustomLanguageClient() { - @Override - public void telemetryEvent(Object o) {} - - @Override - public void publishDiagnostics(PublishDiagnosticsParams publishDiagnosticsParams) { - publishDiagnosticsParams.getDiagnostics().forEach(onError); - } - - @Override - public void showMessage(MessageParams messageParams) {} - - @Override - public CompletableFuture<MessageActionItem> showMessageRequest( - ShowMessageRequestParams showMessageRequestParams) { - return null; + new LanguageClient() { + public void publishDiagnostics(PublishDiagnosticsParams params) { + params.diagnostics.forEach(onError); } - @Override - public void logMessage(MessageParams messageParams) {} - - @Override - public void javaStartProgress(JavaStartProgressParams params) {} + public void showMessage(ShowMessageParams params) {} - @Override - public void javaReportProgress(JavaReportProgressParams params) {} + public void registerCapability(String method, JsonElement options) {} - @Override - public void javaEndProgress() {} + public void customNotification(String method, JsonElement params) {} }); } - private static JavaLanguageServer getJavaLanguageServer(Path workspaceRoot, CustomLanguageClient client) { - var server = new JavaLanguageServer(); + private static JavaLanguageServer getJavaLanguageServer(Path workspaceRoot, LanguageClient client) { + var server = new JavaLanguageServer(client); var init = new InitializeParams(); - init.setRootUri(workspaceRoot.toUri().toString()); - - server.installClient(client); + init.rootUri = workspaceRoot.toUri(); server.initialize(init); - server.initialized(null); + server.initialized(); return server; } diff --git a/src/test/java/org/javacs/SearchTest.java b/src/test/java/org/javacs/SearchTest.java index ace86e8..3ecc567 100644 --- a/src/test/java/org/javacs/SearchTest.java +++ b/src/test/java/org/javacs/SearchTest.java @@ -9,7 +9,6 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Set; -import java.util.concurrent.ExecutionException; import java.util.logging.Logger; import java.util.stream.Collectors; import org.javacs.lsp.*; @@ -27,37 +26,25 @@ public class SearchTest { var textContent = Joiner.on("\n").join(Files.readAllLines(Paths.get(uri))); var document = new TextDocumentItem(); - document.setUri(uri.toString()); - document.setText(textContent); + document.uri = uri; + document.text = textContent; - server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(document, null)); + server.didOpenTextDocument(new DidOpenTextDocumentParams(document)); } private static Set<String> searchWorkspace(String query, int limit) { - try { - return server.getWorkspaceService() - .symbol(new WorkspaceSymbolParams(query)) - .get() - .stream() - .map(result -> result.getName()) - .limit(limit) - .collect(Collectors.toSet()); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + return server.workspaceSymbols(new WorkspaceSymbolParams(query)) + .stream() + .map(result -> result.name) + .limit(limit) + .collect(Collectors.toSet()); } private static Set<String> searchFile(URI uri) { - try { - return server.getTextDocumentService() - .documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(uri.toString()))) - .get() - .stream() - .map(result -> result.getLeft().getName()) - .collect(Collectors.toSet()); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + return server.documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(uri))) + .stream() + .map(result -> result.name) + .collect(Collectors.toSet()); } @Test diff --git a/src/test/java/org/javacs/SignatureHelpTest.java b/src/test/java/org/javacs/SignatureHelpTest.java index 6019021..ec05577 100644 --- a/src/test/java/org/javacs/SignatureHelpTest.java +++ b/src/test/java/org/javacs/SignatureHelpTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.io.IOException; -import java.util.concurrent.ExecutionException; import org.javacs.lsp.*; import org.junit.Test; @@ -13,34 +12,34 @@ public class SignatureHelpTest { public void signatureHelp() throws IOException { var help = doHelp("/org/javacs/example/SignatureHelp.java", 7, 36); - assertThat(help.getSignatures(), hasSize(2)); + assertThat(help.signatures, hasSize(2)); } @Test public void partlyFilledIn() throws IOException { var help = doHelp("/org/javacs/example/SignatureHelp.java", 8, 39); - assertThat(help.getSignatures(), hasSize(2)); - assertThat(help.getActiveSignature(), equalTo(1)); - assertThat(help.getActiveParameter(), equalTo(1)); + assertThat(help.signatures, hasSize(2)); + assertThat(help.activeSignature, equalTo(1)); + assertThat(help.activeParameter, equalTo(1)); } @Test public void constructor() throws IOException { var help = doHelp("/org/javacs/example/SignatureHelp.java", 9, 27); - assertThat(help.getSignatures(), hasSize(1)); - assertThat(help.getSignatures().get(0).getLabel(), startsWith("SignatureHelp")); + assertThat(help.signatures, hasSize(1)); + assertThat(help.signatures.get(0).label, startsWith("SignatureHelp")); } @Test public void platformConstructor() throws IOException { var help = doHelp("/org/javacs/example/SignatureHelp.java", 10, 26); - assertThat(help.getSignatures(), not(empty())); - assertThat(help.getSignatures().get(0).getLabel(), startsWith("ArrayList")); + assertThat(help.signatures, not(empty())); + assertThat(help.signatures.get(0).label, startsWith("ArrayList")); // TODO - // assertThat(help.getSignatures().get(0).getDocumentation(), not(nullValue())); + // assertThat(help.signatures.get(0).documentation, not(nullValue())); } private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer(); @@ -48,22 +47,18 @@ public class SignatureHelpTest { private SignatureHelp doHelp(String file, int row, int column) throws IOException { var document = new TextDocumentIdentifier(); - document.setUri(FindResource.uri(file).toString()); + document.uri = FindResource.uri(file); var position = new Position(); - position.setLine(row - 1); - position.setCharacter(column - 1); + position.line = row - 1; + position.character = column - 1; var p = new TextDocumentPositionParams(); - p.setTextDocument(document); - p.setPosition(position); + p.textDocument = document; + p.position = position; - try { - return server.getTextDocumentService().signatureHelp(p).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } + return server.signatureHelp(p).get(); } } diff --git a/src/test/java/org/javacs/SymbolUnderCursorTest.java b/src/test/java/org/javacs/SymbolUnderCursorTest.java index ca04883..a606f5d 100644 --- a/src/test/java/org/javacs/SymbolUnderCursorTest.java +++ b/src/test/java/org/javacs/SymbolUnderCursorTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.util.StringJoiner; -import java.util.concurrent.ExecutionException; import org.javacs.lsp.*; import org.junit.Ignore; import org.junit.Test; @@ -108,18 +107,10 @@ public class SymbolUnderCursorTest { private String symbolAt(String file, int line, int character) { var pos = new TextDocumentPositionParams( - new TextDocumentIdentifier(FindResource.uri(file).toString()), - new Position(line - 1, character - 1)); + new TextDocumentIdentifier(FindResource.uri(file)), new Position(line - 1, character - 1)); var result = new StringJoiner("\n"); - try { - server.getTextDocumentService() - .hover(pos) - .get() - .getContents() - .getLeft() - .forEach(hover -> result.add(hover.isLeft() ? hover.getLeft() : hover.getRight().getValue())); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); + for (var h : server.hover(pos).get().contents) { + result.add(h.value); } return result.toString(); } diff --git a/src/test/java/org/javacs/lsp/LanguageServerTest.java b/src/test/java/org/javacs/lsp/LanguageServerTest.java index 75a1faf..4330403 100644 --- a/src/test/java/org/javacs/lsp/LanguageServerTest.java +++ b/src/test/java/org/javacs/lsp/LanguageServerTest.java @@ -65,10 +65,24 @@ public class LanguageServerTest { throws IOException, InterruptedException, ExecutionException, TimeoutException { // Send initialize message and wait for ack sendToServer(initializeMessage); - receivedInitialize.get(1, TimeUnit.SECONDS); + receivedInitialize.get(10, TimeUnit.SECONDS); // Send exit message and wait for exit sendToServer(exitMessage); - main.join(1000); + main.join(10_000); + assertThat("Main thread has quit", main.isAlive(), equalTo(false)); + } + + @Test + public void endOfStreamKillsServer() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // Send initialize message and wait for ack + sendToServer(initializeMessage); + receivedInitialize.get(10, TimeUnit.SECONDS); + // Close stream + writeClientToServer.close(); + clientToServer.close(); + // Wait for exit + main.join(10_000); assertThat("Main thread has quit", main.isAlive(), equalTo(false)); } } diff --git a/src/test/java/org/javacs/lsp/LspTest.java b/src/test/java/org/javacs/lsp/LspTest.java index 3f65774..9ef7c4b 100644 --- a/src/test/java/org/javacs/lsp/LspTest.java +++ b/src/test/java/org/javacs/lsp/LspTest.java @@ -8,6 +8,7 @@ import com.google.gson.JsonObject; import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; +import java.util.Optional; import org.junit.Before; import org.junit.Test; @@ -47,6 +48,20 @@ public class LspTest { } @Test + public void writeOptional() { + LSP.respond(writer, 1, Optional.of(1)); + var expected = "Content-Length: 35\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":1}"; + assertThat(bufferToString(), equalTo(expected)); + } + + @Test + public void writeEmpty() { + LSP.respond(writer, 1, Optional.empty()); + var expected = "Content-Length: 38\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":null}"; + assertThat(bufferToString(), equalTo(expected)); + } + + @Test public void readMessage() throws IOException { var message = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}"; var header = String.format("Content-Length: %d\r\n\r\n", message.getBytes().length); |