implements PLN-0034 lsp inline hint transport contract

This commit is contained in:
2026-04-03 11:23:01 +01:00
parent 08f28b4a7d
commit 3e8f53dc16
10 changed files with 178 additions and 1 deletions
@@ -0,0 +1,18 @@
package p.studio.lsp.dtos;
import java.util.Objects;
public record LspInlineHintDTO(
LspRangeDTO anchor,
String label,
String category) {
public LspInlineHintDTO {
anchor = Objects.requireNonNull(anchor, "anchor");
label = Objects.requireNonNull(label, "label").trim();
category = Objects.requireNonNull(category, "category").trim();
if (label.isBlank()) {
throw new IllegalArgumentException("label cannot be blank");
}
}
}
@@ -2,6 +2,7 @@ package p.studio.lsp.messages;
import p.studio.lsp.dtos.LspDiagnosticDTO;
import p.studio.lsp.dtos.LspHighlightSpanDTO;
import p.studio.lsp.dtos.LspInlineHintDTO;
import p.studio.lsp.dtos.LspSemanticPresentationDTO;
import p.studio.lsp.dtos.LspSessionStateDTO;
import p.studio.lsp.dtos.LspStructuralAnchorDTO;
@@ -15,6 +16,7 @@ public record LspAnalyzeDocumentResult(
LspSemanticPresentationDTO semanticPresentation,
List<LspDiagnosticDTO> diagnostics,
List<LspHighlightSpanDTO> semanticHighlights,
List<LspInlineHintDTO> inlineHints,
List<LspSymbolDTO> documentSymbols,
List<LspStructuralAnchorDTO> structuralAnchors,
List<LspSymbolDTO> workspaceSymbols) {
@@ -24,6 +26,7 @@ public record LspAnalyzeDocumentResult(
Objects.requireNonNull(semanticPresentation, "semanticPresentation");
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
semanticHighlights = List.copyOf(Objects.requireNonNull(semanticHighlights, "semanticHighlights"));
inlineHints = List.copyOf(Objects.requireNonNull(inlineHints, "inlineHints"));
documentSymbols = List.copyOf(Objects.requireNonNull(documentSymbols, "documentSymbols"));
structuralAnchors = List.copyOf(Objects.requireNonNull(structuralAnchors, "structuralAnchors"));
workspaceSymbols = List.copyOf(Objects.requireNonNull(workspaceSymbols, "workspaceSymbols"));
@@ -0,0 +1,22 @@
package p.studio.lsp.dtos;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
final class LspInlineHintDTOTest {
@Test
void trimsLabelAndCategory() {
final var hint = new LspInlineHintDTO(new LspRangeDTO(3, 3), " int ", " type ");
assertEquals("int", hint.label());
assertEquals("type", hint.category());
}
@Test
void rejectsBlankLabels() {
assertThrows(IllegalArgumentException.class, () ->
new LspInlineHintDTO(new LspRangeDTO(1, 1), " ", "type"));
}
}
@@ -19,6 +19,7 @@ class LspSemanticAnalyseService {
session.semanticPresentation(),
session.diagnosticsByDocument().getOrDefault(normalizedRequestedDocument, List.of()),
session.semanticHighlightsByDocument().getOrDefault(normalizedRequestedDocument, List.of()),
session.inlineHintsByDocument().getOrDefault(normalizedRequestedDocument, List.of()),
session.documentSymbolsByDocument().getOrDefault(normalizedRequestedDocument, List.of()),
session.structuralAnchorsByDocument().getOrDefault(normalizedRequestedDocument, List.of()),
session.workspaceSymbols());
@@ -146,6 +146,7 @@ final class LspSemanticReadPhase {
Map.of(),
Map.of(),
Map.of(),
Map.of(),
List.of(),
Map.of(),
Map.of());
@@ -180,6 +181,7 @@ final class LspSemanticReadPhase {
semanticPresentation(snapshot.frontendSpec()),
diagnosticsByDocument,
semanticIndex.semanticHighlightsByDocument(),
Map.of(),
semanticIndex.documentSymbolsByDocument(),
semanticIndex.structuralAnchorsByDocument(),
semanticIndex.workspaceSymbols(),
@@ -3,6 +3,7 @@ package p.studio.lsp.messages;
import p.studio.compiler.pbs.lexer.PbsToken;
import p.studio.lsp.dtos.LspDiagnosticDTO;
import p.studio.lsp.dtos.LspHighlightSpanDTO;
import p.studio.lsp.dtos.LspInlineHintDTO;
import p.studio.lsp.dtos.LspSemanticPresentationDTO;
import p.studio.lsp.dtos.LspStructuralAnchorDTO;
import p.studio.lsp.dtos.LspSymbolDTO;
@@ -16,6 +17,7 @@ public record SemanticSession(
LspSemanticPresentationDTO semanticPresentation,
Map<Path, List<LspDiagnosticDTO>> diagnosticsByDocument,
Map<Path, List<LspHighlightSpanDTO>> semanticHighlightsByDocument,
Map<Path, List<LspInlineHintDTO>> inlineHintsByDocument,
Map<Path, List<LspSymbolDTO>> documentSymbolsByDocument,
Map<Path, List<LspStructuralAnchorDTO>> structuralAnchorsByDocument,
List<LspSymbolDTO> workspaceSymbols,
@@ -89,6 +89,7 @@ final class LspServiceImplTest {
assertEquals("pbs-function", semanticKeyForLexeme(analysis, OVERLAY_SOURCE, "helper"));
assertEquals(List.of("/themes/pbs/semantic-highlighting.css"), analysis.semanticPresentation().resources());
assertTrue(analysis.semanticPresentation().semanticKeys().contains("pbs-function"));
assertTrue(analysis.inlineHints().isEmpty());
assertTrue(
analysis.documentSymbols().stream().anyMatch(symbol -> symbol.name().equals("helper_call")),
@@ -204,6 +205,22 @@ final class LspServiceImplTest {
assertEquals(List.of("pbs-struct", "pbs-struct", "pbs-struct"), semanticKeysForLexeme(analysis, PROJECT_IMPORT_SOURCE, "Color"));
}
@Test
void analyzeDocumentReturnsDedicatedInlineHintTransportSurface() throws Exception {
final Path projectRoot = createProject();
final Path mainFile = projectRoot.resolve("src/main.pbs");
Files.writeString(mainFile, "fn main() -> void { let value = 1; }\n");
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 LspAnalyzeDocumentRequest(mainFile));
assertTrue(analysis.inlineHints().isEmpty(), analysis.toString());
}
private Path createProject() throws Exception {
final Path src = Files.createDirectories(tempDir.resolve("src"));
Files.writeString(tempDir.resolve("prometeu.json"), """