nvim-treesitter/runtime/queries/luau/highlights.scm

306 lines
4.6 KiB
Scheme
Raw Permalink Normal View History

2023-04-27 04:25:19 -04:00
; Preproc
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
(hash_bang_line) @keyword.directive
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
; Keywords
2023-04-27 04:25:19 -04:00
"return" @keyword.return
"local" @keyword
"type" @keyword.type
2023-04-27 04:25:19 -04:00
"export" @keyword.import
2023-04-27 04:25:19 -04:00
(do_statement
2024-01-06 15:05:50 +09:00
[
"do"
"end"
] @keyword)
2023-04-27 04:25:19 -04:00
(while_statement
2024-01-06 15:05:50 +09:00
[
"while"
"do"
"end"
] @keyword.repeat)
2023-04-27 04:25:19 -04:00
(repeat_statement
2024-01-06 15:05:50 +09:00
[
"repeat"
"until"
] @keyword.repeat)
2023-04-27 04:25:19 -04:00
[
(break_statement)
(continue_statement)
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
] @keyword.repeat
2023-04-27 04:25:19 -04:00
(if_statement
2024-01-06 15:05:50 +09:00
[
"if"
"elseif"
"else"
"then"
"end"
] @keyword.conditional)
2023-04-27 04:25:19 -04:00
(if_expression
[
"if"
"then"
] @keyword.conditional)
2023-04-27 04:25:19 -04:00
(elseif_statement
2024-01-06 15:05:50 +09:00
[
"elseif"
"then"
"end"
] @keyword.conditional)
2023-04-27 04:25:19 -04:00
(elseif_clause
[
"elseif"
"then"
] @keyword.conditional)
2023-04-27 04:25:19 -04:00
(else_statement
2024-01-06 15:05:50 +09:00
[
"else"
"end"
] @keyword.conditional)
2023-04-27 04:25:19 -04:00
(else_clause
"else" @keyword.conditional)
2023-04-27 04:25:19 -04:00
(for_statement
2024-01-06 15:05:50 +09:00
[
"for"
"do"
"end"
] @keyword.repeat)
2023-04-27 04:25:19 -04:00
(function_declaration
2024-01-06 15:05:50 +09:00
[
"function"
"end"
] @keyword.function)
2023-04-27 04:25:19 -04:00
(function_definition
2024-01-06 15:05:50 +09:00
[
"function"
"end"
] @keyword.function)
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
; Operators
2023-04-27 04:25:19 -04:00
[
"and"
"not"
"or"
"in"
"typeof"
] @keyword.operator
[
"+"
"-"
"*"
"/"
"%"
"^"
"#"
"=="
"~="
"<="
">="
"<"
">"
"="
"&"
"|"
"?"
"//"
".."
"+="
"-="
"*="
"/="
"%="
"^="
"..="
] @operator
2024-01-06 15:05:50 +09:00
; Variables
2023-04-27 04:25:19 -04:00
(identifier) @variable
; Types
(type/identifier) @type
2023-04-27 04:25:19 -04:00
(generic_type
(identifier) @type)
2023-04-27 04:25:19 -04:00
(builtin_type) @type.builtin
((identifier) @type
(#lua-match? @type "^[A-Z]"))
; Typedefs
2024-01-06 15:05:50 +09:00
(type_definition
"type"
.
(type) @type.definition
"=")
2023-04-27 04:25:19 -04:00
; Constants
((identifier) @constant
2024-01-06 15:05:50 +09:00
(#lua-match? @constant "^[A-Z][A-Z_0-9]+$"))
2023-04-27 04:25:19 -04:00
; Builtins
((identifier) @constant.builtin
(#eq? @constant.builtin "_VERSION"))
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))
"..." @variable.builtin
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
((identifier) @module.builtin
(#any-of? @module.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8"))
2023-04-27 04:25:19 -04:00
((identifier) @keyword.coroutine
(#eq? @keyword.coroutine "coroutine"))
2024-01-06 15:05:50 +09:00
; Tables
(field
name: (identifier) @variable.member)
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
(dot_index_expression
field: (identifier) @variable.member)
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
(object_type
(identifier) @variable.member)
2023-04-27 04:25:19 -04:00
(table_constructor
2024-01-06 15:05:50 +09:00
[
"{"
"}"
] @constructor)
2023-04-27 04:25:19 -04:00
; Functions
2024-01-06 15:05:50 +09:00
(parameter
.
(identifier) @variable.parameter)
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
(function_type
(identifier) @variable.parameter)
(function_call
name: (identifier) @function.call)
(function_declaration
name: (identifier) @function)
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
(function_call
name: (dot_index_expression
field: (identifier) @function.call))
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
(function_declaration
name: (dot_index_expression
field: (identifier) @function))
2023-04-27 04:25:19 -04:00
2024-01-06 15:05:50 +09:00
(method_index_expression
method: (identifier) @function.method.call)
2023-04-27 04:25:19 -04:00
(function_call
(identifier) @function.builtin
(#any-of? @function.builtin
; built-in functions in Lua 5.1
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile"
"loadstring" "module" "next" "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset"
"require" "select" "setfenv" "setmetatable" "tonumber" "tostring" "type" "unpack" "xpcall"
"typeof" "__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc"
2023-04-27 04:25:19 -04:00
"__idiv" "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex"
"__pairs" "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
; Literals
(number) @number
(string) @string
2023-04-27 04:25:19 -04:00
(nil) @constant.builtin
(vararg_expression) @variable.builtin
[
(false)
(true)
] @boolean
2024-01-06 15:05:50 +09:00
; Punctuations
2023-04-27 04:25:19 -04:00
[
";"
":"
"::"
","
"."
"->"
] @punctuation.delimiter
[
2024-01-06 15:05:50 +09:00
"("
")"
"["
"]"
"{"
"}"
2023-04-27 04:25:19 -04:00
] @punctuation.bracket
(variable_list
attribute: (attribute
([
"<"
">"
] @punctuation.bracket
(identifier) @attribute)))
2024-01-06 15:05:50 +09:00
(generic_type
[
"<"
">"
] @punctuation.bracket)
(generic_type_list
[
"<"
">"
] @punctuation.bracket)
2023-04-27 04:25:19 -04:00
; Comments
(comment) @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^[-][-][-]"))
((comment) @comment.documentation
(#lua-match? @comment.documentation "^[-][-](%s?)@"))
2023-12-21 15:31:40 -08:00
; string.match("123", "%d+")
(function_call
(dot_index_expression
field: (identifier) @_method
(#any-of? @_method "find" "format" "match" "gmatch" "gsub"))
arguments: (arguments
.
(_)
.
(string
content: _ @string.regexp)))
2023-12-21 15:31:40 -08:00
; ("123"):match("%d+")
(function_call
(method_index_expression
method: (identifier) @_method
(#any-of? @_method "find" "format" "match" "gmatch" "gsub"))
arguments: (arguments
.
(string
content: _ @string.regexp)))