connect MCP language queries to project LSP
This commit is contained in:
@@ -10,6 +10,7 @@ import java.util.Objects;
|
||||
|
||||
public final class LspLifecycleAdapter implements LspLifecyclePort {
|
||||
private final LspServerLifecycle lifecycle;
|
||||
private final java.util.Map<java.nio.file.Path, LspProjectContext> bindings = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
|
||||
public LspLifecycleAdapter(LspServerLifecycle lifecycle) {
|
||||
this.lifecycle = Objects.requireNonNull(lifecycle, "lifecycle");
|
||||
@@ -17,19 +18,26 @@ public final class LspLifecycleAdapter implements LspLifecyclePort {
|
||||
|
||||
@Override
|
||||
public void boot(ProjectReference project) {
|
||||
lifecycle.bootServer(LspServerConfiguration.defaults(), context(project));
|
||||
var binding = context(project);
|
||||
lifecycle.bootServer(LspServerConfiguration.builder().endpoint(
|
||||
new p.studio.lsp.messages.LspServerEndpoint("127.0.0.1", 0)).build(), binding);
|
||||
bindings.put(project.rootPath().toAbsolutePath().normalize(), binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(ProjectReference project) {
|
||||
lifecycle.shutdownServer(context(project));
|
||||
var binding = bindings.remove(project.rootPath().toAbsolutePath().normalize());
|
||||
if (binding != null) lifecycle.shutdownServer(binding);
|
||||
}
|
||||
|
||||
private static LspProjectContext context(ProjectReference project) {
|
||||
static LspProjectContext context(ProjectReference project) {
|
||||
final var safeProject = Objects.requireNonNull(project, "project");
|
||||
final java.nio.file.Path root;
|
||||
try { root = safeProject.rootPath().toRealPath(); }
|
||||
catch (java.io.IOException failure) { throw new IllegalStateException("Project root unavailable", failure); }
|
||||
return new LspProjectContext(
|
||||
safeProject.rootPath().toAbsolutePath().normalize().toString(),
|
||||
root.toString(),
|
||||
safeProject.languageId(),
|
||||
safeProject.rootPath());
|
||||
root);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user