mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-08 06:20:01 -04:00
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"
(3f44b89685/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`
132 lines
3.4 KiB
Scheme
132 lines
3.4 KiB
Scheme
|
|
;; Primitives
|
|
(boolean) @boolean
|
|
(comment) @comment @spell
|
|
((comment) @comment.documentation
|
|
(#lua-match? @comment.documentation "^[-][-][-]"))
|
|
((comment) @comment.documentation
|
|
(#lua-match? @comment.documentation "^[-][-](%s?)@"))
|
|
(shebang_comment) @keyword.directive
|
|
(identifier) @variable
|
|
((identifier) @variable.builtin
|
|
(#eq? @variable.builtin "self"))
|
|
(nil) @constant.builtin
|
|
(number) @number
|
|
(string) @string
|
|
(table_constructor ["{" "}"] @constructor)
|
|
(varargs "..." @constant.builtin)
|
|
[ "," "." ":" ";" ] @punctuation.delimiter
|
|
|
|
(escape_sequence) @string.escape
|
|
(format_specifier) @string.escape
|
|
|
|
;; Basic statements/Keywords
|
|
[ "if" "then" "elseif" "else" ] @keyword.conditional
|
|
[ "for" "while" "repeat" "until" ] @keyword.repeat
|
|
"return" @keyword.return
|
|
[ "in" "local" (break) (goto) "do" "end" ] @keyword
|
|
(label) @label
|
|
|
|
;; Global isn't a real keyword, but it gets special treatment in these places
|
|
(var_declaration "global" @keyword)
|
|
(type_declaration "global" @keyword)
|
|
(function_statement "global" @keyword)
|
|
(record_declaration "global" @keyword)
|
|
(enum_declaration "global" @keyword)
|
|
|
|
;; Ops
|
|
(bin_op (op) @operator)
|
|
(unary_op (op) @operator)
|
|
[ "=" "as" ] @operator
|
|
|
|
;; Functions
|
|
(function_statement
|
|
"function" @keyword.function
|
|
. name: (_) @function)
|
|
(anon_function
|
|
"function" @keyword.function)
|
|
(function_body "end" @keyword.function)
|
|
|
|
(arg name: (identifier) @variable.parameter)
|
|
|
|
(function_signature
|
|
(arguments
|
|
. (arg name: (identifier) @variable.builtin))
|
|
(#eq? @variable.builtin "self"))
|
|
|
|
(typeargs
|
|
"<" @punctuation.bracket
|
|
. (_) @variable.parameter
|
|
. ("," . (_) @variable.parameter)*
|
|
. ">" @punctuation.bracket)
|
|
|
|
(function_call
|
|
(identifier) @function . (arguments))
|
|
(function_call
|
|
(index (_) key: (identifier) @function) . (arguments))
|
|
(function_call
|
|
(method_index (_) key: (identifier) @function) . (arguments))
|
|
|
|
;; Types
|
|
(record_declaration
|
|
. "record" @keyword
|
|
name: (identifier) @type)
|
|
(anon_record . "record" @keyword)
|
|
(record_body
|
|
(record_declaration
|
|
. [ "record" ] @keyword
|
|
. name: (identifier) @type))
|
|
(record_body
|
|
(enum_declaration
|
|
. [ "enum" ] @keyword
|
|
. name: (identifier) @type))
|
|
(record_body
|
|
(typedef
|
|
. "type" @keyword
|
|
. name: (identifier) @type . "="))
|
|
(record_body
|
|
(metamethod "metamethod" @keyword))
|
|
(record_body
|
|
(userdata) @keyword)
|
|
|
|
(enum_declaration
|
|
"enum" @keyword
|
|
name: (identifier) @type)
|
|
|
|
(type_declaration "type" @keyword)
|
|
(type_declaration (identifier) @type)
|
|
(simple_type name: (identifier) @type)
|
|
(type_index (identifier) @type)
|
|
(type_union "|" @operator)
|
|
(function_type "function" @type)
|
|
|
|
;; The rest of it
|
|
(var_declaration
|
|
declarators: (var_declarators
|
|
(var name: (identifier) @variable)))
|
|
(var_declaration
|
|
declarators: (var_declarators
|
|
(var
|
|
"<" @punctuation.bracket
|
|
. attribute: (attribute) @attribute
|
|
. ">" @punctuation.bracket)))
|
|
[ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket
|
|
|
|
;; Only highlight format specifiers in calls to string.format
|
|
;; string.format('...')
|
|
;(function_call
|
|
; called_object: (index
|
|
; (identifier) @base
|
|
; key: (identifier) @entry)
|
|
; arguments: (arguments .
|
|
; (string (format_specifier) @string.escape))
|
|
;
|
|
; (#eq? @base "string")
|
|
; (#eq? @entry "format"))
|
|
|
|
;; ('...'):format()
|
|
;(function_call
|
|
; called_object: (method_index
|
|
; (string (format_specifier) @string.escape)
|
|
; key: (identifier) @func-name)
|
|
; (#eq? @func-name "format"))
|