clean up and simplify
This commit is contained in:
+3
-4
@@ -1,11 +1,10 @@
|
||||
package p.studio.lsp.api;
|
||||
|
||||
import p.studio.lsp.messages.LspProjectContext;
|
||||
import p.studio.lsp.messages.LspServerBootRequest;
|
||||
import p.studio.lsp.messages.LspServerHandle;
|
||||
import p.studio.lsp.messages.LspServerConfiguration;
|
||||
|
||||
public interface LspServerLifecycle {
|
||||
LspServerHandle bootServer(LspServerBootRequest request);
|
||||
void bootServer(LspServerConfiguration serverConfiguration, LspProjectContext context);
|
||||
|
||||
void shutdownServer(LspProjectContext project);
|
||||
void shutdownServer(LspProjectContext context);
|
||||
}
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record LspServerBootRequest(
|
||||
LspProjectContext project,
|
||||
LspServerConfiguration configuration) {
|
||||
|
||||
public LspServerBootRequest {
|
||||
project = Objects.requireNonNull(project, "project");
|
||||
configuration = Objects.requireNonNull(configuration, "configuration");
|
||||
}
|
||||
|
||||
public static LspServerBootRequest defaults(final LspProjectContext project) {
|
||||
return new LspServerBootRequest(project, LspServerConfiguration.defaults());
|
||||
}
|
||||
}
|
||||
+9
-19
@@ -1,29 +1,19 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
public record LspServerConfiguration(
|
||||
String host,
|
||||
int port) {
|
||||
@Builder
|
||||
@Getter
|
||||
public class LspServerConfiguration {
|
||||
public static final String DEFAULT_HOST = "127.0.0.1";
|
||||
public static final int DEFAULT_PORT = 7777;
|
||||
|
||||
public LspServerConfiguration {
|
||||
host = requireHost(host);
|
||||
if (port < 0 || port > 65535) {
|
||||
throw new IllegalArgumentException("port must be between 0 and 65535");
|
||||
}
|
||||
}
|
||||
@Builder.Default
|
||||
private final LspServerEndpoint endpoint = new LspServerEndpoint(DEFAULT_HOST, DEFAULT_PORT);
|
||||
|
||||
|
||||
public static LspServerConfiguration defaults() {
|
||||
return new LspServerConfiguration(DEFAULT_HOST, DEFAULT_PORT);
|
||||
}
|
||||
|
||||
private static String requireHost(final String value) {
|
||||
final String candidate = Objects.requireNonNull(value, "host").trim();
|
||||
if (candidate.isEmpty()) {
|
||||
throw new IllegalArgumentException("host must not be blank");
|
||||
}
|
||||
return candidate;
|
||||
return LspServerConfiguration.builder().build();
|
||||
}
|
||||
}
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record LspServerHandle(
|
||||
LspProjectContext project,
|
||||
LspServerEndpoint endpoint) {
|
||||
|
||||
public LspServerHandle {
|
||||
project = Objects.requireNonNull(project, "project");
|
||||
endpoint = Objects.requireNonNull(endpoint, "endpoint");
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package p.studio.lsp.api;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class LspApiBoundaryTest {
|
||||
|
||||
@Test
|
||||
void apiSourceMustRemainFreeOfLsp4jAndProtocolPackages() throws IOException {
|
||||
final Path sourceRoot = Path.of("src/main/java");
|
||||
final List<Path> javaFiles;
|
||||
try (var stream = Files.walk(sourceRoot)) {
|
||||
javaFiles = stream
|
||||
.filter(path -> path.toString().endsWith(".java"))
|
||||
.toList();
|
||||
}
|
||||
|
||||
for (final Path javaFile : javaFiles) {
|
||||
final String source = Files.readString(javaFile);
|
||||
assertTrue(!source.contains("org.eclipse.lsp4j"),
|
||||
() -> "LSP4J leaked into lsp-api: " + javaFile);
|
||||
assertTrue(!source.contains(".protocol."),
|
||||
() -> "Protocol package leaked into lsp-api: " + javaFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package p.studio.lsp.api;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.lsp.messages.LspProjectContext;
|
||||
import p.studio.lsp.messages.LspServerBootRequest;
|
||||
import p.studio.lsp.messages.LspServerConfiguration;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class LspServerBootRequestTest {
|
||||
|
||||
@Test
|
||||
void defaultsUseDeterministicLoopbackConfiguration() {
|
||||
final LspProjectContext project = new LspProjectContext("demo", "pbs", Path.of("."));
|
||||
|
||||
final LspServerBootRequest request = LspServerBootRequest.defaults(project);
|
||||
|
||||
assertEquals(project, request.project());
|
||||
assertEquals(LspServerConfiguration.DEFAULT_HOST, request.configuration().host());
|
||||
assertEquals(LspServerConfiguration.DEFAULT_PORT, request.configuration().port());
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationRejectsInvalidValues() {
|
||||
assertThrows(NullPointerException.class, () -> new LspServerConfiguration(null, 7777));
|
||||
assertThrows(IllegalArgumentException.class, () -> new LspServerConfiguration(" ", 7777));
|
||||
assertThrows(IllegalArgumentException.class, () -> new LspServerConfiguration("127.0.0.1", -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void projectContextNormalizesAndRejectsBlankFields() {
|
||||
final LspProjectContext context = new LspProjectContext(" demo ", " pbs ", Path.of("."));
|
||||
|
||||
assertEquals("demo", context.projectKey());
|
||||
assertEquals("pbs", context.languageId());
|
||||
assertEquals(Path.of(".").toAbsolutePath().normalize(), context.projectRoot());
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> new LspProjectContext(" ", "pbs", Path.of(".")));
|
||||
assertThrows(IllegalArgumentException.class, () -> new LspProjectContext("demo", " ", Path.of(".")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user