fix(pbs): keep editorial signatures in source syntax
Share frontend type and return presentation across hover, completion, signature help, outline and inferred hints. Preserve generic applications, source grouping, nominal origins and navigation. Add parser structure, real module/reexport, LSP mapping and Studio consumer regressions. Document the PBS editorial contract. WRK-0021 / DEC-0001 / PLN-0001. Full make -C tooling verify passed all 11 stages: tooling/build/runs/20261126T135036Z-bed847d1/manifest.json. Commit and push explicitly requested by the user.
This commit is contained in:
+40
@@ -28,6 +28,46 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class CompilerLanguageServiceBridgeTest {
|
||||
|
||||
@Test
|
||||
void sourceReturnShapesReachTheLspMapperWithoutLosingParameters(@TempDir Path temporary) throws Exception {
|
||||
final var returns = List.of("result<Io>", "result<Io> int", "result<Io> (first: int, second: float)", "optional int");
|
||||
for (int i = 0; i < returns.size(); i++) {
|
||||
final Path root = Files.createDirectories(temporary.resolve("case" + i)).toRealPath();
|
||||
Files.createDirectories(root.resolve("src"));
|
||||
Files.writeString(root.resolve("prometeu.json"), """
|
||||
{"name":"app","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
|
||||
""");
|
||||
final String output = returns.get(i);
|
||||
final String input = output.startsWith("optional") ? "optional int" : "int";
|
||||
final String text = "declare error Io { Failed; }\nfn load(left: " + input + ", right: int) -> " + output
|
||||
+ " {}\nfn caller() { load(1, 2); }\n";
|
||||
final Path file = Files.writeString(root.resolve("src/main.pbs"), text);
|
||||
Files.writeString(root.resolve("src/mod.barrel"), "pub error Io; pub fn load(left: " + input
|
||||
+ ", right: int) -> " + output + "; pub fn caller() -> void;");
|
||||
final String expected = "load(left: " + input + ", right: int) -> " + output;
|
||||
final var bridge = new CompilerLanguageServiceBridge();
|
||||
final var context = new LspProjectContext("app", "pbs", root);
|
||||
final String uri = file.toUri().toString();
|
||||
final var mapper = new DocumentPositionMapper(text);
|
||||
final var argument = mapper.positionOf(text.indexOf("2);"));
|
||||
final var help = bridge.signatureHelp(context, uri, text, argument.line(), argument.character());
|
||||
assertEquals(1, help.activeParameter());
|
||||
assertEquals(expected, help.signatures().getFirst().label());
|
||||
assertEquals(List.of("left: " + input, "right: int"), help.signatures().getFirst().parameters());
|
||||
final var protocol = new p.studio.lsp.services.protocol.mapping.Lsp4jProtocolMessageMapper().mapSignatureHelp(help);
|
||||
assertEquals(1, protocol.getActiveParameter());
|
||||
assertEquals(expected, protocol.getSignatures().getFirst().getLabel());
|
||||
assertEquals(help.signatures().getFirst().parameters(), protocol.getSignatures().getFirst().getParameters()
|
||||
.stream().map(p -> p.getLabel().getLeft()).toList());
|
||||
final var use = mapper.positionOf(text.indexOf("load(1"));
|
||||
assertTrue(bridge.hover(context, uri, text, use.line(), use.character()).markdown().contains(expected));
|
||||
assertEquals(expected, bridge.completion(context, uri, text, use.line(), use.character()).items().stream()
|
||||
.filter(c -> c.label().equals("load")).findFirst().orElseThrow().detail());
|
||||
assertEquals(expected.substring("load".length()), bridge.documentSymbols(context, uri, text).symbols().stream()
|
||||
.filter(s -> s.name().equals("load")).findFirst().orElseThrow().detail());
|
||||
}
|
||||
}
|
||||
|
||||
@Test void genericStructsAndFreeFunctionsExposeConcreteSourceSignatures(@TempDir Path root) throws Exception {
|
||||
Files.createDirectories(root.resolve("src"));
|
||||
Files.writeString(root.resolve("prometeu.json"), """
|
||||
|
||||
Reference in New Issue
Block a user