[vscode] Fix client_end highlighting.
Previously, client_end only highlighted properly if angle brackets were
used unconditionally. So `client_end:<Foo>` and `client_end:<Foo,
optional>` would highlight correctly, but `client_end:Foo` would break
syntax highlighting until a matching `<Foo>` or `<Foo, optional>` was
found.
Change-Id: I74caadf0fd25c87048c5f91f60b52d084860019c
Reviewed-on: https://fuchsia-review.googlesource.com/c/fidl-misc/+/771242
Reviewed-by: Alex Zaslavsky <azaslavsky@google.com>
diff --git a/vscode-language-fidl/syntaxes/fidl.tmLanguage.json b/vscode-language-fidl/syntaxes/fidl.tmLanguage.json
index faa848b..c0fa637 100644
--- a/vscode-language-fidl/syntaxes/fidl.tmLanguage.json
+++ b/vscode-language-fidl/syntaxes/fidl.tmLanguage.json
@@ -551,7 +551,7 @@
"name": "entity.name.type"
}
},
- "end": "(<)\\s*(\\b[a-zA-Z_][0-9a-zA-Z_]*\\b(?:\\.\\b[a-zA-Z_][0-9a-zA-Z_]*\\b)*)\\s*(?:(,)\\s*(\\boptional\\b))?\\s*(>)",
+ "end": "(?:(<)\\s*(\\b[a-zA-Z_][0-9a-zA-Z_]*\\b(?:\\.\\b[a-zA-Z_][0-9a-zA-Z_]*\\b)*)\\s*(?:(,)\\s*(\\boptional\\b))?\\s*(>)|(\\b[a-zA-Z_][0-9a-zA-Z_]*\\b(?:\\.\\b[a-zA-Z_][0-9a-zA-Z_]*\\b)*))",
"endCaptures": {
"1": {
"name": "punctuation.bracket.angle"
@@ -567,6 +567,9 @@
},
"5": {
"name": "punctuation.bracket.angle"
+ },
+ "6": {
+ "name": "entity.name.namespace"
}
},
"patterns": [
diff --git a/vscode-language-fidl/test.test.fidl b/vscode-language-fidl/test.test.fidl
index 2e36f14..4d74d20 100644
--- a/vscode-language-fidl/test.test.fidl
+++ b/vscode-language-fidl/test.test.fidl
@@ -78,9 +78,11 @@
type Foo = resource struct {
f1 client_end:<Foo>;
- f2 server_end:<Foo>;
- f3 client_end:<Foo, optional>;
- f4 server_end:<Foo, optional>;
+ f2 client_end:Foo;
+ f3 server_end:<Foo>;
+ f4 server_end:Foo;
+ f5 client_end:<Foo, optional>;
+ f6 server_end:<Foo, optional>;
};
@foo
diff --git a/vscode-language-fidl/tools/generate-syntax.ts b/vscode-language-fidl/tools/generate-syntax.ts
index e78ede0..4a5e318 100644
--- a/vscode-language-fidl/tools/generate-syntax.ts
+++ b/vscode-language-fidl/tools/generate-syntax.ts
@@ -287,10 +287,7 @@
const SUBTYPE = seq(separator(":"), LAYOUT_REFERENCE);
-const OPTIONAL = named(
- word("optional"),
- "storage.type.modifier"
-);
+const OPTIONAL = named(word("optional"), "storage.type.modifier");
// currently the only valid placement for a type layout parameter is the
// first parameter, so take advantage of this fact to simplify this rule
@@ -301,11 +298,14 @@
// currently the only valid placement for an interface as the first parameter, so take advantage of
// this fact to simplify this rule. The only valid second argument is the optional "constant", which
// is highlighted as a `NUMERIC_CONSTANT` to conform with the style used elsewhere.
-const PROTOCOL_END_PARAMETERS = angle_brackets(
- seq(
- named(COMPOUND_IDENTIFIER, entity_name_interface),
- optional(seq(separator(","), OPTIONAL)),
- )
+const PROTOCOL_END_PARAMETERS = one_of(
+ angle_brackets(
+ seq(
+ named(COMPOUND_IDENTIFIER, entity_name_interface),
+ optional(seq(separator(","), OPTIONAL))
+ )
+ ),
+ named(COMPOUND_IDENTIFIER, entity_name_interface)
);
// Checks
@@ -418,7 +418,10 @@
end: "}",
patterns: [
...WITH_COMMENTS_AND_ATTRIBUTES,
- seq(keyword("compose"), named(COMPOUND_IDENTIFIER, entity_name_interface)),
+ seq(
+ keyword("compose"),
+ named(COMPOUND_IDENTIFIER, entity_name_interface)
+ ),
include("method"),
],
}),