feat(pbs): resolve editorial chains and expose read-only external sources
Intrepid/Prometeu/Studio/pipeline/head Build started...
Test / Build skipped: 16, passed: 838
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good

This commit is contained in:
2026-10-07 09:00:31 +01:00
parent d0737df0ac
commit 967b9ec598
38 changed files with 1856 additions and 42 deletions
@@ -16,6 +16,79 @@ import static org.junit.jupiter.api.Assertions.*;
final class PbsEditorialSupportServiceTest {
private final PbsEditorialSupportService service = new PbsEditorialSupportService();
@Test
void receiverMatrixHandlesNestedCallsVariablesParenthesesAndRecovery() {
final String declarations = """
declare struct Button() { fn down(value: int) -> bool { return true; } }
declare struct Pad() { fn left() -> Button { return new Button(); } }
fn pad(value: int) -> Pad { return new Pad(); }
fn number() -> int { return 1; }
""";
for (final String receiver : List.of("pad(number()).left()", "(pad(1).left())", "typed", "inferred")) {
for (final String suffix : List.of("down(1);", "down(", "")) {
final String source = declarations + """
fn main() -> void {
let typed: Button = new Button();
let inferred = pad(1).left();
""" + receiver + "." + suffix + "\n}\ndeclare ;";
final var ast = parseAllowingErrors(source);
final int member = source.lastIndexOf(receiver + ".") + receiver.length() + 1;
assertTrue(service.completion(source, ast, ReadOnlyList.empty(), member).stream()
.anyMatch(item -> item.label().equals("down")), receiver + "/" + suffix);
if (!suffix.isEmpty()) {
assertTrue(service.hover(source, ast, ReadOnlyList.empty(), member).isPresent(), receiver);
assertFalse(service.definition(source, ast, ReadOnlyList.empty(), member).isEmpty(), receiver);
assertTrue(service.signatureHelp(source, ast, ReadOnlyList.empty(), member + 5).isPresent(), receiver);
}
}
}
}
@Test
void ambiguousAndUnknownReceiverDoNotInventMembers() {
final String source = """
declare struct A() { fn onlyA() -> int { return 1; } }
declare struct B() { fn onlyB() -> int { return 2; } }
fn choose(value: int) -> A { return new A(); }
fn choose(value: int) -> B { return new B(); }
fn main() -> void { choose(1).onlyA(); missing().onlyA(); }
""";
final var ast = parseOrdinary(source);
for (final String receiver : List.of("choose(1).", "missing().")) {
final int offset = source.indexOf(receiver) + receiver.length();
assertTrue(service.hover(source, ast, ReadOnlyList.empty(), offset).isEmpty());
assertTrue(service.definition(source, ast, ReadOnlyList.empty(), offset).isEmpty());
assertTrue(service.completion(source, ast, ReadOnlyList.empty(), offset).isEmpty());
assertTrue(service.signatureHelp(source, ast, ReadOnlyList.empty(), offset + 6).isEmpty());
}
}
@Test
void chainedReceiversShareTypeResolutionAcrossEditorialQueries() {
final String source = """
import { Input } from @sdk:input;
fn main() -> void {
Input.pad().left().down();
}
""";
final var ast = parseOrdinary(source);
final var supplemental = supplementalTopDecls("""
declare host Input { fn pad() -> Pad; }
declare builtin type Pad(pub id: int) { fn left() -> Button; }
declare builtin type Button(pub id: int) { fn down() -> bool; }
""");
final int offset = source.indexOf("down");
assertAll(
() -> assertEquals("Button", service.hover(source, ast, supplemental, offset)
.orElseThrow().origin()),
() -> assertEquals(100, service.definition(source, ast, supplemental, offset)
.getFirst().span().getFileId().getId()),
() -> assertTrue(service.completion(source, ast, supplemental, offset).stream()
.anyMatch(candidate -> candidate.label().equals("down"))),
() -> assertEquals("down() -> bool", service.signatureHelp(source, ast, supplemental, offset + 5)
.orElseThrow().signatures().getFirst().label()));
}
@Test
void shouldResolveGeneralCompletionAndHoverAcrossLocalAndImportedSymbols() {
final var source = """