implements PLN-0133
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 62.84% (18504/29445)
* Branch Coverage: 53.33% (7215/13528)
* Lines of Code: 29445
* Cyclomatic Complexity: 11850
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 669
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 62.84% (18504/29445)
* Branch Coverage: 53.33% (7215/13528)
* Lines of Code: 29445
* Cyclomatic Complexity: 11850
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 669
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Add PBS document symbols as an AST-backed hierarchical outline of the open .pbs file on FrontendLanguageService. Recovered syntax is enough; unnamed InvalidDecl is omitted; barrels, imports, locals, and compile-only frontends stay empty. Advertise documentSymbolProvider with hierarchical DocumentSymbol. Housekeep DSC-0041 with LSN-0070.
This commit is contained in:
+47
@@ -15,8 +15,10 @@ import p.studio.utilities.structures.ReadOnlySet;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class CompilerLanguageServiceBridgeTest {
|
||||
@@ -51,6 +53,9 @@ class CompilerLanguageServiceBridgeTest {
|
||||
final var references = bridge.references(context, documentUri, "fn main() {}", 0, 0, true);
|
||||
assertTrue(references.locations().isEmpty());
|
||||
|
||||
final var documentSymbols = bridge.documentSymbols(context, documentUri, "fn main() {}");
|
||||
assertTrue(documentSymbols.symbols().isEmpty());
|
||||
|
||||
final var semanticTokens = bridge.semanticTokens(context, documentUri, "fn main() {}");
|
||||
assertTrue(semanticTokens.legend().isEmpty());
|
||||
assertTrue(semanticTokens.tokens().isEmpty());
|
||||
@@ -474,6 +479,47 @@ class CompilerLanguageServiceBridgeTest {
|
||||
assertTrue(builtinReferences.locations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void documentSymbolsUseAstHierarchyOfTheOpenPbsFile() {
|
||||
final Path projectRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize())
|
||||
.resolve("test-projects")
|
||||
.resolve("main")
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
final Path documentPath = projectRoot.resolve("src").resolve("main.pbs");
|
||||
final String overlay = """
|
||||
import { Gfx } from @sdk:gfx;
|
||||
|
||||
declare struct Vec(x: int) {
|
||||
ctor make(x: int) { return; }
|
||||
fn blend(dx: int, dy: int) -> int { return dx; }
|
||||
}
|
||||
|
||||
fn helper() -> int { return 42; }
|
||||
fn helper(value: int) -> int { return value; }
|
||||
|
||||
fn frame() -> void {
|
||||
let local = 1;
|
||||
helper(local);
|
||||
}
|
||||
""";
|
||||
final CompilerLanguageServiceBridge bridge = new CompilerLanguageServiceBridge();
|
||||
final var symbols = bridge.documentSymbols(
|
||||
new LspProjectContext("main", "pbs", projectRoot),
|
||||
documentPath.toUri().toString(),
|
||||
overlay).symbols();
|
||||
|
||||
assertEquals(List.of("Vec", "helper", "helper", "frame"), symbols.stream().map(symbol -> symbol.name()).toList());
|
||||
assertTrue(symbols.stream().noneMatch(symbol -> symbol.name().equals("Gfx") || symbol.name().equals("local")));
|
||||
final var vec = symbols.getFirst();
|
||||
assertEquals(p.studio.lsp.messages.BaselineDocumentSymbolKind.STRUCT, vec.kind());
|
||||
assertEquals(List.of("x", "make", "blend"), vec.children().stream().map(symbol -> symbol.name()).toList());
|
||||
assertEquals("(dx: int, dy: int) -> int", vec.children().get(2).detail());
|
||||
assertEquals("helper", symbols.get(1).name());
|
||||
assertEquals("helper", symbols.get(2).name());
|
||||
assertNotEquals(symbols.get(1).detail(), symbols.get(2).detail());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeServerPublishesFrontendVisualThemes() {
|
||||
final CompilerLanguageServiceBridge bridge = new CompilerLanguageServiceBridge();
|
||||
@@ -486,6 +532,7 @@ class CompilerLanguageServiceBridgeTest {
|
||||
assertTrue(description.signatureHelpSupported());
|
||||
assertTrue(description.definitionSupported());
|
||||
assertTrue(description.referencesSupported());
|
||||
assertTrue(description.documentSymbolsSupported());
|
||||
assertEquals(1, description.semanticHostProjections().size());
|
||||
assertEquals("vscode", description.semanticHostProjections().getFirst().hostId());
|
||||
assertTrue(description.semanticHostProjections().getFirst().tokenProjections().stream()
|
||||
|
||||
+15
@@ -101,6 +101,7 @@ class PrometeuLanguageServerTest {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
List.of(),
|
||||
List.of(new BaselineSemanticHostProjection(
|
||||
"vscode",
|
||||
@@ -169,6 +170,14 @@ class PrometeuLanguageServerTest {
|
||||
return p.studio.lsp.messages.BaselineReferences.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public p.studio.lsp.messages.BaselineDocumentSymbols documentSymbols(
|
||||
final LspProjectContext project,
|
||||
final String documentUri,
|
||||
final String text) {
|
||||
return p.studio.lsp.messages.BaselineDocumentSymbols.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext project,
|
||||
@@ -226,6 +235,12 @@ class PrometeuLanguageServerTest {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<org.eclipse.lsp4j.DocumentSymbol> mapDocumentSymbols(
|
||||
final p.studio.lsp.messages.BaselineDocumentSymbols symbols) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.CompletionList mapCompletion(final BaselineCompletion completion) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
+40
@@ -4,6 +4,8 @@ import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.CompletionParams;
|
||||
import org.eclipse.lsp4j.DefinitionParams;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.DocumentSymbolParams;
|
||||
import org.eclipse.lsp4j.ReferenceContext;
|
||||
import org.eclipse.lsp4j.ReferenceParams;
|
||||
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
|
||||
@@ -22,6 +24,9 @@ import p.studio.lsp.messages.BaselineCompletionItem;
|
||||
import p.studio.lsp.messages.BaselineCompletionItemKind;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineDefinitionLocation;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbol;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbolKind;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbols;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
import p.studio.lsp.messages.BaselineDocumentAnalysis;
|
||||
import p.studio.lsp.messages.BaselineHover;
|
||||
@@ -102,6 +107,13 @@ final class PrometeuTextDocumentServiceTest {
|
||||
assertEquals(1, bridge.lastReferencesLine);
|
||||
assertEquals(2, bridge.lastReferencesCharacter);
|
||||
assertTrue(bridge.lastIncludeDeclaration);
|
||||
|
||||
final var documentSymbols = service.documentSymbol(new DocumentSymbolParams(
|
||||
new TextDocumentIdentifier(uri))).join();
|
||||
assertEquals(1, documentSymbols.size());
|
||||
assertTrue(documentSymbols.getFirst().isRight());
|
||||
assertSame(mapper.documentSymbols.getFirst(), documentSymbols.getFirst().getRight());
|
||||
assertEquals(text, bridge.lastDocumentSymbolsText);
|
||||
}
|
||||
|
||||
private static final class RecordingBridge implements LanguageServiceBridge {
|
||||
@@ -116,6 +128,7 @@ final class PrometeuTextDocumentServiceTest {
|
||||
private int lastReferencesLine;
|
||||
private int lastReferencesCharacter;
|
||||
private boolean lastIncludeDeclaration;
|
||||
private String lastDocumentSymbolsText;
|
||||
private String lastSignatureHelpText;
|
||||
private int lastSignatureHelpLine;
|
||||
private int lastSignatureHelpCharacter;
|
||||
@@ -183,6 +196,27 @@ final class PrometeuTextDocumentServiceTest {
|
||||
return new BaselineReferences(List.of(new BaselineDefinitionLocation(documentUri, 0, 0, 0, 6)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineDocumentSymbols documentSymbols(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text) {
|
||||
lastDocumentSymbolsText = text;
|
||||
return new BaselineDocumentSymbols(List.of(new BaselineDocumentSymbol(
|
||||
"frame",
|
||||
BaselineDocumentSymbolKind.FUNCTION,
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
8,
|
||||
List.of())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext context,
|
||||
@@ -213,6 +247,7 @@ final class PrometeuTextDocumentServiceTest {
|
||||
private final SignatureHelp signatureHelp = new SignatureHelp();
|
||||
private final List<Location> definitionLocations = List.of();
|
||||
private final List<Location> referenceLocations = List.of();
|
||||
private final List<DocumentSymbol> documentSymbols = List.of(new DocumentSymbol());
|
||||
private BaselineSignatureHelp mappedSignatureHelp;
|
||||
|
||||
@Override
|
||||
@@ -250,6 +285,11 @@ final class PrometeuTextDocumentServiceTest {
|
||||
return referenceLocations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DocumentSymbol> mapDocumentSymbols(final BaselineDocumentSymbols symbols) {
|
||||
return documentSymbols;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionList mapCompletion(final BaselineCompletion completion) {
|
||||
return completionList;
|
||||
|
||||
+73
@@ -1,6 +1,7 @@
|
||||
package p.studio.lsp.services.protocol.mapping;
|
||||
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.SymbolKind;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.lsp.messages.BaselineCompletion;
|
||||
@@ -8,6 +9,9 @@ import p.studio.lsp.messages.BaselineCompletionItem;
|
||||
import p.studio.lsp.messages.BaselineCompletionItemKind;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineDefinitionLocation;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbol;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbolKind;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbols;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
import p.studio.lsp.messages.BaselineEditorPalette;
|
||||
import p.studio.lsp.messages.BaselineSemanticHostProjection;
|
||||
@@ -40,6 +44,7 @@ final class Lsp4jProtocolMessageMapperTest {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
List.of("demo-keyword"),
|
||||
List.of(new BaselineSemanticHostProjection(
|
||||
"vscode",
|
||||
@@ -62,6 +67,7 @@ final class Lsp4jProtocolMessageMapperTest {
|
||||
assertEquals(List.of("(", ","), result.getCapabilities().getSignatureHelpProvider().getTriggerCharacters());
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getDefinitionProvider().getLeft());
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getReferencesProvider().getLeft());
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getDocumentSymbolProvider().getLeft());
|
||||
|
||||
final var experimental = assertInstanceOf(Map.class, result.getCapabilities().getExperimental());
|
||||
final var semanticPayload = assertInstanceOf(Map.class, experimental.get("prometeuSemanticHostProjections"));
|
||||
@@ -135,4 +141,71 @@ final class Lsp4jProtocolMessageMapperTest {
|
||||
assertEquals(3, locations.getFirst().getRange().getStart().getCharacter());
|
||||
assertTrue(mapper.mapReferences(BaselineReferences.empty()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void documentSymbolsMapToHierarchicalDocumentSymbolTrees() {
|
||||
final var mapper = new Lsp4jProtocolMessageMapper();
|
||||
final var mapped = mapper.mapDocumentSymbols(new BaselineDocumentSymbols(List.of(
|
||||
new BaselineDocumentSymbol(
|
||||
"Mode",
|
||||
BaselineDocumentSymbolKind.ENUM,
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
28,
|
||||
0,
|
||||
14,
|
||||
0,
|
||||
18,
|
||||
List.of(new BaselineDocumentSymbol(
|
||||
"Idle",
|
||||
BaselineDocumentSymbolKind.ENUM,
|
||||
"0",
|
||||
0,
|
||||
19,
|
||||
0,
|
||||
23,
|
||||
0,
|
||||
19,
|
||||
0,
|
||||
23,
|
||||
List.of()))),
|
||||
new BaselineDocumentSymbol(
|
||||
"Point",
|
||||
BaselineDocumentSymbolKind.STRUCT,
|
||||
"",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
1,
|
||||
1,
|
||||
15,
|
||||
1,
|
||||
20,
|
||||
List.of(new BaselineDocumentSymbol(
|
||||
"x",
|
||||
BaselineDocumentSymbolKind.FIELD,
|
||||
"int",
|
||||
1,
|
||||
21,
|
||||
1,
|
||||
27,
|
||||
1,
|
||||
21,
|
||||
1,
|
||||
22,
|
||||
List.of()))))));
|
||||
|
||||
assertEquals(2, mapped.size());
|
||||
assertEquals("Mode", mapped.getFirst().getName());
|
||||
assertEquals(SymbolKind.Enum, mapped.getFirst().getKind());
|
||||
assertEquals("Idle", mapped.getFirst().getChildren().getFirst().getName());
|
||||
assertEquals(SymbolKind.EnumMember, mapped.getFirst().getChildren().getFirst().getKind());
|
||||
assertEquals("Point", mapped.get(1).getName());
|
||||
assertEquals(SymbolKind.Struct, mapped.get(1).getKind());
|
||||
assertEquals("x", mapped.get(1).getChildren().getFirst().getName());
|
||||
assertEquals(SymbolKind.Field, mapped.get(1).getChildren().getFirst().getKind());
|
||||
assertTrue(mapper.mapDocumentSymbols(BaselineDocumentSymbols.empty()).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user