feat(pbs): add concrete generic structs and free functions
This commit is contained in:
+2
-1
@@ -1310,7 +1310,8 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
final List<FrontendSignature> signatures = symbol.signatures();
|
||||
if (!signatures.isEmpty()) {
|
||||
markdown.append("```pbs\n");
|
||||
if (symbol.kind() == p.studio.compiler.services.FrontendSymbolKind.CONTRACT)
|
||||
if (symbol.kind() == p.studio.compiler.services.FrontendSymbolKind.CONTRACT
|
||||
|| symbol.kind() == p.studio.compiler.services.FrontendSymbolKind.STRUCT)
|
||||
markdown.append(symbol.displayName()).append('\n');
|
||||
for (int index = 0; index < signatures.size(); index += 1) {
|
||||
if (index > 0) {
|
||||
|
||||
+26
@@ -28,6 +28,32 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class CompilerLanguageServiceBridgeTest {
|
||||
|
||||
@Test void genericStructsAndFreeFunctionsExposeConcreteSourceSignatures(@TempDir Path root) throws Exception {
|
||||
Files.createDirectories(root.resolve("src"));
|
||||
Files.writeString(root.resolve("prometeu.json"), """
|
||||
{"name":"app","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
|
||||
""");
|
||||
String text = """
|
||||
declare struct Box<T>(value: T) { fn get() -> T { return this.value; } }
|
||||
fn identity<U>(value: U) -> U { return value; }
|
||||
fn demo() -> int { let box = new Box<int>(42); let value = identity<int>(42); return box.get(); }
|
||||
""";
|
||||
Path file = Files.writeString(root.resolve("src/main.pbs"), text).toRealPath();
|
||||
Files.writeString(root.resolve("src/mod.barrel"), "pub struct Box<T>; pub fn identity<U>(value: U) -> U; pub fn demo() -> int;");
|
||||
var bridge = new CompilerLanguageServiceBridge(); var context = new LspProjectContext("app", "pbs", root.toRealPath());
|
||||
var mapper = new DocumentPositionMapper(text);
|
||||
var applied = mapper.positionOf(text.indexOf("Box<int>"));
|
||||
var hover = bridge.hover(context, file.toUri().toString(), text, applied.line(), applied.character());
|
||||
assertTrue(hover.markdown().contains("Box<int>"), hover.markdown());
|
||||
assertTrue(hover.markdown().contains("get() -> int"), hover.markdown());
|
||||
var argument = mapper.positionOf(text.indexOf("identity<int>(42")+14);
|
||||
var help = bridge.signatureHelp(context, file.toUri().toString(), text, argument.line(), argument.character());
|
||||
assertEquals("identity<int>(value: int) -> int", help.signatures().getFirst().label());
|
||||
var parameter = mapper.positionOf(text.indexOf("value: T")+7);
|
||||
var definition = bridge.definition(context, file.toUri().toString(), text, parameter.line(), parameter.character());
|
||||
assertEquals(text.indexOf("<T>")+1, definition.locations().getFirst().startCharacter());
|
||||
}
|
||||
|
||||
@Test void genericContractsKeepSubstitutedSignaturesAcrossTheBridge(@TempDir Path root) throws Exception {
|
||||
Files.createDirectories(root.resolve("src"));
|
||||
Files.writeString(root.resolve("prometeu.json"), """
|
||||
|
||||
Reference in New Issue
Block a user