Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elm: Improve syntax highlighting and bracket handling #22293

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extensions/elm/languages/elm/brackets.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
("(" @open ")" @close)
("[" @open "]" @close)
("{" @open "}" @close)
2 changes: 1 addition & 1 deletion extensions/elm/languages/elm/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ brackets = [
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
]
tab_size = 2
tab_size = 4
246 changes: 192 additions & 54 deletions extensions/elm/languages/elm/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,72 +1,210 @@
[
"if"
"then"
"else"
"let"
"in"
(case)
(of)
(backslash)
(as)
(port)
(exposing)
(alias)
(import)
(module)
(type)
(arrow)
] @keyword
(line_comment)
(block_comment)
] @comment

; Keywords
;---------
[
(eq)
(operator_identifier)
(colon)
] @operator

(type_annotation(lower_case_identifier) @function)
(port_annotation(lower_case_identifier) @function)
(function_declaration_left(lower_case_identifier) @function.definition)
(module)
(import)
(exposing)
(port)
(type)
(alias)
(infix)
(as)
(case)
(of)
"if"
"then"
"else"
"let"
"in"
] @keyword

(function_call_expr
target: (value_expr
name: (value_qid (lower_case_identifier) @function)))

(exposed_value(lower_case_identifier) @function)
(exposed_type(upper_case_identifier) @type)
; Punctuation
;------------
(double_dot) @punctuation.special

(field_access_expr(value_expr(value_qid)) @identifier)
(lower_pattern) @variable
(record_base_identifier) @identifier
[
","
"|"
(dot)
] @punctuation.delimiter

[
"("
")"
"("
")"
"{"
"}"
"["
"]"
] @punctuation.bracket

[
"|"
","
] @punctuation.delimiter
; Variables
;----------
(value_qid
(lower_case_identifier) @variable)

(value_declaration
(function_declaration_left
(lower_case_identifier) @variable))

(type_annotation
(lower_case_identifier) @variable)

(port_annotation
(lower_case_identifier) @variable)

(number_constant_expr) @constant
(record_base_identifier
(lower_case_identifier) @variable)

(type_declaration(upper_case_identifier) @type)
(type_ref) @type
(type_alias_declaration name: (upper_case_identifier) @type)
(lower_pattern
(lower_case_identifier) @variable)

(value_expr(upper_case_qid(upper_case_identifier)) @type)
(exposed_value
(lower_case_identifier) @variable)

(value_qid
((dot)
(lower_case_identifier) @variable))

(field_access_expr
((dot)
(lower_case_identifier) @variable))

(function_declaration_left
(lower_pattern
(lower_case_identifier) @variable))

; Functions
;----------
(value_declaration
functionDeclarationLeft: (function_declaration_left
(lower_case_identifier) @function
(pattern)))

(value_declaration
functionDeclarationLeft: (function_declaration_left
(lower_case_identifier) @function
pattern: (_)))

(value_declaration
functionDeclarationLeft: (function_declaration_left
(lower_case_identifier) @function)
body: (anonymous_function_expr))

(type_annotation
name: (lower_case_identifier) @function
typeExpression: (type_expression
(arrow)))

(port_annotation
name: (lower_case_identifier) @function
typeExpression: (type_expression
(arrow)))

(function_call_expr
target: (value_expr
(value_qid
(lower_case_identifier) @function)))

; Operators
;----------
[
(line_comment)
(block_comment)
] @comment
(operator_identifier)
(eq)
(colon)
(arrow)
(backslash)
"::"
] @operator

; Modules
;--------
(module_declaration
(upper_case_qid
(upper_case_identifier) @title))

(import_clause
(upper_case_qid
(upper_case_identifier) @title))

(as_clause
(upper_case_identifier) @title)

(value_expr
(value_qid
(upper_case_identifier) @title))

; Types
;------
(type_declaration
(upper_case_identifier) @type)

(type_ref
(upper_case_qid
(upper_case_identifier) @type))

(type_variable
(lower_case_identifier) @type)

(lower_type_name
(lower_case_identifier) @type)

(exposed_type
(upper_case_identifier) @type)

(type_alias_declaration
(upper_case_identifier) @type)

(string_escape) @string.escape
(field_type
name: (lower_case_identifier) @property)

(field
name: (lower_case_identifier) @property)

(type_declaration
(union_variant
(upper_case_identifier) @constructor))

(nullary_constructor_argument_pattern
(upper_case_qid
(upper_case_identifier) @constructor))

(union_pattern
(upper_case_qid
(upper_case_identifier) @constructor))

(value_expr
(upper_case_qid
(upper_case_identifier)) @constructor)

; Literals
;---------
(number_constant_expr
(number_literal) @number)

(upper_case_qid
((upper_case_identifier) @boolean
(#any-of? @boolean "True" "False")))

[
(open_quote)
(close_quote)
(regular_string_part)
(open_char)
(close_char)
(open_quote)
(close_quote)
(open_char)
(close_char)
] @string

(string_constant_expr
(string_escape) @string)

(string_constant_expr
(regular_string_part) @string)

(char_constant_expr
(string_escape) @string)

(char_constant_expr
(regular_string_part) @string)