Fix Dart syntax highlighting issue (#8347)
Release Notes: * Improved Dart syntax highlighting ([#8151](https://github.com/zed-industries/zed/pull/8347#8151)) Before: <img width="1246" alt="Before" src="https://github.com/zed-industries/zed/assets/25414681/d9143fe8-c474-40bb-afbd-56fef16edab3"> After: <img width="1249" alt="After" src="https://github.com/zed-industries/zed/assets/25414681/4b103c35-fb24-4693-8b9e-3dd494036c9f"> (Shameless plug, since I build the theme) Theme: The Dark Side
This commit is contained in:
parent
c38f72d194
commit
c6028f6651
3 changed files with 190 additions and 117 deletions
|
@ -7,7 +7,9 @@ brackets = [
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
{ start = "[", end = "]", close = true, newline = true },
|
{ start = "[", end = "]", close = true, newline = true },
|
||||||
{ start = "(", end = ")", close = true, newline = true },
|
{ start = "(", end = ")", close = true, newline = true },
|
||||||
|
{ start = "<", end = ">", close = true, newline = false},
|
||||||
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
|
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
|
||||||
{ start = "'", end = "'", close = true, newline = false, not_in = ["string"] },
|
{ start = "'", end = "'", close = true, newline = false, not_in = ["string"] },
|
||||||
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
|
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
|
{ start = "`", end = "`", close = true, newline = false, not_in = ["string", "comment"] },
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,201 +2,256 @@
|
||||||
|
|
||||||
; Methods
|
; Methods
|
||||||
; --------------------
|
; --------------------
|
||||||
(function_type
|
|
||||||
name: (identifier) @function)
|
|
||||||
(super) @function
|
(super) @function
|
||||||
|
|
||||||
|
(function_expression_body (identifier) @type)
|
||||||
|
; ((identifier)(selector (argument_part)) @function)
|
||||||
|
|
||||||
|
(((identifier) @function (#match? @function "^_?[a-z]"))
|
||||||
|
. (selector . (argument_part))) @function
|
||||||
|
|
||||||
; Annotations
|
; Annotations
|
||||||
; --------------------
|
; --------------------
|
||||||
(annotation
|
(annotation
|
||||||
name: (identifier) @attribute)
|
name: (identifier) @attribute)
|
||||||
|
|
||||||
; Operators and Tokens
|
; Operators and Tokens
|
||||||
; --------------------
|
; --------------------
|
||||||
(template_substitution
|
(template_substitution
|
||||||
"$" @punctuation.special
|
"$" @punctuation.special
|
||||||
"{" @punctuation.special
|
"{" @punctuation.special
|
||||||
"}" @punctuation.special
|
"}" @punctuation.special) @none
|
||||||
) @none
|
|
||||||
|
|
||||||
(template_substitution
|
(template_substitution
|
||||||
"$" @punctuation.special
|
"$" @punctuation.special
|
||||||
(identifier_dollar_escaped) @variable
|
(identifier_dollar_escaped) @variable) @none
|
||||||
) @none
|
|
||||||
|
|
||||||
(escape_sequence) @string.escape
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
[
|
[
|
||||||
"@"
|
"@"
|
||||||
"=>"
|
"=>"
|
||||||
".."
|
".."
|
||||||
"??"
|
"??"
|
||||||
"=="
|
"=="
|
||||||
"?"
|
"?"
|
||||||
":"
|
":"
|
||||||
"&&"
|
"&&"
|
||||||
"%"
|
"%"
|
||||||
"<"
|
"<"
|
||||||
">"
|
">"
|
||||||
"="
|
"="
|
||||||
">="
|
">="
|
||||||
"<="
|
"<="
|
||||||
"||"
|
"||"
|
||||||
(increment_operator)
|
(multiplicative_operator)
|
||||||
(is_operator)
|
(increment_operator)
|
||||||
(prefix_operator)
|
(is_operator)
|
||||||
(equality_operator)
|
(prefix_operator)
|
||||||
(additive_operator)
|
(equality_operator)
|
||||||
] @operator
|
(additive_operator)
|
||||||
|
] @operator
|
||||||
|
|
||||||
[
|
[
|
||||||
"("
|
"("
|
||||||
")"
|
")"
|
||||||
"["
|
"["
|
||||||
"]"
|
"]"
|
||||||
"{"
|
"{"
|
||||||
"}"
|
"}"
|
||||||
"<"
|
] @punctuation.bracket
|
||||||
">"
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
; Delimiters
|
; Delimiters
|
||||||
; --------------------
|
; --------------------
|
||||||
[
|
[
|
||||||
";"
|
";"
|
||||||
"."
|
"."
|
||||||
","
|
","
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
; Types
|
; Types
|
||||||
; --------------------
|
; --------------------
|
||||||
(class_definition
|
(class_definition
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(constructor_signature
|
(constructor_signature
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(scoped_identifier
|
(scoped_identifier
|
||||||
scope: (identifier) @type)
|
scope: (identifier) @type)
|
||||||
(function_signature
|
(function_signature
|
||||||
name: (identifier) @function)
|
name: (identifier) @function.method)
|
||||||
|
|
||||||
(getter_signature
|
(getter_signature
|
||||||
(identifier) @function)
|
(identifier) @function.method)
|
||||||
|
|
||||||
(setter_signature
|
(setter_signature
|
||||||
name: (identifier) @function)
|
name: (identifier) @function.method)
|
||||||
(enum_declaration
|
(enum_declaration
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(enum_constant
|
(enum_constant
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(type_identifier) @type
|
|
||||||
(void_type) @type
|
(void_type) @type
|
||||||
|
|
||||||
((scoped_identifier
|
((scoped_identifier
|
||||||
scope: (identifier) @type
|
scope: (identifier) @type
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(#match? @type "^[a-zA-Z]"))
|
(#match? @type "^[a-zA-Z]"))
|
||||||
|
|
||||||
(type_identifier) @type
|
(type_identifier) @type
|
||||||
|
|
||||||
|
(type_alias
|
||||||
|
(type_identifier) @type.definition)
|
||||||
|
|
||||||
; Variables
|
; Variables
|
||||||
; --------------------
|
; --------------------
|
||||||
; var keyword
|
; var keyword
|
||||||
(inferred_type) @keyword
|
(inferred_type) @keyword
|
||||||
|
|
||||||
(const_builtin) @constant.builtin
|
|
||||||
(final_builtin) @constant.builtin
|
|
||||||
|
|
||||||
((identifier) @type
|
((identifier) @type
|
||||||
(#match? @type "^_?[A-Z]"))
|
(#match? @type "^_?[A-Z].*[a-z]"))
|
||||||
|
|
||||||
("Function" @type)
|
("Function" @type)
|
||||||
|
|
||||||
; properties
|
; properties
|
||||||
; TODO: add method/call_expression to grammar and
|
|
||||||
; distinguish method call from variable access
|
|
||||||
(unconditional_assignable_selector
|
(unconditional_assignable_selector
|
||||||
(identifier) @property)
|
(identifier) @property)
|
||||||
|
|
||||||
|
(conditional_assignable_selector
|
||||||
|
(identifier) @property)
|
||||||
|
|
||||||
; assignments
|
; assignments
|
||||||
(assignment_expression
|
(assignment_expression
|
||||||
left: (assignable_expression) @variable)
|
left: (assignable_expression) @variable)
|
||||||
|
|
||||||
(this) @variable.builtin
|
(this) @variable.builtin
|
||||||
|
|
||||||
|
; Parameters
|
||||||
|
; --------------------
|
||||||
|
(formal_parameter
|
||||||
|
name: (identifier) @variable.parameter)
|
||||||
|
|
||||||
|
(named_argument
|
||||||
|
(label
|
||||||
|
(identifier) @variable.parameter))
|
||||||
|
|
||||||
; Literals
|
; Literals
|
||||||
; --------------------
|
; --------------------
|
||||||
[
|
[
|
||||||
(hex_integer_literal)
|
(hex_integer_literal)
|
||||||
(decimal_integer_literal)
|
(decimal_integer_literal)
|
||||||
(decimal_floating_point_literal)
|
(decimal_floating_point_literal)
|
||||||
; TODO: inaccessible nodes
|
; TODO: inaccessible nodes
|
||||||
; (octal_integer_literal)
|
; (octal_integer_literal)
|
||||||
; (hex_floating_point_literal)
|
; (hex_floating_point_literal)
|
||||||
] @number
|
] @number
|
||||||
|
|
||||||
|
(symbol_literal) @string.special.symbol
|
||||||
|
|
||||||
(symbol_literal) @symbol
|
|
||||||
(string_literal) @string
|
(string_literal) @string
|
||||||
(true) @boolean
|
(true) @boolean
|
||||||
(false) @boolean
|
(false) @boolean
|
||||||
(null_literal) @constant.builtin
|
(null_literal) @constant.builtin
|
||||||
|
|
||||||
(documentation_comment) @comment
|
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
|
|
||||||
|
(documentation_comment) @comment.documentation
|
||||||
|
|
||||||
; Keywords
|
; Keywords
|
||||||
; --------------------
|
; --------------------
|
||||||
["import" "library" "export"] @keyword.include
|
[
|
||||||
|
"import"
|
||||||
|
"library"
|
||||||
|
"export"
|
||||||
|
"as"
|
||||||
|
"show"
|
||||||
|
"hide"
|
||||||
|
] @keyword.import
|
||||||
|
|
||||||
; Reserved words (cannot be used as identifiers)
|
; Reserved words (cannot be used as identifiers)
|
||||||
; TODO: "rethrow" @keyword
|
|
||||||
[
|
[
|
||||||
; "assert"
|
|
||||||
(case_builtin)
|
(case_builtin)
|
||||||
"extension"
|
"late"
|
||||||
"on"
|
"required"
|
||||||
"class"
|
"extension"
|
||||||
"enum"
|
"on"
|
||||||
"extends"
|
"class"
|
||||||
"in"
|
"enum"
|
||||||
"is"
|
"extends"
|
||||||
"new"
|
"in"
|
||||||
"return"
|
"is"
|
||||||
"super"
|
"new"
|
||||||
"with"
|
"super"
|
||||||
] @keyword
|
"with"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
; Built in identifiers:
|
; Built in identifiers:
|
||||||
; alone these are marked as keywords
|
; alone these are marked as keywords
|
||||||
[
|
[
|
||||||
"abstract"
|
"deferred"
|
||||||
"as"
|
"factory"
|
||||||
|
"get"
|
||||||
|
"implements"
|
||||||
|
"interface"
|
||||||
|
"library"
|
||||||
|
"operator"
|
||||||
|
"mixin"
|
||||||
|
"part"
|
||||||
|
"set"
|
||||||
|
"typedef"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
[
|
||||||
"async"
|
"async"
|
||||||
"async*"
|
"async*"
|
||||||
"yield"
|
|
||||||
"sync*"
|
"sync*"
|
||||||
"await"
|
"await"
|
||||||
|
"yield"
|
||||||
|
] @keyword.coroutine
|
||||||
|
|
||||||
|
[
|
||||||
|
(const_builtin)
|
||||||
|
(final_builtin)
|
||||||
|
"abstract"
|
||||||
"covariant"
|
"covariant"
|
||||||
"deferred"
|
"dynamic"
|
||||||
"dynamic"
|
"external"
|
||||||
"external"
|
"static"
|
||||||
"factory"
|
"final"
|
||||||
"get"
|
"base"
|
||||||
"implements"
|
"sealed"
|
||||||
"interface"
|
] @type.qualifier
|
||||||
"library"
|
|
||||||
"operator"
|
|
||||||
"mixin"
|
|
||||||
"part"
|
|
||||||
"set"
|
|
||||||
"show"
|
|
||||||
"static"
|
|
||||||
"typedef"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
; when used as an identifier:
|
; when used as an identifier:
|
||||||
((identifier) @variable.builtin
|
((identifier) @variable.builtin
|
||||||
(#vim-match? @variable.builtin "^(abstract|as|covariant|deferred|dynamic|export|external|factory|Function|get|implements|import|interface|library|operator|mixin|part|set|static|typedef)$"))
|
(#any-of? @variable.builtin
|
||||||
|
"abstract"
|
||||||
|
"as"
|
||||||
|
"covariant"
|
||||||
|
"deferred"
|
||||||
|
"dynamic"
|
||||||
|
"export"
|
||||||
|
"external"
|
||||||
|
"factory"
|
||||||
|
"Function"
|
||||||
|
"get"
|
||||||
|
"implements"
|
||||||
|
"import"
|
||||||
|
"interface"
|
||||||
|
"library"
|
||||||
|
"operator"
|
||||||
|
"mixin"
|
||||||
|
"part"
|
||||||
|
"set"
|
||||||
|
"static"
|
||||||
|
"typedef"))
|
||||||
|
|
||||||
["if" "else" "switch" "default"] @keyword
|
[
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"switch"
|
||||||
|
"default"
|
||||||
|
] @keyword.conditional
|
||||||
|
|
||||||
[
|
[
|
||||||
"try"
|
"try"
|
||||||
|
@ -204,6 +259,11 @@
|
||||||
"catch"
|
"catch"
|
||||||
"finally"
|
"finally"
|
||||||
(break_statement)
|
(break_statement)
|
||||||
] @keyword
|
] @keyword.exception
|
||||||
|
|
||||||
["do" "while" "continue" "for"] @keyword
|
[
|
||||||
|
"do"
|
||||||
|
"while"
|
||||||
|
"continue"
|
||||||
|
"for"
|
||||||
|
] @keyword.repeat
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
[
|
(class_definition
|
||||||
(if_statement)
|
"class" @context
|
||||||
(for_statement)
|
name: (_) @name) @item
|
||||||
] @indent
|
|
||||||
|
|
||||||
(_ "{" "}" @end) @indent
|
(function_signature
|
||||||
(_ "(" ")" @end) @indent
|
name: (_) @name) @item
|
||||||
|
|
||||||
|
(getter_signature
|
||||||
|
"get" @context
|
||||||
|
name: (_) @name) @item
|
||||||
|
|
||||||
|
(setter_signature
|
||||||
|
"set" @context
|
||||||
|
name: (_) @name) @item
|
||||||
|
|
||||||
|
(enum_declaration
|
||||||
|
"enum" @context
|
||||||
|
name: (_) @name) @item
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue