mirror of https://github.com/helix-editor/helix
Julia queries: major refactoring of `highlights.scm`, add regex injections, locals
parent
77f11bf272
commit
f5c00b9bc9
|
@ -1,112 +1,142 @@
|
||||||
|
; ----------
|
||||||
|
; Primitives
|
||||||
|
; ----------
|
||||||
|
|
||||||
(string_literal) @string
|
[
|
||||||
|
(line_comment)
|
||||||
|
(block_comment)
|
||||||
|
] @comment
|
||||||
|
|
||||||
(prefixed_string_literal
|
(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|missing|Inf|NaN)$"))
|
||||||
prefix: (identifier) @constant.builtin)
|
(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true"))
|
||||||
|
(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false"))
|
||||||
(macro_identifier) @function.macro
|
|
||||||
(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight
|
|
||||||
(macro_definition
|
|
||||||
name: (identifier) @function.macro
|
|
||||||
["macro" "end" @keyword])
|
|
||||||
|
|
||||||
(field_expression
|
|
||||||
(identifier)
|
|
||||||
(identifier) @variable.other.member .)
|
|
||||||
|
|
||||||
(function_definition
|
|
||||||
name: (identifier) @function)
|
|
||||||
(call_expression
|
|
||||||
(identifier) @function)
|
|
||||||
(call_expression
|
|
||||||
(field_expression (identifier) @function.method .))
|
|
||||||
(broadcast_call_expression
|
|
||||||
(identifier) @function)
|
|
||||||
(broadcast_call_expression
|
|
||||||
(field_expression (identifier) @function.method .))
|
|
||||||
(parameter_list
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
(parameter_list
|
|
||||||
(optional_parameter .
|
|
||||||
(identifier) @variable.parameter))
|
|
||||||
(typed_parameter
|
|
||||||
(identifier) @variable.parameter
|
|
||||||
(identifier) @type)
|
|
||||||
(type_parameter_list
|
|
||||||
(identifier) @type)
|
|
||||||
(typed_parameter
|
|
||||||
(identifier) @variable.parameter
|
|
||||||
(parameterized_identifier) @type)
|
|
||||||
(function_expression
|
|
||||||
. (identifier) @variable.parameter)
|
|
||||||
(spread_parameter) @variable.parameter
|
|
||||||
(spread_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
(named_argument
|
|
||||||
. (identifier) @variable.parameter)
|
|
||||||
(argument_list
|
|
||||||
(typed_expression
|
|
||||||
(identifier) @variable.parameter
|
|
||||||
(identifier) @type))
|
|
||||||
(argument_list
|
|
||||||
(typed_expression
|
|
||||||
(identifier) @variable.parameter
|
|
||||||
(parameterized_identifier) @type))
|
|
||||||
|
|
||||||
;; Symbol expressions (:my-wanna-be-lisp-keyword)
|
|
||||||
(quote_expression
|
|
||||||
(identifier)) @string.special.symbol
|
|
||||||
|
|
||||||
;; Parsing error! foo (::Type) get's parsed as two quote expressions
|
|
||||||
(argument_list
|
|
||||||
(quote_expression
|
|
||||||
(quote_expression
|
|
||||||
(identifier) @type)))
|
|
||||||
|
|
||||||
(type_argument_list
|
|
||||||
(identifier) @type)
|
|
||||||
(parameterized_identifier (_)) @type
|
|
||||||
(argument_list
|
|
||||||
(typed_expression . (identifier) @variable.parameter))
|
|
||||||
|
|
||||||
(typed_expression
|
|
||||||
(identifier) @type .)
|
|
||||||
(typed_expression
|
|
||||||
(parameterized_identifier) @type .)
|
|
||||||
|
|
||||||
(struct_definition
|
|
||||||
name: (identifier) @type)
|
|
||||||
|
|
||||||
(integer_literal) @constant.numeric.integer
|
(integer_literal) @constant.numeric.integer
|
||||||
(float_literal) @constant.numeric.float
|
(float_literal) @constant.numeric.float
|
||||||
|
|
||||||
(range_expression
|
(character_literal) @constant.character
|
||||||
(identifier) @constant.numeric.integer
|
(escape_sequence) @constant.character.escape
|
||||||
(eq? @constant.numeric.integer "end"))
|
|
||||||
(range_expression
|
|
||||||
(_
|
|
||||||
(identifier) @constant.numeric.integer
|
|
||||||
(eq? @constant.numeric.integer "end")))
|
|
||||||
(coefficient_expression
|
|
||||||
[
|
|
||||||
(integer_literal)
|
|
||||||
(float_literal)
|
|
||||||
]
|
|
||||||
(identifier) @constant.builtin)
|
|
||||||
|
|
||||||
;; TODO: operators.
|
(string_literal) @string
|
||||||
;; Those are a bit difficult to implement since the respective nodes are hidden right now (_power_operator)
|
|
||||||
;; and heavily use Unicode chars (support for those are bad in vim/lua regexes)
|
|
||||||
;[;
|
|
||||||
;(power_operator);
|
|
||||||
;(times_operator);
|
|
||||||
;(plus_operator);
|
|
||||||
;(arrow_operator);
|
|
||||||
;(comparison_operator);
|
|
||||||
;(assign_operator);
|
|
||||||
;] @operator ;
|
|
||||||
|
|
||||||
"end" @keyword
|
(prefixed_string_literal
|
||||||
|
prefix: (identifier) @function.macro) @string
|
||||||
|
|
||||||
|
(quote_expression
|
||||||
|
(identifier) @string.special.symbol)
|
||||||
|
|
||||||
|
; -------------------
|
||||||
|
; Modules and Imports
|
||||||
|
; -------------------
|
||||||
|
|
||||||
|
(module_definition
|
||||||
|
name: (identifier) @namespace)
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(identifier) @namespace)
|
||||||
|
|
||||||
|
(selected_import
|
||||||
|
. (identifier) @namespace)
|
||||||
|
|
||||||
|
(scoped_identifier
|
||||||
|
(identifier) @namespace)
|
||||||
|
|
||||||
|
; -----
|
||||||
|
; Types
|
||||||
|
; -----
|
||||||
|
|
||||||
|
(abstract_definition
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(primitive_definition
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(struct_definition
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(struct_definition
|
||||||
|
. (_)
|
||||||
|
(identifier) @variable.other.member)
|
||||||
|
|
||||||
|
(struct_definition
|
||||||
|
. (_)
|
||||||
|
(typed_expression
|
||||||
|
. (identifier) @variable.other.member))
|
||||||
|
|
||||||
|
(type_parameter_list
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(constrained_parameter
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(subtype_clause
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(typed_expression
|
||||||
|
(identifier) @type . )
|
||||||
|
|
||||||
|
(parameterized_identifier
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(type_argument_list
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
; -------------------
|
||||||
|
; Function definition
|
||||||
|
; -------------------
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (identifier) @function)
|
||||||
|
|
||||||
|
(parameter_list
|
||||||
|
(identifier) @variable.parameter)
|
||||||
|
|
||||||
|
(typed_parameter
|
||||||
|
(identifier) @variable.parameter
|
||||||
|
(identifier)? @type)
|
||||||
|
|
||||||
|
(optional_parameter
|
||||||
|
. (identifier) @variable.parameter)
|
||||||
|
|
||||||
|
(spread_parameter
|
||||||
|
(identifier) @variable.parameter)
|
||||||
|
|
||||||
|
(function_expression
|
||||||
|
. (identifier) @variable.parameter)
|
||||||
|
|
||||||
|
; ---------------
|
||||||
|
; Functions calls
|
||||||
|
; ---------------
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
(identifier) @function)
|
||||||
|
|
||||||
|
(broadcast_call_expression
|
||||||
|
(identifier) @function)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
(field_expression (identifier) @function .))
|
||||||
|
|
||||||
|
(broadcast_call_expression
|
||||||
|
(field_expression (identifier) @function .))
|
||||||
|
|
||||||
|
; ------
|
||||||
|
; Macros
|
||||||
|
; ------
|
||||||
|
|
||||||
|
(macro_definition
|
||||||
|
name: (identifier) @function.macro)
|
||||||
|
|
||||||
|
(macro_identifier
|
||||||
|
"@" @function.macro
|
||||||
|
(identifier) @function.macro)
|
||||||
|
|
||||||
|
; --------
|
||||||
|
; Keywords
|
||||||
|
; --------
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
["function" "end"] @keyword.function)
|
||||||
|
|
||||||
(if_statement
|
(if_statement
|
||||||
["if" "end"] @keyword.control.conditional)
|
["if" "end"] @keyword.control.conditional)
|
||||||
|
@ -117,36 +147,6 @@
|
||||||
(ternary_expression
|
(ternary_expression
|
||||||
["?" ":"] @keyword.control.conditional)
|
["?" ":"] @keyword.control.conditional)
|
||||||
|
|
||||||
(function_definition ["function" "end"] @keyword.function)
|
|
||||||
|
|
||||||
[
|
|
||||||
(line_comment)
|
|
||||||
(block_comment)
|
|
||||||
] @comment
|
|
||||||
|
|
||||||
[
|
|
||||||
"const"
|
|
||||||
"return"
|
|
||||||
"macro"
|
|
||||||
"struct"
|
|
||||||
"primitive"
|
|
||||||
"type"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
((identifier) @keyword (match? @keyword "global|local"))
|
|
||||||
|
|
||||||
(compound_expression
|
|
||||||
["begin" "end"] @keyword)
|
|
||||||
(try_statement
|
|
||||||
["try" "end" ] @keyword.control.exception)
|
|
||||||
(finally_clause
|
|
||||||
"finally" @keyword.control.exception)
|
|
||||||
(catch_clause
|
|
||||||
"catch" @keyword.control.exception)
|
|
||||||
(quote_statement
|
|
||||||
["quote" "end"] @keyword)
|
|
||||||
(let_statement
|
|
||||||
["let" "end"] @keyword)
|
|
||||||
(for_statement
|
(for_statement
|
||||||
["for" "end"] @keyword.control.repeat)
|
["for" "end"] @keyword.control.repeat)
|
||||||
(while_statement
|
(while_statement
|
||||||
|
@ -157,33 +157,90 @@
|
||||||
"in" @keyword.control.repeat)
|
"in" @keyword.control.repeat)
|
||||||
(for_clause
|
(for_clause
|
||||||
"for" @keyword.control.repeat)
|
"for" @keyword.control.repeat)
|
||||||
(do_clause
|
|
||||||
["do" "end"] @keyword)
|
|
||||||
|
|
||||||
(export_statement
|
(try_statement
|
||||||
["export"] @keyword.control.import)
|
["try" "end" ] @keyword.control.exception)
|
||||||
|
(finally_clause
|
||||||
|
"finally" @keyword.control.exception)
|
||||||
|
(catch_clause
|
||||||
|
"catch" @keyword.control.exception)
|
||||||
|
|
||||||
[
|
[
|
||||||
"using"
|
"export"
|
||||||
"module"
|
|
||||||
"import"
|
"import"
|
||||||
|
"using"
|
||||||
] @keyword.control.import
|
] @keyword.control.import
|
||||||
|
|
||||||
((identifier) @keyword.control.import (#eq? @keyword.control.import "baremodule"))
|
[
|
||||||
|
"abstract"
|
||||||
|
"begin"
|
||||||
|
"const"
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
"let"
|
||||||
|
"macro"
|
||||||
|
"module"
|
||||||
|
"mutable"
|
||||||
|
"primitive"
|
||||||
|
"quote"
|
||||||
|
"return"
|
||||||
|
"struct"
|
||||||
|
"type"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
(((identifier) @constant.builtin) (match? @constant.builtin "^(nothing|Inf|NaN)$"))
|
; TODO: fix this
|
||||||
(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "true"))
|
((identifier) @keyword (match? @keyword "global|local"))
|
||||||
(((identifier) @constant.builtin.boolean) (#eq? @constant.builtin.boolean "false"))
|
|
||||||
|
|
||||||
|
; ---------
|
||||||
|
; Operators
|
||||||
|
; ---------
|
||||||
|
|
||||||
["::" ":" "." "," "..."] @punctuation.delimiter
|
[
|
||||||
["[" "]" "(" ")" "{" "}"] @punctuation.bracket
|
(operator)
|
||||||
|
"::"
|
||||||
|
"<:"
|
||||||
|
":"
|
||||||
|
"=>"
|
||||||
|
"..."
|
||||||
|
"$"
|
||||||
|
] @operator
|
||||||
|
|
||||||
["="] @operator
|
; ------------
|
||||||
|
; Punctuations
|
||||||
|
; ------------
|
||||||
|
|
||||||
|
[
|
||||||
|
"."
|
||||||
|
","
|
||||||
|
";"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
; ---------------------
|
||||||
|
; Remaining identifiers
|
||||||
|
; ---------------------
|
||||||
|
|
||||||
|
; could also be namespace but this should cover the majority
|
||||||
|
(field_expression
|
||||||
|
. (_)
|
||||||
|
(identifier) @variable.other.member)
|
||||||
|
|
||||||
|
(const_statement
|
||||||
|
(variable_declaration
|
||||||
|
. (identifier) @constant))
|
||||||
|
|
||||||
|
((identifier) @type
|
||||||
|
(match? @type "([A-Z][a-z0-9]+)+$"))
|
||||||
|
|
||||||
|
((identifier) @constant
|
||||||
|
(match? @constant "^[A-Z][A-Z0-9_]+$"))
|
||||||
|
|
||||||
(identifier) @variable
|
(identifier) @variable
|
||||||
;; In case you want type highlighting based on Julia naming conventions (this might collide with mathematical notation)
|
|
||||||
;((identifier) @type ; exception: mark `A_foo` sort of identifiers as variables
|
|
||||||
;(match? @type "^[A-Z][^_]"))
|
|
||||||
((identifier) @constant
|
|
||||||
(match? @constant "^[A-Z][A-Z_]{2}[A-Z_]*$"))
|
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
; ((string_literal) @injection.content
|
(
|
||||||
; (#set! injection.language "markdown"))
|
(string_literal) @injection.content
|
||||||
|
(#set! injection.language "markdown"))
|
||||||
|
|
||||||
; ((line_comment) @injection.content
|
(
|
||||||
; (#set! injection.language "comment"))
|
[
|
||||||
|
(line_comment)
|
||||||
|
(block_comment)
|
||||||
|
] @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
||||||
|
|
||||||
; ((block_comment) @injection.content
|
(
|
||||||
; (#set! injection.language "comment"))
|
(prefixed_string_literal
|
||||||
|
prefix: (identifier) @function.macro) @injection.content
|
||||||
|
(#eq? @function.macro "re")
|
||||||
|
(#set! injection.language "regex"))
|
||||||
|
|
|
@ -1,59 +1,43 @@
|
||||||
|
; -----------
|
||||||
|
; Definitions
|
||||||
|
; -----------
|
||||||
|
|
||||||
|
; Imports
|
||||||
(import_statement
|
(import_statement
|
||||||
(identifier) @definition.import)
|
(identifier) @local.definition)
|
||||||
(variable_declaration
|
|
||||||
(identifier) @local.definition)
|
; Constants
|
||||||
(variable_declaration
|
(const_statement
|
||||||
(tuple_expression
|
(variable_declaration
|
||||||
(identifier) @local.definition))
|
. (identifier) @local.definition))
|
||||||
(for_binding
|
|
||||||
(identifier) @local.definition)
|
|
||||||
(for_binding
|
|
||||||
(tuple_expression
|
|
||||||
(identifier) @local.definition))
|
|
||||||
|
|
||||||
(assignment_expression
|
|
||||||
(tuple_expression
|
|
||||||
(identifier) @local.definition))
|
|
||||||
(assignment_expression
|
|
||||||
(bare_tuple_expression
|
|
||||||
(identifier) @local.definition))
|
|
||||||
(assignment_expression
|
|
||||||
(identifier) @local.definition)
|
|
||||||
|
|
||||||
(type_parameter_list
|
|
||||||
(identifier) @definition.type)
|
|
||||||
(type_argument_list
|
|
||||||
(identifier) @definition.type)
|
|
||||||
(struct_definition
|
|
||||||
name: (identifier) @definition.type)
|
|
||||||
|
|
||||||
|
; Parameters
|
||||||
(parameter_list
|
(parameter_list
|
||||||
(identifier) @definition.parameter)
|
(identifier) @local.definition)
|
||||||
|
|
||||||
(typed_parameter
|
(typed_parameter
|
||||||
(identifier) @definition.parameter
|
. (identifier) @local.definition)
|
||||||
(identifier))
|
|
||||||
(function_expression
|
(optional_parameter .
|
||||||
. (identifier) @definition.parameter)
|
(identifier) @local.definition)
|
||||||
(argument_list
|
|
||||||
(typed_expression
|
|
||||||
(identifier) @definition.parameter
|
|
||||||
(identifier)))
|
|
||||||
(spread_parameter
|
(spread_parameter
|
||||||
(identifier) @definition.parameter)
|
(identifier) @local.definition)
|
||||||
|
|
||||||
(function_definition
|
(function_expression
|
||||||
name: (identifier) @definition.function) @local.scope
|
. (identifier) @local.definition)
|
||||||
(macro_definition
|
|
||||||
name: (identifier) @definition.macro) @local.scope
|
; ------
|
||||||
|
; Scopes
|
||||||
(identifier) @local.reference
|
; ------
|
||||||
|
|
||||||
[
|
[
|
||||||
(try_statement)
|
(function_definition)
|
||||||
(finally_clause)
|
(macro_definition)
|
||||||
(quote_statement)
|
|
||||||
(let_statement)
|
|
||||||
(compound_expression)
|
|
||||||
(for_statement)
|
|
||||||
] @local.scope
|
] @local.scope
|
||||||
|
|
||||||
|
; ----------
|
||||||
|
; References
|
||||||
|
; ----------
|
||||||
|
|
||||||
|
(identifier) @local.reference
|
||||||
|
|
Loading…
Reference in New Issue