implement PLN-0032 structural anchor payloads and tests

This commit is contained in:
2026-04-03 10:02:48 +01:00
parent 20851c0958
commit d93fe98bcd
13 changed files with 264 additions and 25 deletions
@@ -2,6 +2,7 @@ package p.studio.lsp;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.lsp.dtos.LspStructuralAnchorDTO;
import p.studio.lsp.messages.LspProjectContext;
import p.studio.lsp.dtos.LspDefinitionTargetDTO;
import p.studio.lsp.messages.LspAnalyzeDocumentRequest;
@@ -104,6 +105,12 @@ final class LspServiceImplTest {
assertTrue(
flatten(analysis.documentSymbols()).stream().anyMatch(symbol -> symbol.kind() == p.studio.lsp.messages.LspSymbolKind.HANDLE),
analysis.toString());
assertFalse(analysis.structuralAnchors().isEmpty(), analysis.toString());
assertEquals(OVERLAY_SOURCE.indexOf("{"), analysis.structuralAnchors().getFirst().startAnchor().startOffset());
assertTrue(
flattenAnchors(analysis.structuralAnchors()).stream().anyMatch(anchor ->
anchor.startAnchor().startOffset() == OVERLAY_SOURCE.indexOf("if true {") + "if true ".length()),
analysis.toString());
assertTrue(
analysis.workspaceSymbols().stream().anyMatch(symbol ->
symbol.name().equals("helper") && symbol.documentPath().equals(normalize(helperFile))),
@@ -236,6 +243,16 @@ final class LspServiceImplTest {
return flattened;
}
private static List<LspStructuralAnchorDTO> flattenAnchors(
final List<LspStructuralAnchorDTO> anchors) {
final List<LspStructuralAnchorDTO> flattened = new java.util.ArrayList<>();
for (final var anchor : anchors) {
flattened.add(anchor);
flattened.addAll(flattenAnchors(anchor.children()));
}
return flattened;
}
private VfsProjectContext projectContext(final Path projectRoot) {
return new VfsProjectContext("Example", "pbs", projectRoot);
}