From 110bedee730835531b27e9a6f260c55c48f9423c Mon Sep 17 00:00:00 2001 From: chbk Date: Fri, 21 Feb 2025 13:30:30 +0100 Subject: [PATCH 1/4] Improve JavaScript syntax highlighting --- .../languages/src/javascript/highlights.scm | 25 +++++++++++-------- crates/languages/src/jsdoc/highlights.scm | 4 +-- crates/languages/src/tsx/highlights.scm | 25 +++++++++++-------- .../languages/src/typescript/highlights.scm | 7 ++++-- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/crates/languages/src/javascript/highlights.scm b/crates/languages/src/javascript/highlights.scm index 711e2e5d48759f..b1c144fec037fc 100644 --- a/crates/languages/src/javascript/highlights.scm +++ b/crates/languages/src/javascript/highlights.scm @@ -54,8 +54,8 @@ (identifier) (shorthand_property_identifier) (shorthand_property_identifier_pattern) - ] @constant - (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) + ] @constant.variable + (#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$")) ; Literals @@ -82,6 +82,7 @@ (escape_sequence) @string.escape (regex) @string.regex +(regex_flags) @keyword.regex (number) @number ; Tokens @@ -210,6 +211,8 @@ "<" @punctuation.bracket ">" @punctuation.bracket) +(decorator "@" @punctuation.special) + ; Keywords [ "abstract" @@ -229,11 +232,13 @@ ] @keyword ; JSX elements -(jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$")) -(jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$")) -(jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$")) - -(jsx_attribute (property_identifier) @attribute) -(jsx_opening_element (["<" ">"]) @punctuation.bracket) -(jsx_closing_element ([""]) @punctuation.bracket) -(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket) +(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) +(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) +(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) + +(jsx_attribute (property_identifier) @attribute.jsx) +(jsx_opening_element (["<" ">"]) @punctuation.jsx.bracket) +(jsx_closing_element ([""]) @punctuation.jsx.bracket) +(jsx_self_closing_element (["<" "/>"]) @punctuation.jsx.bracket) +(jsx_attribute "=" @punctuation.jsx.delimiter) +(jsx_text) @text.jsx diff --git a/crates/languages/src/jsdoc/highlights.scm b/crates/languages/src/jsdoc/highlights.scm index 4b4266c9fd1c97..7eee7b698b5941 100644 --- a/crates/languages/src/jsdoc/highlights.scm +++ b/crates/languages/src/jsdoc/highlights.scm @@ -1,2 +1,2 @@ -(tag_name) @keyword -(type) @type +(tag_name) @comment.doc.keyword +(type) @comment.doc.type diff --git a/crates/languages/src/tsx/highlights.scm b/crates/languages/src/tsx/highlights.scm index 323f58c5577f30..c95ecf2a130320 100644 --- a/crates/languages/src/tsx/highlights.scm +++ b/crates/languages/src/tsx/highlights.scm @@ -57,8 +57,8 @@ (identifier) (shorthand_property_identifier) (shorthand_property_identifier_pattern) - ] @constant - (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) + ] @constant.variable + (#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$")) ; Literals @@ -86,6 +86,7 @@ (escape_sequence) @string.escape (regex) @string.regex +(regex_flags) @keyword.regex (number) @number ; Tokens @@ -221,6 +222,8 @@ "<" @punctuation.bracket ">" @punctuation.bracket) +(decorator "@" @punctuation.special) + ; Keywords [ "abstract" @@ -240,11 +243,13 @@ ] @keyword ; JSX elements -(jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$")) -(jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$")) -(jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$")) - -(jsx_attribute (property_identifier) @attribute) -(jsx_opening_element (["<" ">"]) @punctuation.bracket) -(jsx_closing_element ([""]) @punctuation.bracket) -(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket) +(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) +(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) +(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) + +(jsx_attribute (property_identifier) @attribute.jsx) +(jsx_opening_element (["<" ">"]) @punctuation.jsx.bracket) +(jsx_closing_element ([""]) @punctuation.jsx.bracket) +(jsx_self_closing_element (["<" "/>"]) @punctuation.jsx.bracket) +(jsx_attribute "=" @punctuation.jsx.delimiter) +(jsx_text) @text.jsx diff --git a/crates/languages/src/typescript/highlights.scm b/crates/languages/src/typescript/highlights.scm index 091ddfed9d02e9..1a87a4b07723ad 100644 --- a/crates/languages/src/typescript/highlights.scm +++ b/crates/languages/src/typescript/highlights.scm @@ -31,8 +31,8 @@ (identifier) (shorthand_property_identifier) (shorthand_property_identifier_pattern) - ] @constant - (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) + ] @constant.variable + (#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$")) ; Properties @@ -110,6 +110,7 @@ (escape_sequence) @string.escape (regex) @string.regex +(regex_flags) @keyword.regex (number) @number ; Tokens @@ -199,6 +200,8 @@ "<" @punctuation.bracket ">" @punctuation.bracket) +(decorator "@" @punctuation.special) + ; Keywords [ From 0af3279776377a80d870eaf6e4117d18d983c5f2 Mon Sep 17 00:00:00 2001 From: chbk Date: Fri, 21 Feb 2025 16:29:57 +0100 Subject: [PATCH 2/4] Reorder scopes --- crates/languages/src/javascript/highlights.scm | 8 ++++---- crates/languages/src/tsx/highlights.scm | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/languages/src/javascript/highlights.scm b/crates/languages/src/javascript/highlights.scm index b1c144fec037fc..55c602a11179a1 100644 --- a/crates/languages/src/javascript/highlights.scm +++ b/crates/languages/src/javascript/highlights.scm @@ -237,8 +237,8 @@ (jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) (jsx_attribute (property_identifier) @attribute.jsx) -(jsx_opening_element (["<" ">"]) @punctuation.jsx.bracket) -(jsx_closing_element ([""]) @punctuation.jsx.bracket) -(jsx_self_closing_element (["<" "/>"]) @punctuation.jsx.bracket) -(jsx_attribute "=" @punctuation.jsx.delimiter) +(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx) +(jsx_closing_element ([""]) @punctuation.bracket.jsx) +(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx) +(jsx_attribute "=" @punctuation.delimiter.jsx) (jsx_text) @text.jsx diff --git a/crates/languages/src/tsx/highlights.scm b/crates/languages/src/tsx/highlights.scm index c95ecf2a130320..e3de14ce9ed1d7 100644 --- a/crates/languages/src/tsx/highlights.scm +++ b/crates/languages/src/tsx/highlights.scm @@ -248,8 +248,8 @@ (jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$")) (jsx_attribute (property_identifier) @attribute.jsx) -(jsx_opening_element (["<" ">"]) @punctuation.jsx.bracket) -(jsx_closing_element ([""]) @punctuation.jsx.bracket) -(jsx_self_closing_element (["<" "/>"]) @punctuation.jsx.bracket) -(jsx_attribute "=" @punctuation.jsx.delimiter) +(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx) +(jsx_closing_element ([""]) @punctuation.bracket.jsx) +(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx) +(jsx_attribute "=" @punctuation.delimiter.jsx) (jsx_text) @text.jsx From b3bccd34fc57e18ce66763e7bd95030d7bce0105 Mon Sep 17 00:00:00 2001 From: chbk Date: Fri, 21 Feb 2025 18:33:27 +0100 Subject: [PATCH 3/4] Remove `@constant.variable` --- crates/languages/src/javascript/highlights.scm | 4 ++-- crates/languages/src/tsx/highlights.scm | 4 ++-- crates/languages/src/typescript/highlights.scm | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/languages/src/javascript/highlights.scm b/crates/languages/src/javascript/highlights.scm index 55c602a11179a1..9986390b4e4c71 100644 --- a/crates/languages/src/javascript/highlights.scm +++ b/crates/languages/src/javascript/highlights.scm @@ -54,8 +54,8 @@ (identifier) (shorthand_property_identifier) (shorthand_property_identifier_pattern) - ] @constant.variable - (#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$")) + ] @constant + (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Literals diff --git a/crates/languages/src/tsx/highlights.scm b/crates/languages/src/tsx/highlights.scm index e3de14ce9ed1d7..d21f0c2147b33f 100644 --- a/crates/languages/src/tsx/highlights.scm +++ b/crates/languages/src/tsx/highlights.scm @@ -57,8 +57,8 @@ (identifier) (shorthand_property_identifier) (shorthand_property_identifier_pattern) - ] @constant.variable - (#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$")) + ] @constant + (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Literals diff --git a/crates/languages/src/typescript/highlights.scm b/crates/languages/src/typescript/highlights.scm index 1a87a4b07723ad..bccb22fa9c743e 100644 --- a/crates/languages/src/typescript/highlights.scm +++ b/crates/languages/src/typescript/highlights.scm @@ -31,8 +31,8 @@ (identifier) (shorthand_property_identifier) (shorthand_property_identifier_pattern) - ] @constant.variable - (#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$")) + ] @constant + (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Properties From 368c8af4753d75ac121f64ee086e88ce1b042f04 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 21 Feb 2025 16:38:53 -0500 Subject: [PATCH 4/4] Revert breaking changes to JSDoc --- crates/languages/src/jsdoc/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/languages/src/jsdoc/highlights.scm b/crates/languages/src/jsdoc/highlights.scm index 7eee7b698b5941..4b4266c9fd1c97 100644 --- a/crates/languages/src/jsdoc/highlights.scm +++ b/crates/languages/src/jsdoc/highlights.scm @@ -1,2 +1,2 @@ -(tag_name) @comment.doc.keyword -(type) @comment.doc.type +(tag_name) @keyword +(type) @type