Skip to content

Commit a192204

Browse files
committed
Move conversion of legacy semantic token types into general converter
1 parent f05f035 commit a192204

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

rascal-textmate-core/src/main/rascal/VSCodeRascal.rsc

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,7 @@ private Grammar getRscGrammar() {
2121
: p[attributes = attributes + \tag("category"(category))];
2222

2323
return visit (rsc) {
24-
25-
// The following mapping is based on:
26-
// - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
27-
// - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
28-
// With updates based on:
29-
// - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
30-
// - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
31-
case \tag("category"("Normal")) => \tag("category"("source"))
32-
case \tag("category"("Type")) => \tag("category"("type")) // Updated (before: storage.type)
33-
case \tag("category"("Identifier")) => \tag("category"("variable"))
34-
case \tag("category"("Variable")) => \tag("category"("variable"))
35-
case \tag("category"("Constant")) => \tag("category"("string")) // Updated (before: constant)
36-
case \tag("category"("Comment")) => \tag("category"("comment"))
37-
case \tag("category"("Todo")) => \tag("category"("comment"))
38-
case \tag("category"("Quote")) => \tag("category"("string")) // Updated (before: meta.string)
39-
case \tag("category"("MetaAmbiguity")) => \tag("category"("invalid"))
40-
case \tag("category"("MetaVariable")) => \tag("category"("variable"))
41-
case \tag("category"("MetaKeyword")) => \tag("category"("keyword")) // Updated (before: keyword.other)
42-
case \tag("category"("MetaSkipped")) => \tag("category"("string"))
43-
case \tag("category"("NonterminalLabel")) => \tag("category"("variable")) // Updated (before: variable.parameter)
44-
case \tag("category"("Result")) => \tag("category"("string")) // Updated (before: text)
45-
case \tag("category"("StdOut")) => \tag("category"("string")) // Updated (before: text)
46-
case \tag("category"("StdErr")) => \tag("category"("string")) // Updated (before: text)
47-
48-
// With additional hot-patching as discussed:
24+
// Temporarily hot-patch Rascal's own grammar as discussed here:
4925
// - https://github.com/SWAT-engineering/rascal-textmate/pull/6
5026
case p: prod(label("integer", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
5127
case p: prod(label("real", sort("Literal")), _, _) => setCategory(p, "constant.numeric")

rascal-textmate-core/src/main/rascal/lang/textmate/Conversion.rsc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,37 @@ TmGrammar toTmGrammar(RscGrammar rsc, str name, NameGeneration nameGeneration =
5656
RscGrammar preprocess(RscGrammar rsc) {
5757
// Replace occurrences of singleton ranges with just the corresponding
5858
// literal. This makes it easier to identify delimiters.
59-
return visit (rsc) {
59+
rsc = visit (rsc) {
6060
case \char-class([range(char, char)]) => d
6161
when d := \lit("<stringChar(char)>"), isDelimiter(d)
6262
}
63+
64+
// Replace legacy semantic token types with TextMate scopes based on:
65+
// - https://github.com/usethesource/rascal/blob/83023f60a6eb9df7a19ccc7a4194b513ac7b7157/src/org/rascalmpl/values/parsetrees/TreeAdapter.java#L44-L59
66+
// - https://github.com/usethesource/rascal-language-servers/blob/752fea3ea09101e5b22ee426b11c5e36db880225/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L121-L142
67+
// With updates based on:
68+
// - https://github.com/eclipse-lsp4j/lsp4j/blob/f235e91fbe2e45f62e185bbb9f6d21bed48eb2b9/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L5639-L5695
69+
// - https://github.com/usethesource/rascal-language-servers/blob/88be4a326128da8c81d581c2b918b4927f2185be/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java#L134-L152
70+
rsc = visit (rsc) {
71+
case \tag("category"("Normal")) => \tag("category"("source"))
72+
case \tag("category"("Type")) => \tag("category"("type")) // Updated (before: storage.type)
73+
case \tag("category"("Identifier")) => \tag("category"("variable"))
74+
case \tag("category"("Variable")) => \tag("category"("variable"))
75+
case \tag("category"("Constant")) => \tag("category"("string")) // Updated (before: constant)
76+
case \tag("category"("Comment")) => \tag("category"("comment"))
77+
case \tag("category"("Todo")) => \tag("category"("comment"))
78+
case \tag("category"("Quote")) => \tag("category"("string")) // Updated (before: meta.string)
79+
case \tag("category"("MetaAmbiguity")) => \tag("category"("invalid"))
80+
case \tag("category"("MetaVariable")) => \tag("category"("variable"))
81+
case \tag("category"("MetaKeyword")) => \tag("category"("keyword")) // Updated (before: keyword.other)
82+
case \tag("category"("MetaSkipped")) => \tag("category"("string"))
83+
case \tag("category"("NonterminalLabel")) => \tag("category"("variable")) // Updated (before: variable.parameter)
84+
case \tag("category"("Result")) => \tag("category"("string")) // Updated (before: text)
85+
case \tag("category"("StdOut")) => \tag("category"("string")) // Updated (before: text)
86+
case \tag("category"("StdErr")) => \tag("category"("string")) // Updated (before: text)
87+
}
88+
89+
return rsc;
6390
}
6491

6592
@synoposis{

0 commit comments

Comments
 (0)