implements PLN-0134
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 63.37% (18783/29640)
* Branch Coverage: 53.99% (7369/13648)
* Lines of Code: 29640
* Cyclomatic Complexity: 11938
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 674
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: 63.37% (18783/29640)
* Branch Coverage: 53.99% (7369/13648)
* Lines of Code: 29640
* Cyclomatic Complexity: 11938
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 674
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Add PBS workspace symbols as a physical flatten of the outline named-declaration set on FrontendLanguageService. Regular files only; virtual stdlib, barrels, imports, locals, and compile-only frontends stay empty. Advertise workspaceSymbolProvider with flat SymbolInformation. workspace/symbol does not require an open document. Housekeep DSC-0042 with LSN-0071.
This commit is contained in:
+1
@@ -13,6 +13,7 @@ public record BaselineServerDescription(
|
||||
boolean definitionSupported,
|
||||
boolean referencesSupported,
|
||||
boolean documentSymbolsSupported,
|
||||
boolean workspaceSymbolsSupported,
|
||||
List<String> semanticTokenTypes,
|
||||
List<BaselineSemanticHostProjection> semanticHostProjections,
|
||||
List<BaselineVisualTheme> visualThemes,
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record BaselineWorkspaceSymbol(
|
||||
String name,
|
||||
BaselineDocumentSymbolKind kind,
|
||||
String detail,
|
||||
String containerName,
|
||||
String uri,
|
||||
int startLine,
|
||||
int startCharacter,
|
||||
int endLine,
|
||||
int endCharacter) {
|
||||
|
||||
public BaselineWorkspaceSymbol {
|
||||
name = requireText(name, "name");
|
||||
kind = Objects.requireNonNull(kind, "kind");
|
||||
detail = detail == null ? "" : detail;
|
||||
containerName = containerName == null ? "" : containerName;
|
||||
uri = requireText(uri, "uri");
|
||||
if (startLine < 0 || startCharacter < 0 || endLine < 0 || endCharacter < 0) {
|
||||
throw new IllegalArgumentException("workspace symbol range coordinates must not be negative");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record BaselineWorkspaceSymbols(
|
||||
List<BaselineWorkspaceSymbol> symbols) {
|
||||
|
||||
public BaselineWorkspaceSymbols {
|
||||
symbols = symbols == null ? List.of() : List.copyOf(symbols);
|
||||
}
|
||||
|
||||
public static BaselineWorkspaceSymbols empty() {
|
||||
return new BaselineWorkspaceSymbols(List.of());
|
||||
}
|
||||
}
|
||||
+3
@@ -6,6 +6,7 @@ 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.BaselineWorkspaceSymbols;
|
||||
import p.studio.lsp.messages.BaselineSemanticTokens;
|
||||
import p.studio.lsp.messages.BaselineSignatureHelp;
|
||||
import p.studio.lsp.messages.BaselineServerDescription;
|
||||
@@ -32,6 +33,8 @@ public interface LanguageServiceBridge {
|
||||
|
||||
BaselineDocumentSymbols documentSymbols(LspProjectContext context, String documentUri, String text);
|
||||
|
||||
BaselineWorkspaceSymbols workspaceSymbols(LspProjectContext context, String query);
|
||||
|
||||
BaselineSignatureHelp signatureHelp(LspProjectContext context, String documentUri, String text, int line, int character);
|
||||
|
||||
BaselineSemanticTokens semanticTokens(LspProjectContext context, String documentUri, String text);
|
||||
|
||||
+75
@@ -14,6 +14,8 @@ import p.studio.compiler.services.FrontendProvider;
|
||||
import p.studio.compiler.services.FrontendSignature;
|
||||
import p.studio.compiler.services.FrontendSignatureHelp;
|
||||
import p.studio.compiler.services.FrontendSymbolKind;
|
||||
import p.studio.compiler.services.FrontendWorkspaceRequest;
|
||||
import p.studio.compiler.services.FrontendWorkspaceSymbol;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
import p.studio.compiler.workspaces.AssetSurfaceContextLoader;
|
||||
@@ -57,6 +59,7 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
languageServicePresent,
|
||||
languageServicePresent,
|
||||
languageServicePresent,
|
||||
languageServicePresent,
|
||||
presentation.semanticKeys(),
|
||||
presentation.hostProjections().stream().map(this::mapSemanticHostProjection).toList(),
|
||||
presentation.themes().stream().map(this::mapVisualTheme).toList(),
|
||||
@@ -235,6 +238,40 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
.orElseGet(BaselineDocumentSymbols::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineWorkspaceSymbols workspaceSymbols(
|
||||
final LspProjectContext context,
|
||||
final String query) {
|
||||
Objects.requireNonNull(context, "context");
|
||||
final var provider = frontendProvider(context);
|
||||
final var languageService = provider.languageService();
|
||||
if (languageService.isEmpty()) {
|
||||
return BaselineWorkspaceSymbols.empty();
|
||||
}
|
||||
final BuilderPipelineContext pipelineContext = BuilderPipelineContext.fromConfig(
|
||||
new BuilderPipelineConfig(
|
||||
false,
|
||||
context.projectRoot().toString(),
|
||||
"core-v1",
|
||||
SourceProviderFactory.overlayUtf8(Map.of())));
|
||||
BuilderPipelineService.INSTANCE.analyze(pipelineContext, LogAggregator.empty());
|
||||
final FrontendPhaseContext frontendPhaseContext = new FrontendPhaseContext(
|
||||
pipelineContext.resolvedWorkspace.graph().projectTable(),
|
||||
pipelineContext.fileTable,
|
||||
pipelineContext.resolvedWorkspace.stack(),
|
||||
pipelineContext.resolvedWorkspace.stdlib(),
|
||||
pipelineContext.resolvedWorkspace.target(),
|
||||
HostAdmissionContext.permissiveDefault(),
|
||||
assetSurfaceContextLoader.load(pipelineContext.resolvedWorkspace.mainProject().getRootPath()));
|
||||
return languageService.orElseThrow()
|
||||
.prepareEditorialContext(frontendPhaseContext)
|
||||
.map(editorialContext -> new BaselineWorkspaceSymbols(mapWorkspaceSymbols(
|
||||
languageService.orElseThrow().workspaceSymbols(
|
||||
new FrontendWorkspaceRequest(context.projectRoot(), query),
|
||||
editorialContext))))
|
||||
.orElseGet(BaselineWorkspaceSymbols::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext context,
|
||||
@@ -558,6 +595,44 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
children);
|
||||
}
|
||||
|
||||
private List<BaselineWorkspaceSymbol> mapWorkspaceSymbols(final List<FrontendWorkspaceSymbol> symbols) {
|
||||
if (symbols == null || symbols.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
final LinkedHashMap<Path, DocumentPositionMapper> mappers = new LinkedHashMap<>();
|
||||
final ArrayList<BaselineWorkspaceSymbol> mapped = new ArrayList<>();
|
||||
for (final FrontendWorkspaceSymbol symbol : symbols) {
|
||||
final DocumentPositionMapper mapper = mappers.computeIfAbsent(symbol.path(), this::mapperForPath);
|
||||
if (mapper == null) {
|
||||
continue;
|
||||
}
|
||||
final DocumentPosition start = mapper.positionOf(symbol.startOffset());
|
||||
final DocumentPosition end = mapper.positionOf(symbol.endOffset());
|
||||
mapped.add(new BaselineWorkspaceSymbol(
|
||||
symbol.name(),
|
||||
BaselineDocumentSymbolKind.valueOf(symbol.kind().name()),
|
||||
symbol.detail(),
|
||||
symbol.containerName(),
|
||||
symbol.path().toUri().toString(),
|
||||
start.line(),
|
||||
start.character(),
|
||||
end.line(),
|
||||
end.character()));
|
||||
}
|
||||
return List.copyOf(mapped);
|
||||
}
|
||||
|
||||
private DocumentPositionMapper mapperForPath(final Path path) {
|
||||
if (path == null || !Files.isRegularFile(path)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new DocumentPositionMapper(Files.readString(path, StandardCharsets.UTF_8));
|
||||
} catch (final Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<BaselineDefinitionLocation> mapDefinitionLocations(
|
||||
final List<FrontendDefinitionLocation> locations,
|
||||
final Path currentDocumentPath,
|
||||
|
||||
+4
-2
@@ -29,7 +29,7 @@ public final class PrometeuLanguageServer implements LanguageServer, LanguageCli
|
||||
compilerBridge,
|
||||
new Lsp4jProtocolMessageMapper(),
|
||||
null,
|
||||
new PrometeuWorkspaceService());
|
||||
null);
|
||||
}
|
||||
|
||||
PrometeuLanguageServer(
|
||||
@@ -44,7 +44,9 @@ public final class PrometeuLanguageServer implements LanguageServer, LanguageCli
|
||||
this.textDocumentService = textDocumentService != null
|
||||
? textDocumentService
|
||||
: new PrometeuTextDocumentService(project, languageServiceBridge, protocolMessageMapper);
|
||||
this.workspaceService = Objects.requireNonNull(workspaceService, "workspaceService");
|
||||
this.workspaceService = workspaceService != null
|
||||
? workspaceService
|
||||
: new PrometeuWorkspaceService(project, languageServiceBridge, protocolMessageMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+38
@@ -2,9 +2,36 @@ package p.studio.lsp.services.protocol;
|
||||
|
||||
import org.eclipse.lsp4j.DidChangeConfigurationParams;
|
||||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.eclipse.lsp4j.WorkspaceSymbol;
|
||||
import org.eclipse.lsp4j.WorkspaceSymbolParams;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
import p.studio.lsp.messages.LspProjectContext;
|
||||
import p.studio.lsp.services.LanguageServiceBridge;
|
||||
import p.studio.lsp.services.protocol.mapping.ProtocolMessageMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class PrometeuWorkspaceService implements WorkspaceService {
|
||||
private final LspProjectContext project;
|
||||
private final LanguageServiceBridge languageServiceBridge;
|
||||
private final ProtocolMessageMapper protocolMessageMapper;
|
||||
|
||||
public PrometeuWorkspaceService() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
public PrometeuWorkspaceService(
|
||||
final LspProjectContext project,
|
||||
final LanguageServiceBridge languageServiceBridge,
|
||||
final ProtocolMessageMapper protocolMessageMapper) {
|
||||
this.project = project;
|
||||
this.languageServiceBridge = languageServiceBridge;
|
||||
this.protocolMessageMapper = protocolMessageMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didChangeConfiguration(final DidChangeConfigurationParams params) {
|
||||
}
|
||||
@@ -12,4 +39,15 @@ public final class PrometeuWorkspaceService implements WorkspaceService {
|
||||
@Override
|
||||
public void didChangeWatchedFiles(final DidChangeWatchedFilesParams params) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> symbol(
|
||||
final WorkspaceSymbolParams params) {
|
||||
if (project == null || languageServiceBridge == null || protocolMessageMapper == null) {
|
||||
return CompletableFuture.completedFuture(Either.forLeft(List.of()));
|
||||
}
|
||||
final String query = params == null || params.getQuery() == null ? "" : params.getQuery();
|
||||
return CompletableFuture.completedFuture(Either.forLeft(
|
||||
protocolMessageMapper.mapWorkspaceSymbols(languageServiceBridge.workspaceSymbols(project, query))));
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -39,6 +39,7 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
capabilities.setDefinitionProvider(description.definitionSupported());
|
||||
capabilities.setReferencesProvider(description.referencesSupported());
|
||||
capabilities.setDocumentSymbolProvider(description.documentSymbolsSupported());
|
||||
capabilities.setWorkspaceSymbolProvider(description.workspaceSymbolsSupported());
|
||||
final SemanticTokensWithRegistrationOptions semanticTokens = new SemanticTokensWithRegistrationOptions();
|
||||
semanticTokens.setLegend(new SemanticTokensLegend(description.semanticTokenTypes(), List.of()));
|
||||
semanticTokens.setFull(true);
|
||||
@@ -114,6 +115,27 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
return List.copyOf(mapped);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SymbolInformation> mapWorkspaceSymbols(final BaselineWorkspaceSymbols symbols) {
|
||||
if (symbols == null || symbols.symbols().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
final ArrayList<SymbolInformation> mapped = new ArrayList<>();
|
||||
for (final BaselineWorkspaceSymbol symbol : symbols.symbols()) {
|
||||
final SymbolInformation information = new SymbolInformation();
|
||||
information.setName(symbol.name());
|
||||
information.setKind(toLspWorkspaceSymbolKind(symbol.kind(), symbol.containerName()));
|
||||
information.setContainerName(symbol.containerName());
|
||||
information.setLocation(new Location(
|
||||
symbol.uri(),
|
||||
new Range(
|
||||
new Position(symbol.startLine(), symbol.startCharacter()),
|
||||
new Position(symbol.endLine(), symbol.endCharacter()))));
|
||||
mapped.add(information);
|
||||
}
|
||||
return List.copyOf(mapped);
|
||||
}
|
||||
|
||||
private DocumentSymbol mapDocumentSymbol(
|
||||
final BaselineDocumentSymbol symbol,
|
||||
final BaselineDocumentSymbolKind parentKind) {
|
||||
@@ -135,6 +157,17 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
return mapped;
|
||||
}
|
||||
|
||||
private SymbolKind toLspWorkspaceSymbolKind(
|
||||
final BaselineDocumentSymbolKind kind,
|
||||
final String containerName) {
|
||||
if (containerName != null
|
||||
&& !containerName.isBlank()
|
||||
&& (kind == BaselineDocumentSymbolKind.ENUM || kind == BaselineDocumentSymbolKind.ERROR)) {
|
||||
return SymbolKind.EnumMember;
|
||||
}
|
||||
return toLspSymbolKind(kind, null);
|
||||
}
|
||||
|
||||
private SymbolKind toLspSymbolKind(
|
||||
final BaselineDocumentSymbolKind kind,
|
||||
final BaselineDocumentSymbolKind parentKind) {
|
||||
|
||||
+4
@@ -8,8 +8,10 @@ import org.eclipse.lsp4j.SignatureHelp;
|
||||
import org.eclipse.lsp4j.SemanticTokens;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import p.studio.lsp.messages.BaselineDocumentAnalysis;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbols;
|
||||
import p.studio.lsp.messages.BaselineWorkspaceSymbols;
|
||||
import p.studio.lsp.messages.BaselineCompletion;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
@@ -36,6 +38,8 @@ public interface ProtocolMessageMapper {
|
||||
|
||||
List<DocumentSymbol> mapDocumentSymbols(BaselineDocumentSymbols symbols);
|
||||
|
||||
List<SymbolInformation> mapWorkspaceSymbols(BaselineWorkspaceSymbols symbols);
|
||||
|
||||
CompletionList mapCompletion(BaselineCompletion completion);
|
||||
|
||||
SignatureHelp mapSignatureHelp(BaselineSignatureHelp signatureHelp);
|
||||
|
||||
+60
@@ -56,6 +56,9 @@ class CompilerLanguageServiceBridgeTest {
|
||||
final var documentSymbols = bridge.documentSymbols(context, documentUri, "fn main() {}");
|
||||
assertTrue(documentSymbols.symbols().isEmpty());
|
||||
|
||||
final var workspaceSymbols = bridge.workspaceSymbols(context, "frame");
|
||||
assertTrue(workspaceSymbols.symbols().isEmpty());
|
||||
|
||||
final var semanticTokens = bridge.semanticTokens(context, documentUri, "fn main() {}");
|
||||
assertTrue(semanticTokens.legend().isEmpty());
|
||||
assertTrue(semanticTokens.tokens().isEmpty());
|
||||
@@ -520,6 +523,62 @@ class CompilerLanguageServiceBridgeTest {
|
||||
assertNotEquals(symbols.get(1).detail(), symbols.get(2).detail());
|
||||
}
|
||||
|
||||
@Test
|
||||
void workspaceSymbolsSearchPhysicalNamedDeclarationsWithoutAnOpenDocument() {
|
||||
final Path projectRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize())
|
||||
.resolve("test-projects")
|
||||
.resolve("main")
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
final CompilerLanguageServiceBridge bridge = new CompilerLanguageServiceBridge();
|
||||
final var context = new LspProjectContext("main", "pbs", projectRoot);
|
||||
|
||||
final var frameHits = bridge.workspaceSymbols(context, "frame");
|
||||
assertTrue(frameHits.symbols().stream().anyMatch(symbol ->
|
||||
symbol.name().equals("frame") && symbol.containerName().isEmpty()));
|
||||
assertTrue(frameHits.symbols().stream().allMatch(symbol ->
|
||||
symbol.uri().contains("main.pbs")));
|
||||
|
||||
final var caseInsensitive = bridge.workspaceSymbols(context, "BLA");
|
||||
assertTrue(caseInsensitive.symbols().stream().anyMatch(symbol ->
|
||||
symbol.name().equals("Bla") && symbol.containerName().isEmpty()));
|
||||
|
||||
final var all = bridge.workspaceSymbols(context, "");
|
||||
assertTrue(all.symbols().stream().anyMatch(symbol ->
|
||||
symbol.name().equals("a") && symbol.containerName().equals("Bla")));
|
||||
assertTrue(all.symbols().stream().anyMatch(symbol -> symbol.name().equals("init")));
|
||||
assertTrue(all.symbols().stream().noneMatch(symbol ->
|
||||
symbol.name().equals("Gfx")
|
||||
|| symbol.name().equals("Log")
|
||||
|| symbol.name().equals("Composer")));
|
||||
assertTrue(isSortedByNameThenUriThenOffset(all.symbols()));
|
||||
|
||||
final var stdlibMiss = bridge.workspaceSymbols(context, "Gfx");
|
||||
assertTrue(stdlibMiss.symbols().isEmpty());
|
||||
}
|
||||
|
||||
private boolean isSortedByNameThenUriThenOffset(
|
||||
final List<p.studio.lsp.messages.BaselineWorkspaceSymbol> symbols) {
|
||||
for (int index = 1; index < symbols.size(); index += 1) {
|
||||
final var previous = symbols.get(index - 1);
|
||||
final var current = symbols.get(index);
|
||||
final int nameOrder = String.CASE_INSENSITIVE_ORDER.compare(previous.name(), current.name());
|
||||
if (nameOrder > 0) {
|
||||
return false;
|
||||
}
|
||||
if (nameOrder == 0) {
|
||||
final int uriOrder = previous.uri().compareTo(current.uri());
|
||||
if (uriOrder > 0) {
|
||||
return false;
|
||||
}
|
||||
if (uriOrder == 0 && previous.startLine() > current.startLine()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeServerPublishesFrontendVisualThemes() {
|
||||
final CompilerLanguageServiceBridge bridge = new CompilerLanguageServiceBridge();
|
||||
@@ -533,6 +592,7 @@ class CompilerLanguageServiceBridgeTest {
|
||||
assertTrue(description.definitionSupported());
|
||||
assertTrue(description.referencesSupported());
|
||||
assertTrue(description.documentSymbolsSupported());
|
||||
assertTrue(description.workspaceSymbolsSupported());
|
||||
assertEquals(1, description.semanticHostProjections().size());
|
||||
assertEquals("vscode", description.semanticHostProjections().getFirst().hostId());
|
||||
assertTrue(description.semanticHostProjections().getFirst().tokenProjections().stream()
|
||||
|
||||
+14
@@ -102,6 +102,7 @@ class PrometeuLanguageServerTest {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
List.of(),
|
||||
List.of(new BaselineSemanticHostProjection(
|
||||
"vscode",
|
||||
@@ -178,6 +179,13 @@ class PrometeuLanguageServerTest {
|
||||
return p.studio.lsp.messages.BaselineDocumentSymbols.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public p.studio.lsp.messages.BaselineWorkspaceSymbols workspaceSymbols(
|
||||
final LspProjectContext project,
|
||||
final String query) {
|
||||
return p.studio.lsp.messages.BaselineWorkspaceSymbols.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext project,
|
||||
@@ -241,6 +249,12 @@ class PrometeuLanguageServerTest {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<org.eclipse.lsp4j.SymbolInformation> mapWorkspaceSymbols(
|
||||
final p.studio.lsp.messages.BaselineWorkspaceSymbols symbols) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.CompletionList mapCompletion(final BaselineCompletion completion) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
+13
@@ -217,6 +217,13 @@ final class PrometeuTextDocumentServiceTest {
|
||||
List.of())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public p.studio.lsp.messages.BaselineWorkspaceSymbols workspaceSymbols(
|
||||
final LspProjectContext context,
|
||||
final String query) {
|
||||
return p.studio.lsp.messages.BaselineWorkspaceSymbols.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext context,
|
||||
@@ -290,6 +297,12 @@ final class PrometeuTextDocumentServiceTest {
|
||||
return documentSymbols;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.eclipse.lsp4j.SymbolInformation> mapWorkspaceSymbols(
|
||||
final p.studio.lsp.messages.BaselineWorkspaceSymbols symbols) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionList mapCompletion(final BaselineCompletion completion) {
|
||||
return completionList;
|
||||
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
package p.studio.lsp.services.protocol;
|
||||
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.eclipse.lsp4j.WorkspaceSymbolParams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.lsp.messages.BaselineCompletion;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineDocumentAnalysis;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbols;
|
||||
import p.studio.lsp.messages.BaselineDocumentSymbolKind;
|
||||
import p.studio.lsp.messages.BaselineHover;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
import p.studio.lsp.messages.BaselineSemanticTokens;
|
||||
import p.studio.lsp.messages.BaselineServerDescription;
|
||||
import p.studio.lsp.messages.BaselineSignatureHelp;
|
||||
import p.studio.lsp.messages.BaselineWorkspaceSymbol;
|
||||
import p.studio.lsp.messages.BaselineWorkspaceSymbols;
|
||||
import p.studio.lsp.messages.LspProjectContext;
|
||||
import p.studio.lsp.services.LanguageServiceBridge;
|
||||
import p.studio.lsp.services.protocol.mapping.ProtocolMessageMapper;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
final class PrometeuWorkspaceServiceTest {
|
||||
|
||||
@Test
|
||||
void symbolDelegatesQueryWithoutADocumentUri() {
|
||||
final var bridge = new RecordingBridge();
|
||||
final var mapper = new RecordingMapper();
|
||||
final var project = new LspProjectContext("main", "pbs", Path.of("."));
|
||||
final var service = new PrometeuWorkspaceService(project, bridge, mapper);
|
||||
|
||||
final var result = service.symbol(new WorkspaceSymbolParams("blend")).join();
|
||||
|
||||
assertTrue(result.isLeft());
|
||||
assertSame(mapper.workspaceSymbols, result.getLeft());
|
||||
assertEquals("blend", bridge.lastQuery);
|
||||
assertSame(project, bridge.lastContext);
|
||||
}
|
||||
|
||||
private static final class RecordingBridge implements LanguageServiceBridge {
|
||||
private LspProjectContext lastContext;
|
||||
private String lastQuery;
|
||||
|
||||
@Override
|
||||
public BaselineServerDescription describeServer(final LspProjectContext context) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineDocumentAnalysis analyzeDocument(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineCompletion completion(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text,
|
||||
final int line,
|
||||
final int character) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineHover hover(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text,
|
||||
final int line,
|
||||
final int character) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineDefinition definition(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text,
|
||||
final int line,
|
||||
final int character) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineReferences references(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text,
|
||||
final int line,
|
||||
final int character,
|
||||
final boolean includeDeclaration) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineDocumentSymbols documentSymbols(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineWorkspaceSymbols workspaceSymbols(
|
||||
final LspProjectContext context,
|
||||
final String query) {
|
||||
lastContext = context;
|
||||
lastQuery = query;
|
||||
return new BaselineWorkspaceSymbols(List.of(new BaselineWorkspaceSymbol(
|
||||
"blend",
|
||||
BaselineDocumentSymbolKind.METHOD,
|
||||
"",
|
||||
"Vec",
|
||||
"file:///tmp/demo.pbs",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
5)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text,
|
||||
final int line,
|
||||
final int character) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSemanticTokens semanticTokens(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onSave(final LspProjectContext context, final String documentUri) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingMapper implements ProtocolMessageMapper {
|
||||
private final List<SymbolInformation> workspaceSymbols = List.of(new SymbolInformation());
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.InitializeResult mapInitializeResult(final BaselineServerDescription description) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.PublishDiagnosticsParams mapDiagnostics(
|
||||
final String uri,
|
||||
final BaselineDocumentAnalysis analysis) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.PublishDiagnosticsParams emptyDiagnostics(final String uri) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.Hover mapHover(final BaselineHover hover) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.eclipse.lsp4j.Location> mapDefinition(final BaselineDefinition definition) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.eclipse.lsp4j.Location> mapReferences(final BaselineReferences references) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.eclipse.lsp4j.DocumentSymbol> mapDocumentSymbols(final BaselineDocumentSymbols symbols) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SymbolInformation> mapWorkspaceSymbols(final BaselineWorkspaceSymbols symbols) {
|
||||
return workspaceSymbols;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.CompletionList mapCompletion(final BaselineCompletion completion) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.SignatureHelp mapSignatureHelp(final BaselineSignatureHelp signatureHelp) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.SemanticTokens mapSemanticTokens(final BaselineSemanticTokens semanticTokens) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.MessageParams mapInfoMessage(final String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.MessageParams mapErrorMessage(final String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.lsp4j.MessageParams mapWarningMessage(final String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -45,6 +45,7 @@ final class Lsp4jProtocolMessageMapperTest {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
List.of("demo-keyword"),
|
||||
List.of(new BaselineSemanticHostProjection(
|
||||
"vscode",
|
||||
@@ -68,6 +69,7 @@ final class Lsp4jProtocolMessageMapperTest {
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getDefinitionProvider().getLeft());
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getReferencesProvider().getLeft());
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getDocumentSymbolProvider().getLeft());
|
||||
assertEquals(Boolean.TRUE, result.getCapabilities().getWorkspaceSymbolProvider().getLeft());
|
||||
|
||||
final var experimental = assertInstanceOf(Map.class, result.getCapabilities().getExperimental());
|
||||
final var semanticPayload = assertInstanceOf(Map.class, experimental.get("prometeuSemanticHostProjections"));
|
||||
@@ -208,4 +210,40 @@ final class Lsp4jProtocolMessageMapperTest {
|
||||
assertEquals(SymbolKind.Field, mapped.get(1).getChildren().getFirst().getKind());
|
||||
assertTrue(mapper.mapDocumentSymbols(BaselineDocumentSymbols.empty()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void workspaceSymbolsMapToFlatSymbolInformation() {
|
||||
final var mapper = new Lsp4jProtocolMessageMapper();
|
||||
final var mapped = mapper.mapWorkspaceSymbols(new p.studio.lsp.messages.BaselineWorkspaceSymbols(List.of(
|
||||
new p.studio.lsp.messages.BaselineWorkspaceSymbol(
|
||||
"blend",
|
||||
BaselineDocumentSymbolKind.METHOD,
|
||||
"(dx: int, dy: int) -> int",
|
||||
"Vec",
|
||||
"file:///tmp/demo.pbs",
|
||||
3,
|
||||
2,
|
||||
3,
|
||||
7),
|
||||
new p.studio.lsp.messages.BaselineWorkspaceSymbol(
|
||||
"Idle",
|
||||
BaselineDocumentSymbolKind.ENUM,
|
||||
"0",
|
||||
"Mode",
|
||||
"file:///tmp/demo.pbs",
|
||||
0,
|
||||
19,
|
||||
0,
|
||||
23))));
|
||||
|
||||
assertEquals(2, mapped.size());
|
||||
assertEquals("blend", mapped.getFirst().getName());
|
||||
assertEquals("Vec", mapped.getFirst().getContainerName());
|
||||
assertEquals(SymbolKind.Method, mapped.getFirst().getKind());
|
||||
assertEquals("file:///tmp/demo.pbs", mapped.getFirst().getLocation().getUri());
|
||||
assertEquals(2, mapped.getFirst().getLocation().getRange().getStart().getCharacter());
|
||||
assertEquals("Idle", mapped.get(1).getName());
|
||||
assertEquals(SymbolKind.EnumMember, mapped.get(1).getKind());
|
||||
assertTrue(mapper.mapWorkspaceSymbols(p.studio.lsp.messages.BaselineWorkspaceSymbols.empty()).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user