Files
oak-gpui/crates/languages/src/tsx/highlights.scm
T
Alex Zeier 96415e2d19 languages: Separate control flow keywords for JS/TS/TSX (#39801)
Related to #9461, inspired by #39683

`await` and `yield` both seem somewhat debatable on whether they should
be considered the be control flow keywords.

For now I went with:
- `await`: no – The control flow effect of `await` is at a level does
not seem relevant for syntax highlighting.
- `yield`: yes – `yield` directly affects the output of a generator, and
is also included for consistency with Rust (#39683).
 
 Happy to change these either direction.

<img width="1151" height="730" alt="SCR-20251008-izus"
src="https://github.com/user-attachments/assets/533ea670-863a-4c5c-aaa5-4a9bfa0bf0dd"
/>

--- 

Release Notes:

- Improved granularity of keyword highlighting for JS/TS/TSX: Themes can
now specify `keyword.control` for control flow keywords like `if`,
`else`, `return`, etc.
2025-10-20 14:40:05 +02:00

266 lines
4.0 KiB
Scheme

; Variables
(identifier) @variable
; Properties
(property_identifier) @property
(shorthand_property_identifier) @property
(shorthand_property_identifier_pattern) @property
(private_property_identifier) @property
; Function and method calls
(call_expression
function: (identifier) @function)
(call_expression
function: (member_expression
property: [(property_identifier) (private_property_identifier)] @function.method))
; Function and method definitions
(function_expression
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
(method_definition
name: [(property_identifier) (private_property_identifier)] @function.method)
(method_definition
name: (property_identifier) @constructor
(#eq? @constructor "constructor"))
(pair
key: [(property_identifier) (private_property_identifier)] @function.method
value: [(function_expression) (arrow_function)])
(assignment_expression
left: (member_expression
property: [(property_identifier) (private_property_identifier)] @function.method)
right: [(function_expression) (arrow_function)])
(variable_declarator
name: (identifier) @function
value: [(function_expression) (arrow_function)])
(assignment_expression
left: (identifier) @function
right: [(function_expression) (arrow_function)])
; Special identifiers
((identifier) @type
(#match? @type "^[A-Z]"))
(type_identifier) @type
(predefined_type) @type.builtin
([
(identifier)
(shorthand_property_identifier)
(shorthand_property_identifier_pattern)
] @constant
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
; Literals
(this) @variable.special
(super) @variable.special
[
(null)
(undefined)
] @constant.builtin
[
(true)
(false)
] @boolean
(comment) @comment
[
(string)
(template_string)
(template_literal_type)
] @string
(escape_sequence) @string.escape
(regex) @string.regex
(regex_flags) @keyword.operator.regex
(number) @number
; Tokens
[
";"
"?."
"."
","
":"
"?"
] @punctuation.delimiter
[
"-"
"--"
"-="
"+"
"++"
"+="
"*"
"*="
"**"
"**="
"/"
"/="
"%"
"%="
"<"
"<="
"<<"
"<<="
"="
"=="
"==="
"!"
"!="
"!=="
"=>"
">"
">="
">>"
">>="
">>>"
">>>="
"~"
"^"
"&"
"|"
"^="
"&="
"|="
"&&"
"||"
"??"
"&&="
"||="
"??="
"..."
] @operator
(regex "/" @string.regex)
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(ternary_expression
[
"?"
":"
] @operator
)
[
"as"
"async"
"await"
"class"
"const"
"debugger"
"default"
"delete"
"export"
"extends"
"from"
"function"
"get"
"import"
"in"
"instanceof"
"is"
"let"
"new"
"of"
"satisfies"
"set"
"static"
"target"
"typeof"
"using"
"var"
"void"
"with"
] @keyword
[
"break"
"case"
"catch"
"continue"
"do"
"else"
"finally"
"for"
"if"
"return"
"switch"
"throw"
"try"
"while"
"yield"
] @keyword.control
(switch_default "default" @keyword.control)
(template_substitution
"${" @punctuation.special
"}" @punctuation.special) @embedded
(template_type
"${" @punctuation.special
"}" @punctuation.special) @embedded
(type_arguments
"<" @punctuation.bracket
">" @punctuation.bracket)
(decorator "@" @punctuation.special)
; Keywords
[ "abstract"
"declare"
"enum"
"export"
"implements"
"interface"
"keyof"
"module"
"namespace"
"private"
"protected"
"public"
"type"
"readonly"
"override"
] @keyword
; JSX elements
(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.bracket.jsx)
(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
(jsx_attribute "=" @punctuation.delimiter.jsx)
(jsx_text) @text.jsx