connection checker and failure
This commit is contained in:
+58
-1
@@ -2,6 +2,8 @@ package p.studio.lsp.v1.protocol;
|
||||
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.WorkspaceFolder;
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
|
||||
import org.eclipse.lsp4j.PublishDiagnosticsParams;
|
||||
import org.eclipse.lsp4j.services.TextDocumentService;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
@@ -12,9 +14,12 @@ import p.studio.lsp.v1.protocol.mapping.ProtocolMessageMapper;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletionException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PrometeuLanguageServerTest {
|
||||
|
||||
@@ -32,13 +37,60 @@ class PrometeuLanguageServerTest {
|
||||
new NoopTextDocumentService(),
|
||||
new PrometeuWorkspaceService());
|
||||
|
||||
final InitializeResult result = server.initialize(new InitializeParams()).join();
|
||||
final InitializeParams params = new InitializeParams();
|
||||
params.setRootUri(Path.of(".").toAbsolutePath().normalize().toUri().toString());
|
||||
|
||||
final InitializeResult result = server.initialize(params).join();
|
||||
|
||||
assertSame(expected, result);
|
||||
assertEquals(1, bridge.describeServerCalls);
|
||||
assertSame(bridge.serverDescription, mapper.lastServerDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
void initializeRejectsClientBoundToDifferentProjectRoot() {
|
||||
final RecordingBridge bridge = new RecordingBridge();
|
||||
final RecordingMapper mapper = new RecordingMapper();
|
||||
final PrometeuLanguageServer server = new PrometeuLanguageServer(
|
||||
new LspProjectContext("demo", "pbs", Path.of("/tmp/studio-project")),
|
||||
bridge,
|
||||
mapper,
|
||||
new NoopTextDocumentService(),
|
||||
new PrometeuWorkspaceService());
|
||||
|
||||
final InitializeParams params = new InitializeParams();
|
||||
params.setRootUri(Path.of("/tmp/another-project").toUri().toString());
|
||||
|
||||
final CompletionException failure = org.junit.jupiter.api.Assertions.assertThrows(
|
||||
CompletionException.class,
|
||||
() -> server.initialize(params).join());
|
||||
|
||||
final ResponseErrorException responseError = assertInstanceOf(ResponseErrorException.class, failure.getCause());
|
||||
assertTrue(responseError.getMessage().contains("/tmp/studio-project"));
|
||||
assertEquals(0, bridge.describeServerCalls);
|
||||
}
|
||||
|
||||
@Test
|
||||
void initializeAcceptsMatchingWorkspaceFolder() {
|
||||
final RecordingBridge bridge = new RecordingBridge();
|
||||
final RecordingMapper mapper = new RecordingMapper();
|
||||
mapper.initializeResult = new InitializeResult();
|
||||
final Path projectRoot = Path.of("/tmp/studio-project").toAbsolutePath().normalize();
|
||||
final PrometeuLanguageServer server = new PrometeuLanguageServer(
|
||||
new LspProjectContext("demo", "pbs", projectRoot),
|
||||
bridge,
|
||||
mapper,
|
||||
new NoopTextDocumentService(),
|
||||
new PrometeuWorkspaceService());
|
||||
|
||||
final InitializeParams params = new InitializeParams();
|
||||
params.setWorkspaceFolders(List.of(new WorkspaceFolder(projectRoot.toUri().toString(), "studio-project")));
|
||||
|
||||
server.initialize(params).join();
|
||||
|
||||
assertEquals(1, bridge.describeServerCalls);
|
||||
}
|
||||
|
||||
private static final class RecordingBridge implements LanguageServiceBridge {
|
||||
private int describeServerCalls;
|
||||
private final BaselineServerDescription serverDescription = new BaselineServerDescription("demo", "1", true);
|
||||
@@ -94,6 +146,11 @@ class PrometeuLanguageServerTest {
|
||||
public org.eclipse.lsp4j.MessageParams mapInfoMessage(final String message) {
|
||||
return new org.eclipse.lsp4j.MessageParams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.MessageParams mapErrorMessage(final String message) {
|
||||
return new org.eclipse.lsp4j.MessageParams();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NoopTextDocumentService implements TextDocumentService {
|
||||
|
||||
+5
@@ -104,6 +104,11 @@ class PrometeuTextDocumentServiceTest {
|
||||
public MessageParams mapInfoMessage(final String message) {
|
||||
return infoMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageParams mapErrorMessage(final String message) {
|
||||
return infoMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingClient implements LanguageClient {
|
||||
|
||||
Reference in New Issue
Block a user