Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Improve TS/TSX/JS syntax highlighting for parameters, types, and punctuation (#43437)

Clay Tercek9364d3948709
diff --git a/crates/languages/src/javascript/highlights.scm b/crates/languages/src/javascript/highlights.scm
index e5b84ab68df..378cb579f43 100644
--- a/crates/languages/src/javascript/highlights.scm
+++ b/crates/languages/src/javascript/highlights.scm
@@ -47,10 +47,45 @@
left: (identifier) @function
right: [(function_expression) (arrow_function)])
+; Parameters
+
+(required_parameter
+ (identifier) @variable.parameter)
+
+(required_parameter
+ (_
+ ([
+ (identifier)
+ (shorthand_property_identifier_pattern)
+ ]) @variable.parameter))
+
+(optional_parameter
+ (identifier) @variable.parameter)
+
+(optional_parameter
+ (_
+ ([
+ (identifier)
+ (shorthand_property_identifier_pattern)
+ ]) @variable.parameter))
+
+(catch_clause
+ parameter: (identifier) @variable.parameter)
+
+(index_signature
+ name: (identifier) @variable.parameter)
+
+(arrow_function
+ parameter: (identifier) @variable.parameter)
+
; Special identifiers
+;
+(class_declaration
+ (type_identifier) @type.class)
+
+(extends_clause
+ value: (identifier) @type.class)
-((identifier) @type
- (#match? @type "^[A-Z]"))
(type_identifier) @type
(predefined_type) @type.builtin
diff --git a/crates/languages/src/jsdoc/highlights.scm b/crates/languages/src/jsdoc/highlights.scm
index 103d32d0bd2..581b5d8111f 100644
--- a/crates/languages/src/jsdoc/highlights.scm
+++ b/crates/languages/src/jsdoc/highlights.scm
@@ -1,2 +1,3 @@
(tag_name) @keyword.jsdoc
(type) @type.jsdoc
+(identifier) @variable.jsdoc
diff --git a/crates/languages/src/tsx/highlights.scm b/crates/languages/src/tsx/highlights.scm
index ef12b3d7913..816ae3c5863 100644
--- a/crates/languages/src/tsx/highlights.scm
+++ b/crates/languages/src/tsx/highlights.scm
@@ -47,13 +47,68 @@
left: (identifier) @function
right: [(function_expression) (arrow_function)])
+; Parameters
+
+(required_parameter
+ (identifier) @variable.parameter)
+
+(required_parameter
+ (_
+ ([
+ (identifier)
+ (shorthand_property_identifier_pattern)
+ ]) @variable.parameter))
+
+(optional_parameter
+ (identifier) @variable.parameter)
+
+(optional_parameter
+ (_
+ ([
+ (identifier)
+ (shorthand_property_identifier_pattern)
+ ]) @variable.parameter))
+
+(catch_clause
+ parameter: (identifier) @variable.parameter)
+
+(index_signature
+ name: (identifier) @variable.parameter)
+
+(arrow_function
+ parameter: (identifier) @variable.parameter)
+
+(type_predicate
+ name: (identifier) @variable.parameter)
+
; Special identifiers
-((identifier) @type
- (#match? @type "^[A-Z]"))
+(type_annotation) @type
(type_identifier) @type
(predefined_type) @type.builtin
+(type_alias_declaration
+ (type_identifier) @type)
+
+(type_alias_declaration
+ value: (_
+ (type_identifier) @type))
+
+(interface_declaration
+ (type_identifier) @type)
+
+(class_declaration
+ (type_identifier) @type.class)
+
+(extends_clause
+ value: (identifier) @type.class)
+
+(extends_type_clause
+ type: (type_identifier) @type)
+
+(implements_clause
+ (type_identifier) @type)
+
([
(identifier)
(shorthand_property_identifier)
@@ -231,8 +286,42 @@
"<" @punctuation.bracket
">" @punctuation.bracket)
+(type_parameters
+ "<" @punctuation.bracket
+ ">" @punctuation.bracket)
+
(decorator "@" @punctuation.special)
+(union_type
+ ("|") @punctuation.special)
+
+(intersection_type
+ ("&") @punctuation.special)
+
+(type_annotation
+ (":") @punctuation.special)
+
+(index_signature
+ (":") @punctuation.special)
+
+(type_predicate_annotation
+ (":") @punctuation.special)
+
+(public_field_definition
+ ("?") @punctuation.special)
+
+(property_signature
+ ("?") @punctuation.special)
+
+(method_signature
+ ("?") @punctuation.special)
+
+(optional_parameter
+ ([
+ "?"
+ ":"
+ ]) @punctuation.special)
+
; Keywords
[ "abstract"
diff --git a/crates/languages/src/typescript/highlights.scm b/crates/languages/src/typescript/highlights.scm
index 5e8d55581e3..94690ca30ec 100644
--- a/crates/languages/src/typescript/highlights.scm
+++ b/crates/languages/src/typescript/highlights.scm
@@ -4,11 +4,33 @@
; Special identifiers
-((identifier) @type
- (#match? @type "^[A-Z]"))
+(type_annotation) @type
+
(type_identifier) @type
(predefined_type) @type.builtin
+(type_alias_declaration
+ (type_identifier) @type)
+
+(type_alias_declaration
+ value: (_
+ (type_identifier) @type))
+
+(interface_declaration
+ (type_identifier) @type)
+
+(class_declaration
+ (type_identifier) @type.class)
+
+(extends_clause
+ value: (identifier) @type.class)
+
+(extends_type_clause
+ type: (type_identifier) @type)
+
+(implements_clause
+ (type_identifier) @type)
+
;; Enables ts-pretty-errors
;; The Lsp returns "snippets" of typescript, which are not valid typescript in totality,
;; but should still be highlighted
@@ -114,6 +136,40 @@
(arrow_function) @function
+; Parameters
+
+(required_parameter
+ (identifier) @variable.parameter)
+
+(required_parameter
+ (_
+ ([
+ (identifier)
+ (shorthand_property_identifier_pattern)
+ ]) @variable.parameter))
+
+(optional_parameter
+ (identifier) @variable.parameter)
+
+(optional_parameter
+ (_
+ ([
+ (identifier)
+ (shorthand_property_identifier_pattern)
+ ]) @variable.parameter))
+
+(catch_clause
+ parameter: (identifier) @variable.parameter)
+
+(index_signature
+ name: (identifier) @variable.parameter)
+
+(arrow_function
+ parameter: (identifier) @variable.parameter)
+
+(type_predicate
+ name: (identifier) @variable.parameter)
+
; Literals
(this) @variable.special
@@ -244,8 +300,42 @@
"<" @punctuation.bracket
">" @punctuation.bracket)
+(type_parameters
+ "<" @punctuation.bracket
+ ">" @punctuation.bracket)
+
(decorator "@" @punctuation.special)
+(union_type
+ ("|") @punctuation.special)
+
+(intersection_type
+ ("&") @punctuation.special)
+
+(type_annotation
+ (":") @punctuation.special)
+
+(index_signature
+ (":") @punctuation.special)
+
+(type_predicate_annotation
+ (":") @punctuation.special)
+
+(public_field_definition
+ ("?") @punctuation.special)
+
+(property_signature
+ ("?") @punctuation.special)
+
+(method_signature
+ ("?") @punctuation.special)
+
+(optional_parameter
+ ([
+ "?"
+ ":"
+ ]) @punctuation.special)
+
; Keywords
[