implements PLN-0027 frontend semantic presentation contract and lsp descriptor
This commit is contained in:
+5
@@ -1,6 +1,8 @@
|
||||
package p.studio.compiler;
|
||||
|
||||
import p.studio.compiler.models.FrontendSpec;
|
||||
import p.studio.compiler.models.FrontendSemanticPresentationSpec;
|
||||
import p.studio.compiler.pbs.PbsSemanticKind;
|
||||
import p.studio.utilities.structures.ReadOnlySet;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,5 +14,8 @@ public class PBSDefinitions {
|
||||
.allowedExtensions(ReadOnlySet.from("pbs", "barrel"))
|
||||
.sourceRoots(ReadOnlySet.from("src"))
|
||||
.stdlibVersions(List.of(FrontendSpec.Stdlib.asDefault(1)))
|
||||
.semanticPresentation(new FrontendSemanticPresentationSpec(
|
||||
PbsSemanticKind.semanticKeys(),
|
||||
List.of("/themes/pbs/semantic-highlighting.css")))
|
||||
.build();
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package p.studio.compiler.pbs;
|
||||
|
||||
import p.studio.compiler.pbs.lexer.PbsToken;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public enum PbsSemanticKind {
|
||||
COMMENT("pbs-comment"),
|
||||
STRING("pbs-string"),
|
||||
NUMBER("pbs-number"),
|
||||
LITERAL("pbs-literal"),
|
||||
KEYWORD("pbs-keyword"),
|
||||
OPERATOR("pbs-operator"),
|
||||
PUNCTUATION("pbs-punctuation"),
|
||||
FUNCTION("pbs-function"),
|
||||
TYPE("pbs-type"),
|
||||
BINDING("pbs-binding"),
|
||||
IDENTIFIER("pbs-identifier");
|
||||
|
||||
private final String semanticKey;
|
||||
|
||||
PbsSemanticKind(final String semanticKey) {
|
||||
this.semanticKey = semanticKey;
|
||||
}
|
||||
|
||||
public String semanticKey() {
|
||||
return semanticKey;
|
||||
}
|
||||
|
||||
public static List<String> semanticKeys() {
|
||||
return Arrays.stream(values())
|
||||
.map(PbsSemanticKind::semanticKey)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static PbsSemanticKind forToken(final PbsToken token) {
|
||||
return switch (token.kind()) {
|
||||
case COMMENT -> COMMENT;
|
||||
case STRING_LITERAL -> STRING;
|
||||
case INT_LITERAL, FLOAT_LITERAL, BOUNDED_LITERAL -> NUMBER;
|
||||
case TRUE, FALSE, NONE -> LITERAL;
|
||||
case IMPORT, FROM, AS, SERVICE, HOST, FN, APPLY, BIND, NEW, IMPLEMENTS, USING, CTOR,
|
||||
DECLARE, LET, CONST, GLOBAL, STRUCT, CONTRACT, ERROR, ENUM, CALLBACK, BUILTIN,
|
||||
SELF, THIS, PUB, MUT, MOD, TYPE, IF, ELSE, SWITCH, DEFAULT, FOR, UNTIL, STEP,
|
||||
WHILE, BREAK, CONTINUE, RETURN, VOID, OPTIONAL, RESULT, SOME, OK, ERR, HANDLE,
|
||||
AND, OR, NOT, SPAWN, YIELD, SLEEP, MATCH -> KEYWORD;
|
||||
case PLUS, MINUS, STAR, SLASH, PERCENT, BANG, PLUS_EQUAL, MINUS_EQUAL, STAR_EQUAL,
|
||||
SLASH_EQUAL, PERCENT_EQUAL, BANG_EQUAL, EQUAL, EQUAL_EQUAL, LESS, LESS_EQUAL,
|
||||
GREATER, GREATER_EQUAL, AND_AND, OR_OR, ARROW, QUESTION -> OPERATOR;
|
||||
case LEFT_PAREN, RIGHT_PAREN, LEFT_BRACE, RIGHT_BRACE, LEFT_BRACKET, RIGHT_BRACKET,
|
||||
COMMA, COLON, SEMICOLON, AT, DOT, DOT_DOT -> PUNCTUATION;
|
||||
case IDENTIFIER, EOF -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
.editor-workspace-code-area-type-pbs {
|
||||
-fx-highlight-fill: #1b3244;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text {
|
||||
-fx-fill: #edf4fb;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .lineno {
|
||||
-fx-text-fill: #71859a;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-keyword {
|
||||
-fx-fill: #8dc7ff;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-function {
|
||||
-fx-fill: #f0cb79;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-type {
|
||||
-fx-fill: #9ddba8;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-binding {
|
||||
-fx-fill: #ffb1c8;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-string {
|
||||
-fx-fill: #e2c48c;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-number {
|
||||
-fx-fill: #c4e58a;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-comment {
|
||||
-fx-fill: #6f8192;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-literal {
|
||||
-fx-fill: #c8a2ff;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-operator {
|
||||
-fx-fill: #dbe6f1;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-punctuation {
|
||||
-fx-fill: #adc1d4;
|
||||
}
|
||||
|
||||
.editor-workspace-code-area-type-pbs .text.editor-syntax-pbs-identifier {
|
||||
-fx-fill: #edf4fb;
|
||||
}
|
||||
|
||||
.editor-workspace-status-chip-type-pbs {
|
||||
-fx-background-color: #152432;
|
||||
-fx-border-color: #4d8db9;
|
||||
-fx-text-fill: #e8f5ff;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package p.studio.compiler.pbs;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.PBSDefinitions;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
final class PbsSemanticPresentationContractTest {
|
||||
|
||||
@Test
|
||||
void shouldPublishSemanticPresentationContractThroughFrontendSpec() {
|
||||
final var presentation = PBSDefinitions.PBS.getSemanticPresentation();
|
||||
|
||||
assertFalse(presentation.semanticKeys().isEmpty());
|
||||
assertEquals(PbsSemanticKind.semanticKeys(), presentation.semanticKeys());
|
||||
assertEquals(1, presentation.resources().size());
|
||||
assertEquals("/themes/pbs/semantic-highlighting.css", presentation.resources().getFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPublishResolvableSemanticPresentationResources() {
|
||||
final var resourcePath = PBSDefinitions.PBS.getSemanticPresentation().resources().getFirst();
|
||||
final URL resource = PBSDefinitions.class.getResource(resourcePath);
|
||||
|
||||
assertNotNull(resource, resourcePath);
|
||||
assertTrue(resource.toExternalForm().endsWith("themes/pbs/semantic-highlighting.css"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user