helix/runtime/queries/haskell/highlights.scm

439 lines
8.2 KiB
Scheme
Raw Normal View History

2025-05-17 20:42:52 +08:00
;----------------------------------------------------------------------------
; Parameters and variables
; NOTE: These are at the top, so that they have low priority,
; and don't override destructured parameters
(variable) @variable
(pattern/wildcard) @variable
(decl/function
patterns: (patterns
(_) @variable.parameter))
(expression/lambda
(_)+ @variable.parameter
"->")
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
(decl/function
(infix
(pattern) @variable.parameter))
; ----------------------------------------------------------------------------
; Literals and comments
(integer) @constant.numeric.integer
2025-05-17 20:42:52 +08:00
(negation) @constant.numeric
(expression/literal
(float)) @constant.numeric.float
(char) @constant.character
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
(string) @string
2025-05-17 20:42:52 +08:00
(unit) @string.special.symbol ; unit, as in ()
2022-01-06 01:53:37 +08:00
(comment) @comment
2025-05-17 20:42:52 +08:00
((haddock) @comment.documentation)
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
; ----------------------------------------------------------------------------
; Punctuation
2021-09-06 13:33:02 +08:00
[
"("
")"
2022-01-06 01:53:37 +08:00
"{"
"}"
"["
"]"
2021-09-06 13:33:02 +08:00
] @punctuation.bracket
2022-01-06 01:53:37 +08:00
[
2025-05-17 20:42:52 +08:00
","
2022-01-06 01:53:37 +08:00
";"
] @punctuation.delimiter
2025-05-17 20:42:52 +08:00
; ----------------------------------------------------------------------------
; Keywords, operators, includes
[
"forall"
2025-05-17 20:42:52 +08:00
; "∀" ; utf-8 is not cross-platform safe
] @keyword.repeat
2025-05-17 20:42:52 +08:00
(pragma) @keyword.directive
2022-01-06 01:53:37 +08:00
[
"if"
"then"
"else"
"case"
"of"
2025-05-17 20:42:52 +08:00
] @keyword.conditional
2022-01-06 01:53:37 +08:00
[
"import"
"qualified"
"module"
2025-05-17 20:42:52 +08:00
] @keyword.import
2022-01-06 01:53:37 +08:00
[
(operator)
(constructor_operator)
(all_names)
(wildcard)
2025-05-17 20:42:52 +08:00
"."
".."
2022-01-06 01:53:37 +08:00
"="
"|"
"::"
"=>"
"->"
"<-"
"\\"
"`"
"@"
] @operator
2025-05-17 20:42:52 +08:00
; TODO broken, also huh?
; ((qualified_module
; (module) @constructor)
; .
; (module))
(module
(module_id) @namespace)
2022-01-06 01:53:37 +08:00
[
2025-05-17 20:42:52 +08:00
"where"
2022-01-06 01:53:37 +08:00
"let"
"in"
"class"
"instance"
2025-05-17 20:42:52 +08:00
"pattern"
2022-01-06 01:53:37 +08:00
"data"
"newtype"
"family"
"type"
"as"
"hiding"
"deriving"
"via"
"stock"
"anyclass"
"do"
"mdo"
"rec"
"infix"
"infixl"
"infixr"
2022-01-06 01:53:37 +08:00
] @keyword
2025-05-17 20:42:52 +08:00
; ----------------------------------------------------------------------------
; Functions and variables
(decl
[
name: (variable) @function
names: (binding_list (variable) @function)
])
(decl/bind
name: (variable) @variable)
; Consider signatures (and accompanying functions)
; with only one value on the rhs as variables
(decl/signature
name: (variable) @variable
type: (type))
((decl/signature
name: (variable) @variable.name
type: (type))
.
(decl
name: (variable) @variable)
match: (_)
(#eq? @variable.name @variable))
; but consider a type that involves 'IO' a decl/function
(decl/signature
name: (variable) @function
type: (type/apply
constructor: (name) @type)
(#eq? @type "IO"))
((decl/signature
name: (variable) @function.name
type: (type/apply
constructor: (name) @type)
(#eq? @type "IO"))
.
(decl
name: (variable) @function)
match: (_)
(#eq? @function.name @function))
((decl/signature) @function
.
(decl/function
name: (variable) @function))
(decl/bind
name: (variable) @function
(match
expression: (expression/lambda)))
; view patterns
(view_pattern
[
(expression/variable) @function.call
(expression/qualified
(variable) @function.call)
])
; consider infix functions as operators
(infix_id
[
(variable) @operator
(qualified
(variable) @operator)
])
; decl/function calls with an infix operator
; e.g. func <$> a <*> b
(infix
[
(variable) @function.call
(qualified
((module) @namespace
(variable) @function.call))
]
.
(operator))
; infix operators applied to variables
((expression/variable) @variable
.
(operator))
((operator)
.
[
(expression/variable) @variable
(expression/qualified
(variable) @variable)
])
; decl/function calls with infix operators
([
(expression/variable) @function.call
(expression/qualified
(variable) @function.call)
]
.
(operator) @operator
(#any-of? @operator "$" "<$>" ">>=" "=<<"))
; right hand side of infix operator
((infix
[
(operator)
(infix_id (variable))
] ; infix or `func`
.
[
(variable) @function.call
(qualified
(variable) @function.call)
])
.
(operator) @operator
(#any-of? @operator "$" "<$>" "=<<"))
; decl/function composition, arrows, monadic composition (lhs)
(
[
(expression/variable) @function
(expression/qualified
(variable) @function)
]
.
(operator) @operator
(#any-of? @operator "." ">>>" "***" ">=>" "<=<"))
; right hand side of infix operator
((infix
[
(operator)
(infix_id (variable))
] ; infix or `func`
.
[
(variable) @function
(qualified
(variable) @function)
])
.
(operator) @operator
(#any-of? @operator "." ">>>" "***" ">=>" "<=<"))
; function composition, arrows, monadic composition (rhs)
((operator) @operator
.
[
(expression/variable) @function
(expression/qualified
(variable) @function)
]
(#any-of? @operator "." ">>>" "***" ">=>" "<=<"))
; function defined in terms of a function composition
(decl/function
name: (variable) @function
(match
expression: (infix
operator: (operator) @operator
(#any-of? @operator "." ">>>" "***" ">=>" "<=<"))))
(apply
[
(expression/variable) @function.call
(expression/qualified
(variable) @function.call)
])
; function compositions, in parentheses, applied
; lhs
(apply
.
(expression/parens
(infix
[
(variable) @function.call
(qualified
(variable) @function.call)
]
.
(operator))))
; rhs
(apply
.
(expression/parens
(infix
(operator)
.
[
(variable) @function.call
(qualified
(variable) @function.call)
])))
; variables being passed to a function call
(apply
(_)
.
[
(expression/variable) @variable
(expression/qualified
(variable) @variable)
])
; main is always a function
; (this prevents `main = undefined` from being highlighted as a variable)
(decl/bind
name: (variable) @function
(#eq? @function "main"))
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
; scoped function types (func :: a -> b)
(signature
pattern: (pattern/variable) @function
type: (quantified_type))
2025-05-17 20:42:52 +08:00
; signatures that have a function type
; + binds that follow them
(decl/signature
name: (variable) @function
2025-05-17 20:42:52 +08:00
type: (quantified_type))
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
((decl/signature
name: (variable) @function.name
type: (quantified_type))
.
(decl/bind
(variable) @function)
(#eq? @function @function.name))
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
; ----------------------------------------------------------------------------
; Types
(name) @type
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
(type/star) @type
2022-01-06 01:53:37 +08:00
2025-05-17 20:42:52 +08:00
; (variable) @type
2022-01-06 01:53:37 +08:00
(constructor) @constructor
; True or False
2025-05-17 20:42:52 +08:00
((constructor) @constant.builtin.boolean
(#any-of? @constant.builtin.boolean "True" "False"))
; otherwise (= True)
((variable) @constant.builtin.boolean
(#eq? @constant.builtin.boolean "otherwise"))
; ----------------------------------------------------------------------------
; Quasi-quotes
(quoter) @function.call
(quasiquote
[
(quoter) @_name
(_
(variable) @_name)
]
(#eq? @_name "qq")
(quasiquote_body) @string)
(quasiquote
(_
(variable) @_name)
(#eq? @_name "qq")
(quasiquote_body) @string)
; namespaced quasi-quoter
(quasiquote
(_
(module) @namespace
.
(variable) @function.call))
; Highlighting of quasiquote_body for other languages is handled by injections.scm
; ----------------------------------------------------------------------------
; Exceptions/error handling
((variable) @keyword.exception
(#any-of? @keyword.exception
"error" "undefined" "try" "tryJust" "tryAny" "catch" "catches" "catchJust" "handle" "handleJust"
"throw" "throwIO" "throwTo" "throwError" "ioError" "mask" "mask_" "uninterruptibleMask"
"uninterruptibleMask_" "bracket" "bracket_" "bracketOnErrorSource" "finally" "fail"
"onException" "expectationFailure"))
; ----------------------------------------------------------------------------
; Debugging
((variable) @keyword.debug
(#any-of? @keyword.debug
"trace" "traceId" "traceShow" "traceShowId" "traceWith" "traceShowWith" "traceStack" "traceIO"
"traceM" "traceShowM" "traceEvent" "traceEventWith" "traceEventIO" "flushEventLog" "traceMarker"
"traceMarkerIO"))
; ----------------------------------------------------------------------------
; Fields
(field_name
(variable) @variable.member)
(import_name
(name)
.
(children
(variable) @variable.member))