Skip to content

Commit 9e7b49d

Browse files
committed
fix: Separate rules for result keyword with and without <>
fix #35 This commit separates the syntax highlighting rules for `result` types with angle brackets (`result<...>`) and `result` types without type parameters. Previously, both types were handled in a single rule, `meta.result.ty.wit`, which ended at a newline (technically "after"), comma, or closing bracket. However, if a `result` type appeared as a parameter, the scope wouldn't end until one of these conditions was met. (As observed, the scope didn’t end even when a newline was encountered, likely because it was captured by other rules, though...). This change simplifies the `meta.result.ty.wit` scope by splitting the handling of `result<...>` and `result`. Now, `result<...>` is handled similarly to `list<...>` and `tuple<...>`, while `result` without `<...>` is handled by `result-base`, which marks the `result` keyword as `entity.name.type.result.wit`. As a consequence of this change, line comments on `result<xxx> // comment` will no longer be ignored. However, this is a known issue for other types as well.
1 parent e4c1ca6 commit 9e7b49d

15 files changed

+577
-499
lines changed

syntaxes/wit.tmLanguage.json

+26-37
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,9 @@
976976
{
977977
"include": "#container"
978978
},
979+
{
980+
"include": "#result-base"
981+
},
979982
{
980983
"include": "#identifier"
981984
}
@@ -1032,6 +1035,11 @@
10321035
}
10331036
]
10341037
},
1038+
"result-base": {
1039+
"name": "entity.name.type.result.wit",
1040+
"comment": "Syntax for result types where both the `ok` and `err` types are `_`. This pattern must be placed after the #container pattern to correctly capture `result<...>`.",
1041+
"match": "\\b(result)\\b"
1042+
},
10351043
"tuple": {
10361044
"name": "meta.tuple.ty.wit",
10371045
"comment": "Syntax for WIT types such as tuple",
@@ -1135,7 +1143,7 @@
11351143
"result": {
11361144
"name": "meta.result.ty.wit",
11371145
"comment": "Syntax for WIT types such as result",
1138-
"begin": "\\b(result)\\b",
1146+
"begin": "\\b(result)\\b(\\<)",
11391147
"beginCaptures": {
11401148
"1": {
11411149
"name": "entity.name.type.result.wit"
@@ -1149,47 +1157,28 @@
11491157
"include": "#comment"
11501158
},
11511159
{
1152-
"name": "meta.inner.result.wit",
1153-
"begin": "(\\<)",
1154-
"beginCaptures": {
1155-
"1": {
1156-
"name": "punctuation.brackets.angle.begin.wit"
1157-
}
1158-
},
1159-
"patterns": [
1160-
{
1161-
"include": "#comment"
1162-
},
1163-
{
1164-
"name": "variable.other.inferred-type.result.wit",
1165-
"match": "(?<!\\w)(\\_)(?!\\w)"
1166-
},
1167-
{
1168-
"name": "meta.types.result.wit",
1169-
"include": "#types"
1170-
},
1171-
{
1172-
"name": "punctuation.comma.wit",
1173-
"match": "(?<!result)\\s*(\\,)"
1174-
},
1175-
{
1176-
"include": "#whitespace"
1177-
}
1178-
],
1179-
"end": "(\\>)",
1180-
"applyEndPatternLast": 1,
1181-
"endCaptures": {
1182-
"1": {
1183-
"name": "punctuation.brackets.angle.end.wit"
1184-
}
1185-
}
1160+
"name": "variable.other.inferred-type.result.wit",
1161+
"match": "(?<!\\w)(\\_)(?!\\w)"
1162+
},
1163+
{
1164+
"name": "meta.types.list.wit",
1165+
"include": "#types"
1166+
},
1167+
{
1168+
"name": "punctuation.comma.wit",
1169+
"match": "(?<!result)\\s*(\\,)"
11861170
},
11871171
{
11881172
"include": "#whitespace"
11891173
}
11901174
],
1191-
"end": "((?<=\\n)|(?=\\,)|(?=\\}))",
1192-
"applyEndPatternLast": 1
1175+
"end": "(\\>)",
1176+
"applyEndPatternLast": 1,
1177+
"endCaptures": {
1178+
"1": {
1179+
"name": "punctuation.brackets.angle.end.wit"
1180+
}
1181+
}
11931182
},
11941183
"handle": {
11951184
"name": "meta.handle.ty.wit",

tests/grammar/integration/import-func.wit.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
# ^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit keyword.operator.arrow.skinny.wit
7171
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.whitespace.wit
7272
# ^^^^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit entity.name.type.result.wit
73-
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit punctuation.brackets.angle.begin.wit
74-
# ^^^^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit meta.option.ty.wit entity.name.type.option.wit
75-
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit meta.option.ty.wit punctuation.brackets.angle.begin.wit
76-
# ^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit meta.option.ty.wit entity.name.type.numeric.wit
77-
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit meta.option.ty.wit punctuation.brackets.angle.end.wit
78-
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit punctuation.comma.wit
79-
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit meta.whitespace.wit
80-
# ^^^^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit entity.name.type.string.wit
81-
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.inner.result.wit punctuation.brackets.angle.end.wit
73+
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit punctuation.brackets.angle.begin.wit
74+
# ^^^^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.option.ty.wit entity.name.type.option.wit
75+
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.option.ty.wit punctuation.brackets.angle.begin.wit
76+
# ^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.option.ty.wit entity.name.type.numeric.wit
77+
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.option.ty.wit punctuation.brackets.angle.end.wit
78+
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit punctuation.comma.wit
79+
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit meta.whitespace.wit
80+
# ^^^^^^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit entity.name.type.string.wit
81+
# ^ source.wit meta.world-item.wit meta.import-item.wit meta.function.wit meta.result-list.wit meta.result.ty.wit punctuation.brackets.angle.end.wit
8282
>}
8383
#^ source.wit meta.world-item.wit punctuation.brackets.curly.end.wit
8484
>

0 commit comments

Comments
 (0)