implements PLN-0132
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 62.51% (18192/29102)
* Branch Coverage: 53.15% (7093/13345)
* Lines of Code: 29102
* Cyclomatic Complexity: 11715
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 663
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 62.51% (18192/29102)
* Branch Coverage: 53.15% (7093/13345)
* Lines of Code: 29102
* Cyclomatic Complexity: 11715
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 663
Add PBS find-references as the request-local inverse of definition identity on FrontendLanguageService. Usage sites are identifier tokens whose definition locations intersect the cursor set. Empty results stay honest when definition is empty, including virtual stdlib paths. Honor includeDeclaration in the LSP bridge. Housekeep DSC-0040 with LSN-0069.
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
package p.studio.lsp.messages;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record BaselineReferences(
|
||||
List<BaselineDefinitionLocation> locations) {
|
||||
|
||||
public BaselineReferences {
|
||||
locations = List.copyOf(Objects.requireNonNull(locations, "locations"));
|
||||
}
|
||||
|
||||
public static BaselineReferences empty() {
|
||||
return new BaselineReferences(List.of());
|
||||
}
|
||||
}
|
||||
+1
@@ -11,6 +11,7 @@ public record BaselineServerDescription(
|
||||
boolean completionSupported,
|
||||
boolean signatureHelpSupported,
|
||||
boolean definitionSupported,
|
||||
boolean referencesSupported,
|
||||
List<String> semanticTokenTypes,
|
||||
List<BaselineSemanticHostProjection> semanticHostProjections,
|
||||
List<BaselineVisualTheme> visualThemes,
|
||||
|
||||
+9
@@ -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.BaselineReferences;
|
||||
import p.studio.lsp.messages.BaselineSemanticTokens;
|
||||
import p.studio.lsp.messages.BaselineSignatureHelp;
|
||||
import p.studio.lsp.messages.BaselineServerDescription;
|
||||
@@ -20,6 +21,14 @@ public interface LanguageServiceBridge {
|
||||
|
||||
BaselineDefinition definition(LspProjectContext context, String documentUri, String text, int line, int character);
|
||||
|
||||
BaselineReferences references(
|
||||
LspProjectContext context,
|
||||
String documentUri,
|
||||
String text,
|
||||
int line,
|
||||
int character,
|
||||
boolean includeDeclaration);
|
||||
|
||||
BaselineSignatureHelp signatureHelp(LspProjectContext context, String documentUri, String text, int line, int character);
|
||||
|
||||
BaselineSemanticTokens semanticTokens(LspProjectContext context, String documentUri, String text);
|
||||
|
||||
+49
@@ -53,6 +53,7 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
true,
|
||||
true,
|
||||
frontendProvider(context).languageService().isPresent(),
|
||||
frontendProvider(context).languageService().isPresent(),
|
||||
presentation.semanticKeys(),
|
||||
presentation.hostProjections().stream().map(this::mapSemanticHostProjection).toList(),
|
||||
presentation.themes().stream().map(this::mapVisualTheme).toList(),
|
||||
@@ -163,6 +164,50 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
.orElseGet(BaselineDefinition::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineReferences references(
|
||||
final LspProjectContext context,
|
||||
final String documentUri,
|
||||
final String text,
|
||||
final int line,
|
||||
final int character,
|
||||
final boolean includeDeclaration) {
|
||||
Objects.requireNonNull(context, "context");
|
||||
final var provider = frontendProvider(context);
|
||||
final var languageService = provider.languageService();
|
||||
if (languageService.isEmpty()) {
|
||||
return BaselineReferences.empty();
|
||||
}
|
||||
return editorialDocument(context, documentUri, text)
|
||||
.map(document -> {
|
||||
final int offset = new DocumentPositionMapper(document.text()).byteOffsetOf(line, character);
|
||||
final FrontendDocumentRequest request = new FrontendDocumentRequest(
|
||||
context.projectRoot(),
|
||||
normalizeDocumentPath(documentUri),
|
||||
document.text());
|
||||
final LinkedHashMap<String, FrontendDefinitionLocation> merged = new LinkedHashMap<>();
|
||||
for (final FrontendDefinitionLocation location : languageService.orElseThrow().references(
|
||||
request,
|
||||
document.editorialContext(),
|
||||
offset)) {
|
||||
merged.putIfAbsent(frontendLocationKey(location), location);
|
||||
}
|
||||
if (includeDeclaration) {
|
||||
for (final FrontendDefinitionLocation location : languageService.orElseThrow().definition(
|
||||
request,
|
||||
document.editorialContext(),
|
||||
offset)) {
|
||||
merged.putIfAbsent(frontendLocationKey(location), location);
|
||||
}
|
||||
}
|
||||
return new BaselineReferences(mapDefinitionLocations(
|
||||
List.copyOf(merged.values()),
|
||||
request.documentPath(),
|
||||
document.text()));
|
||||
})
|
||||
.orElseGet(BaselineReferences::empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineSignatureHelp signatureHelp(
|
||||
final LspProjectContext context,
|
||||
@@ -442,6 +487,10 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
|
||||
};
|
||||
}
|
||||
|
||||
private static String frontendLocationKey(final FrontendDefinitionLocation location) {
|
||||
return location.path() + ":" + location.startOffset() + ":" + location.endOffset();
|
||||
}
|
||||
|
||||
private List<BaselineDefinitionLocation> mapDefinitionLocations(
|
||||
final List<FrontendDefinitionLocation> locations,
|
||||
final Path currentDocumentPath,
|
||||
|
||||
+16
@@ -111,6 +111,22 @@ public final class PrometeuTextDocumentService implements TextDocumentService {
|
||||
return CompletableFuture.completedFuture(Either.forLeft(locations));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends Location>> references(final ReferenceParams params) {
|
||||
final String uri = params.getTextDocument().getUri();
|
||||
final String text = documentTextByUri.get(uri);
|
||||
final boolean includeDeclaration = params.getContext() != null
|
||||
&& Boolean.TRUE.equals(params.getContext().isIncludeDeclaration());
|
||||
return CompletableFuture.completedFuture(protocolMessageMapper.mapReferences(
|
||||
languageServiceBridge.references(
|
||||
project,
|
||||
uri,
|
||||
text,
|
||||
params.getPosition().getLine(),
|
||||
params.getPosition().getCharacter(),
|
||||
includeDeclaration)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SignatureHelp> signatureHelp(final SignatureHelpParams params) {
|
||||
final String uri = params.getTextDocument().getUri();
|
||||
|
||||
+14
-1
@@ -37,6 +37,7 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
capabilities.setSignatureHelpProvider(signatureHelpOptions);
|
||||
}
|
||||
capabilities.setDefinitionProvider(description.definitionSupported());
|
||||
capabilities.setReferencesProvider(description.referencesSupported());
|
||||
final SemanticTokensWithRegistrationOptions semanticTokens = new SemanticTokensWithRegistrationOptions();
|
||||
semanticTokens.setLegend(new SemanticTokensLegend(description.semanticTokenTypes(), List.of()));
|
||||
semanticTokens.setFull(true);
|
||||
@@ -89,7 +90,19 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
|
||||
if (definition == null || definition.locations().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return definition.locations().stream()
|
||||
return mapLocations(definition.locations());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> mapReferences(final BaselineReferences references) {
|
||||
if (references == null || references.locations().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return mapLocations(references.locations());
|
||||
}
|
||||
|
||||
private List<Location> mapLocations(final List<BaselineDefinitionLocation> locations) {
|
||||
return locations.stream()
|
||||
.map(location -> new Location(
|
||||
location.uri(),
|
||||
new Range(
|
||||
|
||||
+3
@@ -10,6 +10,7 @@ import org.eclipse.lsp4j.Location;
|
||||
import p.studio.lsp.messages.BaselineDocumentAnalysis;
|
||||
import p.studio.lsp.messages.BaselineCompletion;
|
||||
import p.studio.lsp.messages.BaselineDefinition;
|
||||
import p.studio.lsp.messages.BaselineReferences;
|
||||
import p.studio.lsp.messages.BaselineHover;
|
||||
import p.studio.lsp.messages.BaselineSemanticTokens;
|
||||
import p.studio.lsp.messages.BaselineSignatureHelp;
|
||||
@@ -29,6 +30,8 @@ public interface ProtocolMessageMapper {
|
||||
|
||||
List<Location> mapDefinition(BaselineDefinition definition);
|
||||
|
||||
List<Location> mapReferences(BaselineReferences references);
|
||||
|
||||
CompletionList mapCompletion(BaselineCompletion completion);
|
||||
|
||||
SignatureHelp mapSignatureHelp(BaselineSignatureHelp signatureHelp);
|
||||
|
||||
Reference in New Issue
Block a user