implements PLN-0073
This commit is contained in:
+27
@@ -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;
|
||||
}
|
||||
}
|
||||
+38
@@ -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;
|
||||
}
|
||||
}
|
||||
+8
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user