implements PLN-0023

This commit is contained in:
2026-03-31 16:57:31 +01:00
parent 53552ca012
commit 8dd3b58f39
24 changed files with 297 additions and 9 deletions
+1
View File
@@ -5,6 +5,7 @@ plugins {
dependencies {
implementation(project(":prometeu-infra"))
implementation(project(":prometeu-lsp:prometeu-lsp-api"))
implementation(project(":prometeu-vfs:prometeu-vfs-api"))
implementation(project(":prometeu-packer:prometeu-packer-api"))
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
@@ -1,6 +1,7 @@
package p.studio;
import com.fasterxml.jackson.databind.ObjectMapper;
import p.lsp.PrometeuLspServiceFactory;
import p.studio.events.StudioEventBus;
import p.studio.utilities.ThemeService;
import p.studio.utilities.i18n.I18nService;
@@ -18,6 +19,8 @@ public interface Container {
ObjectMapper getMapper();
PrometeuLspServiceFactory getPrometeuLspServiceFactory();
ProjectDocumentVfsFactory getProjectDocumentVfsFactory();
EmbeddedPacker getPacker();
@@ -63,6 +66,10 @@ public interface Container {
return current().getMapper();
}
static PrometeuLspServiceFactory prometeuLspServiceFactory() {
return current().getPrometeuLspServiceFactory();
}
static ProjectDocumentVfsFactory projectDocumentVfsFactory() {
return current().getProjectDocumentVfsFactory();
}
@@ -1,5 +1,6 @@
package p.studio.projectsessions;
import p.lsp.PrometeuLspService;
import p.studio.projects.ProjectReference;
import p.studio.vfs.ProjectDocumentVfs;
@@ -7,13 +8,16 @@ import java.util.Objects;
public final class StudioProjectSession implements AutoCloseable {
private final ProjectReference projectReference;
private final PrometeuLspService prometeuLspService;
private final ProjectDocumentVfs projectDocumentVfs;
private boolean closed;
public StudioProjectSession(
final ProjectReference projectReference,
final PrometeuLspService prometeuLspService,
final ProjectDocumentVfs projectDocumentVfs) {
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
this.prometeuLspService = Objects.requireNonNull(prometeuLspService, "prometeuLspService");
this.projectDocumentVfs = Objects.requireNonNull(projectDocumentVfs, "projectDocumentVfs");
}
@@ -25,12 +29,17 @@ public final class StudioProjectSession implements AutoCloseable {
return projectDocumentVfs;
}
public PrometeuLspService prometeuLspService() {
return prometeuLspService;
}
@Override
public void close() {
if (closed) {
return;
}
closed = true;
prometeuLspService.close();
projectDocumentVfs.close();
}
}
@@ -1,21 +1,37 @@
package p.studio.projectsessions;
import p.lsp.PrometeuLspProjectContext;
import p.lsp.PrometeuLspServiceFactory;
import p.studio.projects.ProjectReference;
import p.studio.vfs.ProjectDocumentVfs;
import p.studio.vfs.ProjectDocumentVfsFactory;
import java.util.Objects;
public final class StudioProjectSessionFactory {
private final PrometeuLspServiceFactory prometeuLspServiceFactory;
private final ProjectDocumentVfsFactory projectDocumentVfsFactory;
public StudioProjectSessionFactory(final ProjectDocumentVfsFactory projectDocumentVfsFactory) {
public StudioProjectSessionFactory(
final PrometeuLspServiceFactory prometeuLspServiceFactory,
final ProjectDocumentVfsFactory projectDocumentVfsFactory) {
this.prometeuLspServiceFactory = Objects.requireNonNull(prometeuLspServiceFactory, "prometeuLspServiceFactory");
this.projectDocumentVfsFactory = Objects.requireNonNull(projectDocumentVfsFactory, "projectDocumentVfsFactory");
}
public StudioProjectSession open(final ProjectReference projectReference) {
final ProjectReference target = Objects.requireNonNull(projectReference, "projectReference");
final ProjectDocumentVfs projectDocumentVfs = projectDocumentVfsFactory.open(target.toVfsProjectContext());
return new StudioProjectSession(
target,
projectDocumentVfsFactory.open(target.toVfsProjectContext()));
prometeuLspServiceFactory.open(lspProjectContext(target), projectDocumentVfs),
projectDocumentVfs);
}
private PrometeuLspProjectContext lspProjectContext(final ProjectReference projectReference) {
return new PrometeuLspProjectContext(
projectReference.name(),
projectReference.languageId(),
projectReference.rootPath());
}
}
@@ -37,7 +37,9 @@ public final class StudioWindowCoordinator {
this.projectCatalogService = new ProjectCatalogService(resolveDefaultProjectsRoot());
this.knownProjectsService = new KnownProjectsService(resolveKnownProjectsStorage(), projectCatalogService);
this.windowStateService = new WindowStateService(resolveWindowStateStorage());
this.projectSessionFactory = new StudioProjectSessionFactory(Container.projectDocumentVfsFactory());
this.projectSessionFactory = new StudioProjectSessionFactory(
Container.prometeuLspServiceFactory(),
Container.projectDocumentVfsFactory());
this.launcherView = new ProjectLauncherView(
knownProjectsService,
projectCatalogService,
@@ -1,6 +1,10 @@
package p.studio.projectsessions;
import org.junit.jupiter.api.Test;
import p.lsp.PrometeuLspProjectContext;
import p.lsp.PrometeuLspService;
import p.lsp.PrometeuLspServiceFactory;
import p.lsp.dtos.PrometeuLspSessionStateDTO;
import p.studio.projects.ProjectReference;
import p.studio.vfs.ProjectDocumentVfs;
import p.studio.vfs.ProjectDocumentVfsFactory;
@@ -17,8 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertSame;
final class StudioProjectSessionFactoryTest {
@Test
void openCreatesProjectSessionBackedByProjectScopedVfs() {
final RecordingLspFactory lspFactory = new RecordingLspFactory();
final RecordingVfsFactory vfsFactory = new RecordingVfsFactory();
final StudioProjectSessionFactory sessionFactory = new StudioProjectSessionFactory(vfsFactory);
final StudioProjectSessionFactory sessionFactory = new StudioProjectSessionFactory(lspFactory, vfsFactory);
final ProjectReference projectReference = new ProjectReference(
"Example",
"1.0.0",
@@ -30,9 +35,13 @@ final class StudioProjectSessionFactoryTest {
assertSame(projectReference, session.projectReference());
assertSame(vfsFactory.vfs, session.projectDocumentVfs());
assertSame(lspFactory.service, session.prometeuLspService());
assertEquals("Example", vfsFactory.capturedContext.projectName());
assertEquals("pbs", vfsFactory.capturedContext.languageId());
assertEquals(projectReference.rootPath().toAbsolutePath().normalize(), vfsFactory.capturedContext.rootPath());
assertEquals("Example", lspFactory.capturedContext.projectName());
assertEquals("pbs", lspFactory.capturedContext.languageId());
assertSame(vfsFactory.vfs, lspFactory.capturedVfs);
}
private static final class RecordingVfsFactory implements ProjectDocumentVfsFactory {
@@ -46,6 +55,21 @@ final class StudioProjectSessionFactoryTest {
}
}
private static final class RecordingLspFactory implements PrometeuLspServiceFactory {
private PrometeuLspProjectContext capturedContext;
private ProjectDocumentVfs capturedVfs;
private final PrometeuLspService service = new NoOpPrometeuLspService();
@Override
public PrometeuLspService open(
final PrometeuLspProjectContext projectContext,
final ProjectDocumentVfs projectDocumentVfs) {
this.capturedContext = projectContext;
this.capturedVfs = projectDocumentVfs;
return service;
}
}
private static final class NoOpProjectDocumentVfs implements ProjectDocumentVfs {
@Override
public VfsProjectContext projectContext() {
@@ -72,4 +96,21 @@ final class StudioProjectSessionFactoryTest {
throw new UnsupportedOperationException();
}
}
private static final class NoOpPrometeuLspService implements PrometeuLspService {
@Override
public PrometeuLspProjectContext projectContext() {
throw new UnsupportedOperationException();
}
@Override
public ProjectDocumentVfs projectDocumentVfs() {
throw new UnsupportedOperationException();
}
@Override
public PrometeuLspSessionStateDTO snapshot() {
throw new UnsupportedOperationException();
}
}
}
@@ -1,6 +1,9 @@
package p.studio.projectsessions;
import org.junit.jupiter.api.Test;
import p.lsp.PrometeuLspProjectContext;
import p.lsp.PrometeuLspService;
import p.lsp.dtos.PrometeuLspSessionStateDTO;
import p.studio.projects.ProjectReference;
import p.studio.vfs.ProjectDocumentVfs;
import p.studio.vfs.VfsDocumentOpenResult;
@@ -14,13 +17,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
final class StudioProjectSessionTest {
@Test
void closeDelegatesToUnderlyingVfsOnlyOnce() {
void closeDelegatesToUnderlyingServicesOnlyOnce() {
final CountingProjectDocumentVfs vfs = new CountingProjectDocumentVfs();
final StudioProjectSession session = new StudioProjectSession(projectReference(), vfs);
final CountingPrometeuLspService lsp = new CountingPrometeuLspService(vfs);
final StudioProjectSession session = new StudioProjectSession(projectReference(), lsp, vfs);
session.close();
session.close();
assertEquals(1, lsp.closeCalls);
assertEquals(1, vfs.closeCalls);
}
@@ -61,4 +66,33 @@ final class StudioProjectSessionTest {
closeCalls++;
}
}
private static final class CountingPrometeuLspService implements PrometeuLspService {
private final ProjectDocumentVfs projectDocumentVfs;
private int closeCalls;
private CountingPrometeuLspService(final ProjectDocumentVfs projectDocumentVfs) {
this.projectDocumentVfs = projectDocumentVfs;
}
@Override
public PrometeuLspProjectContext projectContext() {
throw new UnsupportedOperationException();
}
@Override
public ProjectDocumentVfs projectDocumentVfs() {
return projectDocumentVfs;
}
@Override
public PrometeuLspSessionStateDTO snapshot() {
throw new UnsupportedOperationException();
}
@Override
public void close() {
closeCalls++;
}
}
}