implements PLN-0073

This commit is contained in:
2026-05-06 15:26:24 +01:00
parent 9d75f2f0e2
commit e5ab4cd021
10 changed files with 193 additions and 7 deletions
@@ -0,0 +1,27 @@
package p.studio.lsp.messages;
import java.util.List;
import java.util.Objects;
public record BaselineSemanticHostProjection(
String hostId,
List<BaselineSemanticHostProjectionEntry> tokenProjections) {
public BaselineSemanticHostProjection {
hostId = requireText(hostId, "hostId");
tokenProjections = List.copyOf(Objects.requireNonNull(tokenProjections, "tokenProjections"));
if (tokenProjections.isEmpty()) {
throw new IllegalArgumentException("tokenProjections must not be empty");
}
}
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;
}
}
@@ -0,0 +1,38 @@
package p.studio.lsp.messages;
import java.util.List;
import java.util.Objects;
public record BaselineSemanticHostProjectionEntry(
String semanticKey,
String hostTokenType,
List<String> hostTokenModifiers,
String fallbackTokenType,
List<String> fallbackTokenModifiers) {
public BaselineSemanticHostProjectionEntry {
semanticKey = requireText(semanticKey, "semanticKey");
hostTokenType = requireText(hostTokenType, "hostTokenType");
hostTokenModifiers = normalizeList(hostTokenModifiers, "hostTokenModifiers");
fallbackTokenType = requireText(fallbackTokenType, "fallbackTokenType");
fallbackTokenModifiers = normalizeList(fallbackTokenModifiers, "fallbackTokenModifiers");
}
private static List<String> normalizeList(
final List<String> values,
final String field) {
return List.copyOf(Objects.requireNonNull(values, field).stream()
.map(value -> requireText(value, field + " entry"))
.toList());
}
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;
}
}
@@ -9,6 +9,7 @@ public record BaselineServerDescription(
String frontendLanguageId,
boolean hoverSupported,
List<String> semanticTokenTypes,
List<BaselineSemanticHostProjection> semanticHostProjections,
List<BaselineVisualTheme> visualThemes,
String activeVisualThemeId) {
@@ -17,8 +18,15 @@ public record BaselineServerDescription(
version = requireText(version, "version");
frontendLanguageId = requireText(frontendLanguageId, "frontendLanguageId");
semanticTokenTypes = List.copyOf(Objects.requireNonNull(semanticTokenTypes, "semanticTokenTypes"));
semanticHostProjections = List.copyOf(Objects.requireNonNull(semanticHostProjections, "semanticHostProjections"));
visualThemes = List.copyOf(Objects.requireNonNull(visualThemes, "visualThemes"));
activeVisualThemeId = requireText(activeVisualThemeId, "activeVisualThemeId");
final var hostIds = new java.util.LinkedHashSet<String>();
for (final BaselineSemanticHostProjection hostProjection : semanticHostProjections) {
if (!hostIds.add(hostProjection.hostId())) {
throw new IllegalArgumentException("duplicate semantic host projection for hostId: " + hostProjection.hostId());
}
}
if (visualThemes.stream().map(BaselineVisualTheme::themeId).noneMatch(activeVisualThemeId::equals)) {
throw new IllegalArgumentException("activeVisualThemeId must reference one of the declared visual themes");
}
@@ -6,6 +6,8 @@ import p.studio.compiler.messages.BuildingIssue;
import p.studio.compiler.models.AnalysisSnapshot;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.models.FrontendEditorPaletteSpec;
import p.studio.compiler.models.FrontendHostProjectionEntrySpec;
import p.studio.compiler.models.FrontendHostProjectionSpec;
import p.studio.compiler.PBSDefinitions;
import p.studio.compiler.models.FrontendTokenStyleSpec;
import p.studio.compiler.models.FrontendVisualThemeSpec;
@@ -33,14 +35,16 @@ public record CompilerLanguageServiceBridge() implements LanguageServiceBridge {
@Override
public BaselineServerDescription describeServer(final LspProjectContext context) {
Objects.requireNonNull(context, "context");
final var presentation = PBSDefinitions.PBS.getSemanticPresentation();
return new BaselineServerDescription(
"Prometeu Studio LSP",
"0.1.0",
context.languageId(),
true,
PBSDefinitions.PBS.getSemanticPresentation().semanticKeys(),
PBSDefinitions.PBS.getSemanticPresentation().themes().stream().map(this::mapVisualTheme).toList(),
PBSDefinitions.PBS.getSemanticPresentation().defaultThemeId());
presentation.semanticKeys(),
presentation.hostProjections().stream().map(this::mapSemanticHostProjection).toList(),
presentation.themes().stream().map(this::mapVisualTheme).toList(),
presentation.defaultThemeId());
}
@Override
@@ -205,6 +209,21 @@ public record CompilerLanguageServiceBridge() implements LanguageServiceBridge {
theme.tokenStyles().stream().map(this::mapTokenStyle).toList());
}
private BaselineSemanticHostProjection mapSemanticHostProjection(final FrontendHostProjectionSpec hostProjection) {
return new BaselineSemanticHostProjection(
hostProjection.hostId(),
hostProjection.tokenProjections().stream().map(this::mapSemanticHostProjectionEntry).toList());
}
private BaselineSemanticHostProjectionEntry mapSemanticHostProjectionEntry(final FrontendHostProjectionEntrySpec tokenProjection) {
return new BaselineSemanticHostProjectionEntry(
tokenProjection.semanticKey(),
tokenProjection.hostTokenType(),
tokenProjection.hostTokenModifiers(),
tokenProjection.fallbackTokenType(),
tokenProjection.fallbackTokenModifiers());
}
private BaselineEditorPalette mapEditorPalette(final FrontendEditorPaletteSpec palette) {
return new BaselineEditorPalette(
palette.baseForeground(),
@@ -33,7 +33,12 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
Map.of(
"frontendLanguageId", description.frontendLanguageId(),
"activeVisualThemeId", description.activeVisualThemeId(),
"visualThemes", description.visualThemes().stream().map(this::mapVisualThemePayload).toList())));
"visualThemes", description.visualThemes().stream().map(this::mapVisualThemePayload).toList()),
"prometeuSemanticHostProjections",
Map.of(
"frontendLanguageId", description.frontendLanguageId(),
"semanticKeys", description.semanticTokenTypes(),
"hostProjections", description.semanticHostProjections().stream().map(this::mapSemanticHostProjectionPayload).toList())));
final InitializeResult result = new InitializeResult(capabilities);
final ServerInfo serverInfo = new ServerInfo();
@@ -151,4 +156,16 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
"underline", tokenStyle.underline())).toList());
return payload;
}
private Map<String, Object> mapSemanticHostProjectionPayload(final BaselineSemanticHostProjection hostProjection) {
final Map<String, Object> payload = new LinkedHashMap<>();
payload.put("hostId", hostProjection.hostId());
payload.put("tokenProjections", hostProjection.tokenProjections().stream().map(tokenProjection -> Map.of(
"semanticKey", tokenProjection.semanticKey(),
"hostTokenType", tokenProjection.hostTokenType(),
"hostTokenModifiers", tokenProjection.hostTokenModifiers(),
"fallbackTokenType", tokenProjection.fallbackTokenType(),
"fallbackTokenModifiers", tokenProjection.fallbackTokenModifiers())).toList());
return payload;
}
}