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);
|
||||
|
||||
Reference in New Issue
Block a user