implements PLN-0035 pbs inline type hint payload production
This commit is contained in:
@@ -14,11 +14,13 @@ import p.studio.compiler.source.diagnostics.Diagnostic;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.services.PBSFrontendPhaseService;
|
||||
import p.studio.compiler.services.PbsInlineHintSurface;
|
||||
import p.studio.compiler.workspaces.AssetSurfaceContextLoader;
|
||||
import p.studio.compiler.workspaces.PipelineStage;
|
||||
import p.studio.compiler.workspaces.stages.LoadSourcesPipelineStage;
|
||||
import p.studio.compiler.workspaces.stages.ResolveDepsPipelineStage;
|
||||
import p.studio.lsp.dtos.LspDiagnosticDTO;
|
||||
import p.studio.lsp.dtos.LspInlineHintDTO;
|
||||
import p.studio.lsp.dtos.LspRangeDTO;
|
||||
import p.studio.lsp.dtos.LspSemanticPresentationDTO;
|
||||
import p.studio.lsp.messages.*;
|
||||
@@ -154,6 +156,10 @@ final class LspSemanticReadPhase {
|
||||
final Map<FileId, List<PbsAst.TopDecl>> importedSupplementalTopDeclsByFile = importedSupplementalTopDeclsByFile(
|
||||
snapshot.frontendSpec(),
|
||||
context);
|
||||
final Map<Path, List<LspInlineHintDTO>> inlineHintsByDocument = inlineHintsByDocument(
|
||||
snapshot,
|
||||
snapshot.frontendSpec(),
|
||||
context);
|
||||
final List<IndexedDocument> indexedDocuments = new ArrayList<>();
|
||||
for (final FileId fileId : snapshot.fileTable()) {
|
||||
final SourceHandle sourceHandle = snapshot.fileTable().get(fileId);
|
||||
@@ -181,7 +187,7 @@ final class LspSemanticReadPhase {
|
||||
semanticPresentation(snapshot.frontendSpec()),
|
||||
diagnosticsByDocument,
|
||||
semanticIndex.semanticHighlightsByDocument(),
|
||||
Map.of(),
|
||||
inlineHintsByDocument,
|
||||
semanticIndex.documentSymbolsByDocument(),
|
||||
semanticIndex.structuralAnchorsByDocument(),
|
||||
semanticIndex.workspaceSymbols(),
|
||||
@@ -192,9 +198,42 @@ final class LspSemanticReadPhase {
|
||||
private static Map<FileId, List<PbsAst.TopDecl>> importedSupplementalTopDeclsByFile(
|
||||
final FrontendSpec frontendSpec,
|
||||
final BuilderPipelineContext context) {
|
||||
if (context.resolvedWorkspace == null || context.fileTable == null || !"pbs".equals(frontendSpec.getLanguageId())) {
|
||||
final var surface = semanticReadSurface(frontendSpec, context);
|
||||
final Map<FileId, List<PbsAst.TopDecl>> byFile = new LinkedHashMap<>();
|
||||
for (final var entry : surface.supplementalTopDeclsByFile().entrySet()) {
|
||||
byFile.put(entry.getKey(), entry.getValue().asList());
|
||||
}
|
||||
return Map.copyOf(byFile);
|
||||
}
|
||||
|
||||
private static Map<Path, List<LspInlineHintDTO>> inlineHintsByDocument(
|
||||
final AnalysisSnapshot snapshot,
|
||||
final FrontendSpec frontendSpec,
|
||||
final BuilderPipelineContext context) {
|
||||
if (snapshot.fileTable() == null) {
|
||||
return Map.of();
|
||||
}
|
||||
final var surface = semanticReadSurface(frontendSpec, context);
|
||||
final Map<Path, List<LspInlineHintDTO>> byDocument = new LinkedHashMap<>();
|
||||
for (final var entry : surface.inlineHintsByFile().entrySet()) {
|
||||
final SourceHandle sourceHandle = snapshot.fileTable().get(entry.getKey());
|
||||
final Path documentPath = sourceHandle.getCanonPath().toAbsolutePath().normalize();
|
||||
final var hints = entry.getValue().asList().stream()
|
||||
.map(LspSemanticReadPhase::toInlineHintDTO)
|
||||
.toList();
|
||||
if (!hints.isEmpty()) {
|
||||
byDocument.put(documentPath, hints);
|
||||
}
|
||||
}
|
||||
return Map.copyOf(byDocument);
|
||||
}
|
||||
|
||||
private static PBSFrontendPhaseService.PbsSemanticReadSurface semanticReadSurface(
|
||||
final FrontendSpec frontendSpec,
|
||||
final BuilderPipelineContext context) {
|
||||
if (context.resolvedWorkspace == null || context.fileTable == null || !"pbs".equals(frontendSpec.getLanguageId())) {
|
||||
return new PBSFrontendPhaseService.PbsSemanticReadSurface(Map.of(), Map.of());
|
||||
}
|
||||
final FESurfaceContext feSurfaceContext = new AssetSurfaceContextLoader().load(context.resolvedWorkspace.mainProject().getRootPath());
|
||||
final FrontendPhaseContext frontendPhaseContext = new FrontendPhaseContext(
|
||||
context.resolvedWorkspace.graph().projectTable(),
|
||||
@@ -205,15 +244,19 @@ final class LspSemanticReadPhase {
|
||||
feSurfaceContext);
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
final var issues = BuildingIssueSink.empty();
|
||||
final var supplementalTopDecls = PBSFrontendPhaseService.importedSupplementalTopDeclsByFile(
|
||||
return PBSFrontendPhaseService.semanticReadSurface(
|
||||
frontendPhaseContext,
|
||||
diagnostics,
|
||||
issues);
|
||||
final Map<FileId, List<PbsAst.TopDecl>> byFile = new LinkedHashMap<>();
|
||||
for (final var entry : supplementalTopDecls.entrySet()) {
|
||||
byFile.put(entry.getKey(), entry.getValue().asList());
|
||||
}
|
||||
return Map.copyOf(byFile);
|
||||
}
|
||||
|
||||
private static LspInlineHintDTO toInlineHintDTO(final PbsInlineHintSurface hint) {
|
||||
return new LspInlineHintDTO(
|
||||
new LspRangeDTO(
|
||||
(int) hint.anchorSpan().getStart(),
|
||||
(int) hint.anchorSpan().getEnd()),
|
||||
hint.label(),
|
||||
hint.category());
|
||||
}
|
||||
|
||||
private record IndexedDocument(
|
||||
|
||||
Reference in New Issue
Block a user