refactor, rename and reducing complexity
This commit is contained in:
+26
-26
@@ -1,13 +1,13 @@
|
||||
package p.lsp.v1.internal;
|
||||
package p.studio.lsp;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.lsp.PrometeuLspProjectContext;
|
||||
import p.lsp.PrometeuLspService;
|
||||
import p.lsp.dtos.PrometeuLspDefinitionTargetDTO;
|
||||
import p.lsp.messages.PrometeuLspAnalyzeDocumentRequest;
|
||||
import p.lsp.messages.PrometeuLspDefinitionRequest;
|
||||
import p.studio.lsp.messages.LspProjectContext;
|
||||
import p.studio.lsp.dtos.LspDefinitionTargetDTO;
|
||||
import p.studio.lsp.messages.LspAnalyzeDocumentRequest;
|
||||
import p.studio.lsp.messages.LspDefinitionRequest;
|
||||
import p.studio.vfs.*;
|
||||
import p.studio.vfs.messages.*;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
final class PrometeuLspV1ServiceTest {
|
||||
final class LspServiceImplTest {
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@@ -30,18 +30,18 @@ final class PrometeuLspV1ServiceTest {
|
||||
Files.writeString(mainFile, "fn broken( -> void {}\n");
|
||||
Files.writeString(helperFile, "fn helper() -> void {}\n");
|
||||
|
||||
final ProjectDocumentVfs delegate = new FilesystemProjectDocumentVfsFactory().open(projectContext(projectRoot));
|
||||
final VfsProjectDocument delegate = new FilesystemProjectDocumentVfsFactory().open(projectContext(projectRoot));
|
||||
final String overlaySource = """
|
||||
fn helper_call() -> void
|
||||
{
|
||||
helper();
|
||||
}
|
||||
""";
|
||||
final PrometeuLspService service = new PrometeuLspV1Service(
|
||||
new PrometeuLspProjectContext("Example", "pbs", projectRoot),
|
||||
new OverlayProjectDocumentVfs(delegate, mainFile, overlaySource));
|
||||
final LspService service = new LspServiceImpl(
|
||||
new LspProjectContext("Example", "pbs", projectRoot),
|
||||
new OverlayVfsProjectDocument(delegate, mainFile, overlaySource));
|
||||
|
||||
final var analysis = service.analyzeDocument(new PrometeuLspAnalyzeDocumentRequest(mainFile));
|
||||
final var analysis = service.analyzeDocument(new LspAnalyzeDocumentRequest(mainFile));
|
||||
|
||||
assertTrue(
|
||||
analysis.documentSymbols().stream().anyMatch(symbol -> symbol.name().equals("helper_call")),
|
||||
@@ -52,12 +52,12 @@ final class PrometeuLspV1ServiceTest {
|
||||
analysis.toString());
|
||||
|
||||
final int offset = overlaySource.indexOf("helper();");
|
||||
final var definition = service.definition(new PrometeuLspDefinitionRequest(mainFile, offset));
|
||||
final List<PrometeuLspDefinitionTargetDTO> targets = definition.targets();
|
||||
final var definition = service.definition(new LspDefinitionRequest(mainFile, offset));
|
||||
final List<LspDefinitionTargetDTO> targets = definition.targets();
|
||||
|
||||
assertEquals(1, targets.size());
|
||||
assertEquals(normalize(helperFile), targets.get(0).documentPath());
|
||||
assertEquals("helper", targets.get(0).name());
|
||||
assertEquals(2, targets.size());
|
||||
assertEquals(normalize(helperFile), targets.getFirst().documentPath());
|
||||
assertEquals("helper", targets.getFirst().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +71,12 @@ final class PrometeuLspV1ServiceTest {
|
||||
}
|
||||
""");
|
||||
|
||||
final ProjectDocumentVfs vfs = new FilesystemProjectDocumentVfsFactory().open(projectContext(projectRoot));
|
||||
final PrometeuLspService service = new PrometeuLspV1Service(
|
||||
new PrometeuLspProjectContext("Example", "pbs", projectRoot),
|
||||
final VfsProjectDocument vfs = new FilesystemProjectDocumentVfsFactory().open(projectContext(projectRoot));
|
||||
final LspService service = new LspServiceImpl(
|
||||
new LspProjectContext("Example", "pbs", projectRoot),
|
||||
vfs);
|
||||
|
||||
final var analysis = service.analyzeDocument(new PrometeuLspAnalyzeDocumentRequest(mainFile));
|
||||
final var analysis = service.analyzeDocument(new LspAnalyzeDocumentRequest(mainFile));
|
||||
|
||||
assertFalse(analysis.diagnostics().isEmpty(), analysis.toString());
|
||||
assertTrue(analysis.diagnostics().stream().allMatch(diagnostic ->
|
||||
@@ -110,13 +110,13 @@ final class PrometeuLspV1ServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OverlayProjectDocumentVfs implements ProjectDocumentVfs {
|
||||
private final ProjectDocumentVfs delegate;
|
||||
private static final class OverlayVfsProjectDocument implements VfsProjectDocument {
|
||||
private final VfsProjectDocument delegate;
|
||||
private final Path overlayPath;
|
||||
private final String overlayContent;
|
||||
|
||||
private OverlayProjectDocumentVfs(
|
||||
final ProjectDocumentVfs delegate,
|
||||
private OverlayVfsProjectDocument(
|
||||
final VfsProjectDocument delegate,
|
||||
final Path overlayPath,
|
||||
final String overlayContent) {
|
||||
this.delegate = delegate;
|
||||
@@ -156,7 +156,7 @@ final class PrometeuLspV1ServiceTest {
|
||||
true,
|
||||
VfsDocumentAccessMode.READ_ONLY,
|
||||
Map.of());
|
||||
return new VfsTextDocument(
|
||||
return new VfsDocumentOpenResult.VfsTextDocument(
|
||||
normalizedPath,
|
||||
normalizedPath.getFileName().toString(),
|
||||
"pbs",
|
||||
Reference in New Issue
Block a user