implements PLN-0071

This commit is contained in:
2026-05-06 13:53:23 +01:00
parent ed2070c5a4
commit 69f5c4abdd
8 changed files with 469 additions and 35 deletions
@@ -6,6 +6,7 @@ import java.util.List;
public record BaselineServerDescription(
String name,
String version,
String frontendLanguageId,
boolean hoverSupported,
List<String> semanticTokenTypes,
List<BaselineVisualTheme> visualThemes,
@@ -14,6 +15,7 @@ public record BaselineServerDescription(
public BaselineServerDescription {
name = requireText(name, "name");
version = requireText(version, "version");
frontendLanguageId = requireText(frontendLanguageId, "frontendLanguageId");
semanticTokenTypes = List.copyOf(Objects.requireNonNull(semanticTokenTypes, "semanticTokenTypes"));
visualThemes = List.copyOf(Objects.requireNonNull(visualThemes, "visualThemes"));
activeVisualThemeId = requireText(activeVisualThemeId, "activeVisualThemeId");
@@ -36,6 +36,7 @@ public record CompilerLanguageServiceBridge() implements LanguageServiceBridge {
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(),
@@ -5,7 +5,9 @@ import p.studio.lsp.messages.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
@Override
@@ -26,6 +28,12 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
semanticTokens.setLegend(new SemanticTokensLegend(description.semanticTokenTypes(), List.of()));
semanticTokens.setFull(true);
capabilities.setSemanticTokensProvider(semanticTokens);
capabilities.setExperimental(Map.of(
"prometeuVisualThemes",
Map.of(
"frontendLanguageId", description.frontendLanguageId(),
"activeVisualThemeId", description.activeVisualThemeId(),
"visualThemes", description.visualThemes().stream().map(this::mapVisualThemePayload).toList())));
final InitializeResult result = new InitializeResult(capabilities);
final ServerInfo serverInfo = new ServerInfo();
@@ -122,4 +130,25 @@ public final class Lsp4jProtocolMessageMapper implements ProtocolMessageMapper {
case ERROR -> DiagnosticSeverity.Error;
};
}
private Map<String, Object> mapVisualThemePayload(final BaselineVisualTheme theme) {
final Map<String, Object> payload = new LinkedHashMap<>();
payload.put("themeId", theme.themeId());
payload.put("displayName", theme.displayName());
payload.put("editorPalette", Map.of(
"baseForeground", theme.editorPalette().baseForeground(),
"selectionBackground", theme.editorPalette().selectionBackground(),
"activeHighlightBackground", theme.editorPalette().activeHighlightBackground(),
"lineNumberForeground", theme.editorPalette().lineNumberForeground(),
"statusChipBackground", theme.editorPalette().statusChipBackground(),
"statusChipBorder", theme.editorPalette().statusChipBorder(),
"statusChipForeground", theme.editorPalette().statusChipForeground()));
payload.put("tokenStyles", theme.tokenStyles().stream().map(tokenStyle -> Map.of(
"semanticKey", tokenStyle.semanticKey(),
"foreground", tokenStyle.foreground(),
"italic", tokenStyle.italic(),
"bold", tokenStyle.bold(),
"underline", tokenStyle.underline())).toList());
return payload;
}
}
@@ -62,6 +62,7 @@ class CompilerLanguageServiceBridgeTest {
final var description = bridge.describeServer(new LspProjectContext("main", "pbs", Path.of(".")));
assertEquals("pbs", description.frontendLanguageId());
assertEquals("pbs-default", description.activeVisualThemeId());
assertEquals(1, description.visualThemes().size());
assertEquals("PBS Default", description.visualThemes().getFirst().displayName());
@@ -55,6 +55,7 @@ class PrometeuLanguageServerTest {
assertSame(expected, result);
assertEquals(1, bridge.describeServerCalls);
assertSame(bridge.serverDescription, mapper.lastServerDescription);
assertEquals("pbs", bridge.serverDescription.frontendLanguageId());
}
@Test
@@ -85,6 +86,7 @@ class PrometeuLanguageServerTest {
private final BaselineServerDescription serverDescription = new BaselineServerDescription(
"demo",
"1",
"pbs",
true,
List.of(),
List.of(new BaselineVisualTheme(