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:
+41
@@ -0,0 +1,41 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record BaselineDocumentSymbol(
|
||||
String name,
|
||||
BaselineDocumentSymbolKind kind,
|
||||
String detail,
|
||||
int startLine,
|
||||
int startCharacter,
|
||||
int endLine,
|
||||
int endCharacter,
|
||||
int selectionStartLine,
|
||||
int selectionStartCharacter,
|
||||
int selectionEndLine,
|
||||
int selectionEndCharacter,
|
||||
List<BaselineDocumentSymbol> children) {
|
||||
|
||||
public BaselineDocumentSymbol {
|
||||
name = requireText(name, "name");
|
||||
kind = Objects.requireNonNull(kind, "kind");
|
||||
detail = detail == null ? "" : detail;
|
||||
if (startLine < 0 || startCharacter < 0 || endLine < 0 || endCharacter < 0
|
||||
|| selectionStartLine < 0 || selectionStartCharacter < 0
|
||||
|| selectionEndLine < 0 || selectionEndCharacter < 0) {
|
||||
throw new IllegalArgumentException("document symbol range coordinates must not be negative");
|
||||
}
|
||||
children = children == null ? List.of() : List.copyOf(children);
|
||||
}
|
||||
|
||||
private static String requireText(
|
||||
final String value,
|
||||
final String field) {
|
||||
final String candidate = Objects.requireNonNull(value, field).trim();
|
||||
if (candidate.isEmpty()) {
|
||||
throw new IllegalArgumentException(field + " must not be blank");
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
public enum BaselineDocumentSymbolKind {
|
||||
KEYWORD,
|
||||
LOCAL,
|
||||
PARAMETER,
|
||||
FIELD,
|
||||
FUNCTION,
|
||||
METHOD,
|
||||
CONSTRUCTOR,
|
||||
STRUCT,
|
||||
BUILTIN_TYPE,
|
||||
SERVICE,
|
||||
HOST,
|
||||
CONTRACT,
|
||||
CALLBACK,
|
||||
ENUM,
|
||||
ERROR,
|
||||
GLOBAL,
|
||||
CONST
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record BaselineDocumentSymbols(
|
||||
List<BaselineDocumentSymbol> symbols) {
|
||||
|
||||
public BaselineDocumentSymbols {
|
||||
symbols = symbols == null ? List.of() : List.copyOf(symbols);
|
||||
}
|
||||
|
||||
public static BaselineDocumentSymbols empty() {
|
||||
return new BaselineDocumentSymbols(List.of());
|
||||
}
|
||||
}
|
||||
+1
@@ -12,6 +12,7 @@ public record BaselineServerDescription(
|
||||
boolean signatureHelpSupported,
|
||||
boolean definitionSupported,
|
||||
boolean referencesSupported,
|
||||
boolean documentSymbolsSupported,
|
||||
List<String> semanticTokenTypes,
|
||||
List<BaselineSemanticHostProjection> semanticHostProjections,
|
||||
List<BaselineVisualTheme> visualThemes,
|
||||
|
||||
+3
@@ -4,6 +4,7 @@ import p.studio.lsp.messages.BaselineDocumentAnalysis;
|
||||
import p.studio.lsp.messages.BaselineCompletion;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineHover;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbols;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
import p.studio.lsp.messages.BaselineSemanticTokens;
|
||||
import p.studio.lsp.messages.BaselineSignatureHelp;
|
||||
@@ -29,6 +30,8 @@ public interface LanguageServiceBridge {
|
||||
int character,
|
||||
boolean includeDeclaration);
|
||||
|
||||
BaselineDocumentSymbols documentSymbols(LspProjectContext context, String documentUri, String text);
|
||||
|
||||
BaselineSignatureHelp signatureHelp(LspProjectContext context, String documentUri, String text, int line, int character);
|
||||
|
||||
BaselineSemanticTokens semanticTokens(LspProjectContext context, String documentUri, String text);
|
||||
|
||||
+69
-2
@@ -7,6 +7,7 @@ import p.studio.compiler.models.*;
|
||||
import p.studio.compiler.services.FrontendCompletionCandidate;
|
||||
import p.studio.compiler.services.FrontendDefinitionLocation;
|
||||
import p.studio.compiler.services.FrontendDocumentRequest;
|
||||
import p.studio.compiler.services.FrontendDocumentSymbol;
|
||||
import p.studio.compiler.services.FrontendEditorialContext;
|
||||
import p.studio.compiler.services.FrontendHover;
|
||||
import p.studio.compiler.services.FrontendProvider;
|
||||
@@ -45,6 +46,7 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
Objects.requireNonNull(context, "context");
|
||||
final var frontend = frontendSpec(context);
|
||||
final var presentation = frontend.getSemanticPresentation();
|
||||
final boolean languageServicePresent = frontendProvider(context).languageService().isPresent();
|
||||
return new BaselineServerDescription(
|
||||
"Prometeu Studio LSP",
|
||||
"0.1.0",
|
||||
@@ -52,8 +54,9 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
frontendProvider(context).languageService().isPresent(),
|
||||
frontendProvider(context).languageService().isPresent(),
|
||||
languageServicePresent,
|
||||
languageServicePresent,
|
||||
languageServicePresent,
|
||||
presentation.semanticKeys(),
|
||||
presentation.hostProjections().stream().map(this::mapSemanticHostProjection).toList(),
|
||||
presentation.themes().stream().map(this::mapVisualTheme).toList(),
|
||||
@@ -208,6 +211,30 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
.orElseGet(BaselineReferences::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineDocumentSymbols documentSymbols(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text) {
|
||||
Objects.requireNonNull(context, "context");
|
||||
final var provider = frontendProvider(context);
|
||||
final var languageService = provider.languageService();
|
||||
if (languageService.isEmpty()) {
|
||||
return BaselineDocumentSymbols.empty();
|
||||
}
|
||||
return editorialDocument(context, documentUri, text)
|
||||
.map(document -> {
|
||||
final FrontendDocumentRequest request = new FrontendDocumentRequest(
|
||||
context.projectRoot(),
|
||||
normalizeDocumentPath(documentUri),
|
||||
document.text());
|
||||
return new BaselineDocumentSymbols(mapDocumentSymbols(
|
||||
languageService.orElseThrow().documentSymbols(request, document.editorialContext()),
|
||||
document.text()));
|
||||
})
|
||||
.orElseGet(BaselineDocumentSymbols::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext context,
|
||||
@@ -491,6 +518,46 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
return location.path() + ":" + location.startOffset() + ":" + location.endOffset();
|
||||
}
|
||||
|
||||
private List<BaselineDocumentSymbol> mapDocumentSymbols(
|
||||
final List<FrontendDocumentSymbol> symbols,
|
||||
final String documentText) {
|
||||
if (symbols == null || symbols.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
final DocumentPositionMapper mapper = new DocumentPositionMapper(documentText == null ? "" : documentText);
|
||||
final ArrayList<BaselineDocumentSymbol> mapped = new ArrayList<>();
|
||||
for (final FrontendDocumentSymbol symbol : symbols) {
|
||||
mapped.add(mapDocumentSymbol(symbol, mapper));
|
||||
}
|
||||
return List.copyOf(mapped);
|
||||
}
|
||||
|
||||
private BaselineDocumentSymbol mapDocumentSymbol(
|
||||
final FrontendDocumentSymbol symbol,
|
||||
final DocumentPositionMapper mapper) {
|
||||
final DocumentPosition rangeStart = mapper.positionOf(symbol.rangeStart());
|
||||
final DocumentPosition rangeEnd = mapper.positionOf(symbol.rangeEnd());
|
||||
final DocumentPosition selectionStart = mapper.positionOf(symbol.selectionStart());
|
||||
final DocumentPosition selectionEnd = mapper.positionOf(symbol.selectionEnd());
|
||||
final ArrayList<BaselineDocumentSymbol> children = new ArrayList<>();
|
||||
for (final FrontendDocumentSymbol child : symbol.children()) {
|
||||
children.add(mapDocumentSymbol(child, mapper));
|
||||
}
|
||||
return new BaselineDocumentSymbol(
|
||||
symbol.name(),
|
||||
BaselineDocumentSymbolKind.valueOf(symbol.kind().name()),
|
||||
symbol.detail(),
|
||||
rangeStart.line(),
|
||||
rangeStart.character(),
|
||||
rangeEnd.line(),
|
||||
rangeEnd.character(),
|
||||
selectionStart.line(),
|
||||
selectionStart.character(),
|
||||
selectionEnd.line(),
|
||||
selectionEnd.character(),
|
||||
children);
|
||||
}
|
||||
|
||||
private List<BaselineDefinitionLocation> mapDefinitionLocations(
|
||||
final List<FrontendDefinitionLocation> locations,
|
||||
final Path currentDocumentPath,
|
||||
|
||||
+14
@@ -8,6 +8,7 @@ import p.studio.lsp.messages.LspProjectContext;
|
||||
import p.studio.lsp.services.LanguageServiceBridge;
|
||||
import p.studio.lsp.services.protocol.mapping.ProtocolMessageMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -127,6 +128,19 @@ public final class PrometeuTextDocumentService implements TextDocumentService {
|
||||
includeDeclaration)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
|
||||
final DocumentSymbolParams params) {
|
||||
final String uri = params.getTextDocument().getUri();
|
||||
final String text = documentTextByUri.get(uri);
|
||||
final List<Either<SymbolInformation, DocumentSymbol>> symbols = new ArrayList<>();
|
||||
for (final DocumentSymbol symbol : protocolMessageMapper.mapDocumentSymbols(
|
||||
languageServiceBridge.documentSymbols(project, uri, text))) {
|
||||
symbols.add(Either.forRight(symbol));
|
||||
}
|
||||
return CompletableFuture.completedFuture(List.copyOf(symbols));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SignatureHelp> signatureHelp(final SignatureHelpParams params) {
|
||||
final String uri = params.getTextDocument().getUri();
|
||||
|
||||
+57
@@ -38,6 +38,7 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
}
|
||||
capabilities.setDefinitionProvider(description.definitionSupported());
|
||||
capabilities.setReferencesProvider(description.referencesSupported());
|
||||
capabilities.setDocumentSymbolProvider(description.documentSymbolsSupported());
|
||||
final SemanticTokensWithRegistrationOptions semanticTokens = new SemanticTokensWithRegistrationOptions();
|
||||
semanticTokens.setLegend(new SemanticTokensLegend(description.semanticTokenTypes(), List.of()));
|
||||
semanticTokens.setFull(true);
|
||||
@@ -101,6 +102,62 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
return mapLocations(references.locations());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DocumentSymbol> mapDocumentSymbols(final BaselineDocumentSymbols symbols) {
|
||||
if (symbols == null || symbols.symbols().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
final ArrayList<DocumentSymbol> mapped = new ArrayList<>();
|
||||
for (final BaselineDocumentSymbol symbol : symbols.symbols()) {
|
||||
mapped.add(mapDocumentSymbol(symbol, null));
|
||||
}
|
||||
return List.copyOf(mapped);
|
||||
}
|
||||
|
||||
private DocumentSymbol mapDocumentSymbol(
|
||||
final BaselineDocumentSymbol symbol,
|
||||
final BaselineDocumentSymbolKind parentKind) {
|
||||
final DocumentSymbol mapped = new DocumentSymbol();
|
||||
mapped.setName(symbol.name());
|
||||
mapped.setDetail(symbol.detail());
|
||||
mapped.setKind(toLspSymbolKind(symbol.kind(), parentKind));
|
||||
mapped.setRange(new Range(
|
||||
new Position(symbol.startLine(), symbol.startCharacter()),
|
||||
new Position(symbol.endLine(), symbol.endCharacter())));
|
||||
mapped.setSelectionRange(new Range(
|
||||
new Position(symbol.selectionStartLine(), symbol.selectionStartCharacter()),
|
||||
new Position(symbol.selectionEndLine(), symbol.selectionEndCharacter())));
|
||||
final ArrayList<DocumentSymbol> children = new ArrayList<>();
|
||||
for (final BaselineDocumentSymbol child : symbol.children()) {
|
||||
children.add(mapDocumentSymbol(child, symbol.kind()));
|
||||
}
|
||||
mapped.setChildren(children);
|
||||
return mapped;
|
||||
}
|
||||
|
||||
private SymbolKind toLspSymbolKind(
|
||||
final BaselineDocumentSymbolKind kind,
|
||||
final BaselineDocumentSymbolKind parentKind) {
|
||||
if (parentKind == BaselineDocumentSymbolKind.ENUM || parentKind == BaselineDocumentSymbolKind.ERROR) {
|
||||
if (kind == BaselineDocumentSymbolKind.ENUM || kind == BaselineDocumentSymbolKind.ERROR) {
|
||||
return SymbolKind.EnumMember;
|
||||
}
|
||||
}
|
||||
return switch (kind) {
|
||||
case FUNCTION -> SymbolKind.Function;
|
||||
case METHOD -> SymbolKind.Method;
|
||||
case CONSTRUCTOR -> SymbolKind.Constructor;
|
||||
case FIELD -> SymbolKind.Field;
|
||||
case STRUCT, BUILTIN_TYPE -> SymbolKind.Struct;
|
||||
case SERVICE, HOST -> SymbolKind.Class;
|
||||
case CONTRACT, CALLBACK -> SymbolKind.Interface;
|
||||
case ENUM, ERROR -> SymbolKind.Enum;
|
||||
case GLOBAL, LOCAL, PARAMETER -> SymbolKind.Variable;
|
||||
case CONST -> SymbolKind.Constant;
|
||||
case KEYWORD -> SymbolKind.Key;
|
||||
};
|
||||
}
|
||||
|
||||
private List<Location> mapLocations(final List<BaselineDefinitionLocation> locations) {
|
||||
return locations.stream()
|
||||
.map(location -> new Location(
|
||||
|
||||
+4
@@ -6,8 +6,10 @@ import org.eclipse.lsp4j.MessageParams;
|
||||
import org.eclipse.lsp4j.PublishDiagnosticsParams;
|
||||
import org.eclipse.lsp4j.SignatureHelp;
|
||||
import org.eclipse.lsp4j.SemanticTokens;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import p.studio.lsp.messages.BaselineDocumentAnalysis;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbols;
|
||||
import p.studio.lsp.messages.BaselineCompletion;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
@@ -32,6 +34,8 @@ public interface ProtocolMessageMapper {
|
||||
|
||||
List<Location> mapReferences(BaselineReferences references);
|
||||
|
||||
List<DocumentSymbol> mapDocumentSymbols(BaselineDocumentSymbols symbols);
|
||||
|
||||
CompletionList mapCompletion(BaselineCompletion completion);
|
||||
|
||||
SignatureHelp mapSignatureHelp(BaselineSignatureHelp signatureHelp);
|
||||
|
||||
+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