implements PLN-0066
This commit is contained in:
@@ -5,6 +5,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":prometeu-infra"))
|
||||
implementation(project(":prometeu-lsp:prometeu-lsp-api"))
|
||||
implementation(project(":prometeu-packer:prometeu-packer-api"))
|
||||
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
|
||||
implementation(project(":prometeu-compiler:prometeu-build-pipeline"))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package p.studio;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.lsp.events.StudioEventBus;
|
||||
import p.studio.utilities.ThemeService;
|
||||
import p.studio.utilities.i18n.I18nService;
|
||||
@@ -21,6 +22,8 @@ public interface Container {
|
||||
|
||||
StudioBackgroundTasks getBackgroundTasks();
|
||||
|
||||
LspServerLifecycle getLspServerLifecycle();
|
||||
|
||||
void shutdownContainer();
|
||||
|
||||
static void install(Container container) {
|
||||
@@ -68,6 +71,10 @@ public interface Container {
|
||||
return current().getBackgroundTasks();
|
||||
}
|
||||
|
||||
static LspServerLifecycle lspServerLifecycle() {
|
||||
return current().getLspServerLifecycle();
|
||||
}
|
||||
|
||||
static void shutdown() {
|
||||
final Container container = Holder.CURRENT.get();
|
||||
if (container != null) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package p.studio.projectsessions;
|
||||
|
||||
import p.studio.execution.StudioExecutionSessionService;
|
||||
import p.studio.lsp.api.LspProjectContext;
|
||||
import p.studio.lsp.api.LspServerHandle;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.projectstate.ProjectLocalStudioSetup;
|
||||
import p.studio.projectstate.ProjectLocalStudioState;
|
||||
import p.studio.projectstate.ProjectLocalStudioStateService;
|
||||
@@ -13,6 +16,8 @@ public final class StudioProjectSession implements AutoCloseable {
|
||||
private final ProjectLocalStudioStateService projectLocalStudioStateService;
|
||||
private final ProjectLocalStudioSetup projectLocalStudioSetup;
|
||||
private final StudioExecutionSessionService executionSessionService;
|
||||
private final LspServerLifecycle lspServerLifecycle;
|
||||
private final LspServerHandle lspServerHandle;
|
||||
private ProjectLocalStudioState projectLocalStudioState;
|
||||
private boolean closed;
|
||||
|
||||
@@ -23,6 +28,8 @@ public final class StudioProjectSession implements AutoCloseable {
|
||||
new ProjectLocalStudioStateService(),
|
||||
ProjectLocalStudioSetup.defaults(),
|
||||
new StudioExecutionSessionService(),
|
||||
null,
|
||||
null,
|
||||
ProjectLocalStudioState.defaults());
|
||||
}
|
||||
|
||||
@@ -31,11 +38,15 @@ public final class StudioProjectSession implements AutoCloseable {
|
||||
final ProjectLocalStudioStateService projectLocalStudioStateService,
|
||||
final ProjectLocalStudioSetup projectLocalStudioSetup,
|
||||
final StudioExecutionSessionService executionSessionService,
|
||||
final LspServerLifecycle lspServerLifecycle,
|
||||
final LspServerHandle lspServerHandle,
|
||||
final ProjectLocalStudioState projectLocalStudioState) {
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.projectLocalStudioStateService = Objects.requireNonNull(projectLocalStudioStateService, "projectLocalStudioStateService");
|
||||
this.projectLocalStudioSetup = Objects.requireNonNull(projectLocalStudioSetup, "projectLocalStudioSetup");
|
||||
this.executionSessionService = Objects.requireNonNull(executionSessionService, "executionSessionService");
|
||||
this.lspServerLifecycle = lspServerLifecycle;
|
||||
this.lspServerHandle = lspServerHandle;
|
||||
this.projectLocalStudioState = Objects.requireNonNull(projectLocalStudioState, "projectLocalStudioState");
|
||||
}
|
||||
|
||||
@@ -55,6 +66,10 @@ public final class StudioProjectSession implements AutoCloseable {
|
||||
return executionSessionService;
|
||||
}
|
||||
|
||||
public LspServerHandle lspServerHandle() {
|
||||
return lspServerHandle;
|
||||
}
|
||||
|
||||
public void replaceProjectLocalStudioState(final ProjectLocalStudioState nextProjectLocalStudioState) {
|
||||
this.projectLocalStudioState = Objects.requireNonNull(nextProjectLocalStudioState, "nextProjectLocalStudioState");
|
||||
}
|
||||
@@ -76,8 +91,12 @@ public final class StudioProjectSession implements AutoCloseable {
|
||||
failure = runtimeException;
|
||||
}
|
||||
try {
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
shutdownLspServer();
|
||||
} catch (RuntimeException runtimeException) {
|
||||
if (failure == null) {
|
||||
failure = runtimeException;
|
||||
} else {
|
||||
failure.addSuppressed(runtimeException);
|
||||
}
|
||||
} finally {
|
||||
if (failure != null) {
|
||||
@@ -85,4 +104,12 @@ public final class StudioProjectSession implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void shutdownLspServer() {
|
||||
if (lspServerLifecycle == null || lspServerHandle == null) {
|
||||
return;
|
||||
}
|
||||
final LspProjectContext projectContext = lspServerHandle.project();
|
||||
lspServerLifecycle.shutdownServer(projectContext);
|
||||
}
|
||||
}
|
||||
|
||||
+26
-5
@@ -1,5 +1,9 @@
|
||||
package p.studio.projectsessions;
|
||||
|
||||
import p.studio.lsp.api.LspProjectContext;
|
||||
import p.studio.lsp.api.LspServerBootRequest;
|
||||
import p.studio.lsp.api.LspServerHandle;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.execution.StudioExecutionSessionService;
|
||||
import p.studio.projectstate.ProjectLocalStudioSetupService;
|
||||
import p.studio.projectstate.ProjectLocalStudioStateService;
|
||||
@@ -10,27 +14,44 @@ import java.util.Objects;
|
||||
public final class StudioProjectSessionFactory {
|
||||
private final ProjectLocalStudioStateService projectLocalStudioStateService;
|
||||
private final ProjectLocalStudioSetupService projectLocalStudioSetupService;
|
||||
private final LspServerLifecycle lspServerLifecycle;
|
||||
|
||||
public StudioProjectSessionFactory() {
|
||||
public StudioProjectSessionFactory(final LspServerLifecycle lspServerLifecycle) {
|
||||
this(
|
||||
new ProjectLocalStudioStateService(),
|
||||
new ProjectLocalStudioSetupService());
|
||||
new ProjectLocalStudioSetupService(),
|
||||
Objects.requireNonNull(lspServerLifecycle, "lspServerLifecycle"));
|
||||
}
|
||||
|
||||
StudioProjectSessionFactory(
|
||||
final ProjectLocalStudioStateService projectLocalStudioStateService,
|
||||
final ProjectLocalStudioSetupService projectLocalStudioSetupService) {
|
||||
final ProjectLocalStudioSetupService projectLocalStudioSetupService,
|
||||
final LspServerLifecycle lspServerLifecycle) {
|
||||
this.projectLocalStudioStateService = Objects.requireNonNull(projectLocalStudioStateService, "projectLocalStudioStateService");
|
||||
this.projectLocalStudioSetupService = Objects.requireNonNull(projectLocalStudioSetupService, "projectLocalStudioSetupService");
|
||||
this.lspServerLifecycle = Objects.requireNonNull(lspServerLifecycle, "lspServerLifecycle");
|
||||
}
|
||||
|
||||
public StudioProjectSession open(final ProjectReference projectReference) {
|
||||
final ProjectReference target = Objects.requireNonNull(projectReference, "projectReference");
|
||||
final var setup = projectLocalStudioSetupService.load(target);
|
||||
final var state = projectLocalStudioStateService.load(target);
|
||||
final LspProjectContext lspProjectContext = toLspProjectContext(target);
|
||||
final LspServerHandle lspServerHandle = lspServerLifecycle.bootServer(LspServerBootRequest.defaults(lspProjectContext));
|
||||
return new StudioProjectSession(
|
||||
target,
|
||||
projectLocalStudioStateService,
|
||||
projectLocalStudioSetupService.load(target),
|
||||
setup,
|
||||
new StudioExecutionSessionService(),
|
||||
projectLocalStudioStateService.load(target));
|
||||
lspServerLifecycle,
|
||||
lspServerHandle,
|
||||
state);
|
||||
}
|
||||
|
||||
private static LspProjectContext toLspProjectContext(final ProjectReference projectReference) {
|
||||
return new LspProjectContext(
|
||||
projectReference.rootPath().toAbsolutePath().normalize().toString(),
|
||||
projectReference.languageId(),
|
||||
projectReference.rootPath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class StudioWindowCoordinator {
|
||||
this.projectCatalogService = new ProjectCatalogService(resolveDefaultProjectsRoot());
|
||||
this.knownProjectsService = new KnownProjectsService(resolveKnownProjectsStorage(), projectCatalogService);
|
||||
this.windowStateService = new WindowStateService(resolveWindowStateStorage());
|
||||
this.projectSessionFactory = new StudioProjectSessionFactory();
|
||||
this.projectSessionFactory = new StudioProjectSessionFactory(Container.lspServerLifecycle());
|
||||
this.launcherView = new ProjectLauncherView(
|
||||
knownProjectsService,
|
||||
projectCatalogService,
|
||||
|
||||
+62
-2
@@ -1,6 +1,10 @@
|
||||
package p.studio.projectsessions;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.lsp.api.LspProjectContext;
|
||||
import p.studio.lsp.api.LspServerBootRequest;
|
||||
import p.studio.lsp.api.LspServerHandle;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.projectstate.ProjectLocalStudioSetup;
|
||||
import p.studio.projectstate.ProjectLocalStudioSetupService;
|
||||
import p.studio.projectstate.ProjectLocalStudioState;
|
||||
@@ -10,16 +14,20 @@ import p.studio.projects.ProjectReference;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
final class StudioProjectSessionFactoryTest {
|
||||
@Test
|
||||
void openCreatesProjectSessionWithoutLegacyEditorServices() {
|
||||
void openCreatesProjectSessionAndBootsLspServer() {
|
||||
final RecordingProjectLocalStudioStateService stateService = new RecordingProjectLocalStudioStateService();
|
||||
final RecordingProjectLocalStudioSetupService setupService = new RecordingProjectLocalStudioSetupService();
|
||||
final RecordingLspServerLifecycle lspServerLifecycle = new RecordingLspServerLifecycle();
|
||||
final StudioProjectSessionFactory sessionFactory = new StudioProjectSessionFactory(
|
||||
stateService,
|
||||
setupService);
|
||||
setupService,
|
||||
lspServerLifecycle);
|
||||
final ProjectReference projectReference = new ProjectReference(
|
||||
"Example",
|
||||
"1.0.0",
|
||||
@@ -35,6 +43,29 @@ final class StudioProjectSessionFactoryTest {
|
||||
assertEquals("IDLE", session.executionSession().snapshot().state().name());
|
||||
assertSame(projectReference, stateService.loadedProjectReference);
|
||||
assertSame(projectReference, setupService.loadedProjectReference);
|
||||
assertNotNull(session.lspServerHandle());
|
||||
assertEquals(1, lspServerLifecycle.bootCalls);
|
||||
assertEquals(projectReference.languageId(), lspServerLifecycle.lastRequest.project().languageId());
|
||||
assertEquals(projectReference.rootPath().toAbsolutePath().normalize(), lspServerLifecycle.lastRequest.project().projectRoot());
|
||||
}
|
||||
|
||||
@Test
|
||||
void openSurfacesLspBootFailure() {
|
||||
final RecordingProjectLocalStudioStateService stateService = new RecordingProjectLocalStudioStateService();
|
||||
final RecordingProjectLocalStudioSetupService setupService = new RecordingProjectLocalStudioSetupService();
|
||||
final StudioProjectSessionFactory sessionFactory = new StudioProjectSessionFactory(
|
||||
stateService,
|
||||
setupService,
|
||||
new FailingLspServerLifecycle());
|
||||
|
||||
final IllegalStateException failure = assertThrows(IllegalStateException.class, () -> sessionFactory.open(new ProjectReference(
|
||||
"Example",
|
||||
"1.0.0",
|
||||
"pbs",
|
||||
1,
|
||||
Path.of("/tmp/example"))));
|
||||
|
||||
assertEquals("boom", failure.getMessage());
|
||||
}
|
||||
|
||||
private static final class RecordingProjectLocalStudioStateService extends ProjectLocalStudioStateService {
|
||||
@@ -63,4 +94,33 @@ final class StudioProjectSessionFactoryTest {
|
||||
return loadedSetup;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingLspServerLifecycle implements LspServerLifecycle {
|
||||
private int bootCalls;
|
||||
private LspServerBootRequest lastRequest;
|
||||
|
||||
@Override
|
||||
public LspServerHandle bootServer(final LspServerBootRequest request) {
|
||||
bootCalls++;
|
||||
lastRequest = request;
|
||||
return new LspServerHandle(
|
||||
request.project(),
|
||||
new p.studio.lsp.api.LspServerEndpoint("127.0.0.1", request.configuration().port()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownServer(final LspProjectContext project) {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class FailingLspServerLifecycle implements LspServerLifecycle {
|
||||
@Override
|
||||
public LspServerHandle bootServer(final LspServerBootRequest request) {
|
||||
throw new IllegalStateException("boom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownServer(final LspProjectContext project) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package p.studio.projectsessions;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.execution.StudioExecutionSessionService;
|
||||
import p.studio.lsp.api.LspProjectContext;
|
||||
import p.studio.lsp.api.LspServerHandle;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.projectstate.ProjectLocalStudioSetup;
|
||||
import p.studio.projectstate.ProjectLocalStudioState;
|
||||
import p.studio.projectstate.ProjectLocalStudioStateService;
|
||||
@@ -21,6 +24,8 @@ final class StudioProjectSessionTest {
|
||||
stateService,
|
||||
ProjectLocalStudioSetup.defaults(),
|
||||
new StudioExecutionSessionService(),
|
||||
null,
|
||||
null,
|
||||
ProjectLocalStudioState.defaults());
|
||||
|
||||
session.close();
|
||||
@@ -38,6 +43,8 @@ final class StudioProjectSessionTest {
|
||||
stateService,
|
||||
ProjectLocalStudioSetup.defaults(),
|
||||
new StudioExecutionSessionService(),
|
||||
null,
|
||||
null,
|
||||
ProjectLocalStudioState.defaults());
|
||||
final ProjectLocalStudioState nextState = ProjectLocalStudioState.defaults()
|
||||
.withOpenShellState(new ProjectLocalStudioState.OpenShellState("ASSETS"));
|
||||
@@ -48,6 +55,29 @@ final class StudioProjectSessionTest {
|
||||
assertSame(nextState, stateService.savedState);
|
||||
}
|
||||
|
||||
@Test
|
||||
void closeShutsDownLspServerOnlyOnce() {
|
||||
final RecordingProjectLocalStudioStateService stateService = new RecordingProjectLocalStudioStateService();
|
||||
final RecordingLspServerLifecycle lspServerLifecycle = new RecordingLspServerLifecycle();
|
||||
final LspServerHandle lspServerHandle = new LspServerHandle(
|
||||
new LspProjectContext("demo", "pbs", Path.of("/tmp/example")),
|
||||
new p.studio.lsp.api.LspServerEndpoint("127.0.0.1", 7777));
|
||||
final StudioProjectSession session = new StudioProjectSession(
|
||||
projectReference(),
|
||||
stateService,
|
||||
ProjectLocalStudioSetup.defaults(),
|
||||
new StudioExecutionSessionService(),
|
||||
lspServerLifecycle,
|
||||
lspServerHandle,
|
||||
ProjectLocalStudioState.defaults());
|
||||
|
||||
session.close();
|
||||
session.close();
|
||||
|
||||
assertEquals(1, lspServerLifecycle.shutdownCalls);
|
||||
assertEquals(lspServerHandle.project(), lspServerLifecycle.lastProject);
|
||||
}
|
||||
|
||||
private ProjectReference projectReference() {
|
||||
return new ProjectReference("Example", "1.0.0", "pbs", 1, Path.of("/tmp/example"));
|
||||
}
|
||||
@@ -64,4 +94,20 @@ final class StudioProjectSessionTest {
|
||||
savedState = state;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingLspServerLifecycle implements LspServerLifecycle {
|
||||
private int shutdownCalls;
|
||||
private LspProjectContext lastProject;
|
||||
|
||||
@Override
|
||||
public LspServerHandle bootServer(final p.studio.lsp.api.LspServerBootRequest request) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownServer(final LspProjectContext project) {
|
||||
shutdownCalls++;
|
||||
lastProject = project;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user