implements PLN-0137 (7/7) call-hierarchy

Call hierarchy walks CallExpr nodes for functions and methods. It does
not use the references index. A cursor that is not on a callable is
empty, and type hierarchy stays unadvertised.

Housekeep DSC-0066 with LSN-0074.
This commit is contained in:
2026-09-22 09:20:28 +01:00
parent e456bb8d7a
commit 1fcecdb04d
24 changed files with 995 additions and 333 deletions
@@ -222,6 +222,62 @@ class CompilerLanguageServiceBridgeTest {
assertTrue(brokenTokens.tokens().stream().anyMatch(token -> token.semanticKey().equals("pbs-punctuation")));
}
@Test
void callHierarchyUsesAstCallsAndRefusesAStruct(@TempDir final Path tempDir) throws IOException {
final Path projectRoot = tempDir.resolve("app");
final Path source = projectRoot.resolve("src").resolve("main.pbs");
Files.createDirectories(source.getParent());
Files.writeString(projectRoot.resolve("prometeu.json"), """
{
"name": "app",
"version": "1.0.0",
"language": "pbs",
"stdlib": "1",
"target": "Game",
"dependencies": []
}
""");
final String text = """
fn helper() -> int {
return 1;
}
fn main() -> int {
return helper();
}
""";
Files.writeString(source, text);
Files.writeString(source.getParent().resolve("mod.barrel"), """
pub fn helper() -> int;
pub fn main() -> int;
""");
final CompilerLanguageServiceBridge bridge = new CompilerLanguageServiceBridge();
final LspProjectContext context = new LspProjectContext("app", "pbs", projectRoot.toRealPath());
final String uri = source.toRealPath().toUri().toString();
final DocumentPositionMapper mapper = new DocumentPositionMapper(text);
final var mainPosition = mapper.positionOf(text.indexOf("fn main") + 1);
final var prepared = bridge.prepareCallHierarchy(
context,
uri,
text,
mainPosition.line(),
mainPosition.character());
assertEquals(1, prepared.size());
assertEquals("main", prepared.getFirst().name());
final var outgoing = bridge.outgoingCalls(context, uri, text, prepared.getFirst());
assertTrue(outgoing.stream().anyMatch(call -> call.item().name().equals("helper")));
final var structPosition = mapper.positionOf(text.indexOf("fn helper") + 1);
final var helper = bridge.prepareCallHierarchy(
context,
uri,
text,
structPosition.line(),
structPosition.character());
assertEquals("helper", helper.getFirst().name());
assertTrue(bridge.incomingCalls(context, uri, text, helper.getFirst()).stream()
.anyMatch(call -> call.item().name().equals("main")));
}
@Test
void completionHoverAndSignatureHelpUseCompilerBackedEditorialResolution() {
final Path projectRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize())
@@ -830,6 +886,7 @@ class CompilerLanguageServiceBridgeTest {
assertTrue(description.foldingRangesSupported());
assertTrue(description.selectionRangesSupported());
assertTrue(description.formattingSupported());
assertTrue(description.callHierarchySupported());
assertEquals(1, description.semanticHostProjections().size());
assertEquals("vscode", description.semanticHostProjections().getFirst().hostId());
assertTrue(description.semanticHostProjections().getFirst().tokenProjections().stream()
@@ -109,6 +109,7 @@ class PrometeuLanguageServerTest {
false,
false,
false,
false,
List.of(),
List.of(new BaselineSemanticHostProjection(
"vscode",
@@ -61,6 +61,7 @@ final class Lsp4jProtocolMessageMapperTest {
true,
true,
true,
true,
List.of("demo-keyword"),
List.of(new BaselineSemanticHostProjection(
"vscode",
@@ -94,6 +95,8 @@ final class Lsp4jProtocolMessageMapperTest {
assertEquals(Boolean.TRUE, result.getCapabilities().getDocumentFormattingProvider().getLeft());
assertNull(result.getCapabilities().getDocumentRangeFormattingProvider());
assertNull(result.getCapabilities().getDocumentOnTypeFormattingProvider());
assertEquals(Boolean.TRUE, result.getCapabilities().getCallHierarchyProvider().getLeft());
assertNull(result.getCapabilities().getTypeHierarchyProvider());
final var experimental = assertInstanceOf(Map.class, result.getCapabilities().getExperimental());
final var semanticPayload = assertInstanceOf(Map.class, experimental.get("prometeuSemanticHostProjections"));
@@ -348,6 +351,7 @@ final class Lsp4jProtocolMessageMapperTest {
documentLinksSupported,
documentLinksSupported,
documentLinksSupported,
documentLinksSupported,
List.of("demo-keyword"),
List.of(new BaselineSemanticHostProjection(
"vscode",