mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-07 22:10: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`
265 lines
4.5 KiB
Scheme
265 lines
4.5 KiB
Scheme
; CREDITS @stumash (stuart.mashaal@gmail.com)
|
|
|
|
(class_definition
|
|
name: (identifier) @type)
|
|
|
|
(enum_definition
|
|
name: (identifier) @type)
|
|
|
|
(object_definition
|
|
name: (identifier) @type)
|
|
|
|
(trait_definition
|
|
name: (identifier) @type)
|
|
|
|
(full_enum_case
|
|
name: (identifier) @type)
|
|
|
|
(simple_enum_case
|
|
name: (identifier) @type)
|
|
|
|
;; variables
|
|
|
|
(class_parameter
|
|
name: (identifier) @variable.parameter)
|
|
|
|
(self_type (identifier) @variable.parameter)
|
|
|
|
(interpolation (identifier) @none)
|
|
(interpolation (block) @none)
|
|
|
|
;; types
|
|
|
|
(type_definition
|
|
name: (type_identifier) @type.definition)
|
|
|
|
(type_identifier) @type
|
|
|
|
;; val/var definitions/declarations
|
|
|
|
(val_definition
|
|
pattern: (identifier) @variable)
|
|
|
|
(var_definition
|
|
pattern: (identifier) @variable)
|
|
|
|
(val_declaration
|
|
name: (identifier) @variable)
|
|
|
|
(var_declaration
|
|
name: (identifier) @variable)
|
|
|
|
; method definition
|
|
|
|
(function_declaration
|
|
name: (identifier) @function.method)
|
|
|
|
(function_definition
|
|
name: (identifier) @function.method)
|
|
|
|
; imports/exports
|
|
|
|
(import_declaration
|
|
path: (identifier) @module)
|
|
((stable_identifier (identifier) @module))
|
|
|
|
((import_declaration
|
|
path: (identifier) @type) (#lua-match? @type "^[A-Z]"))
|
|
((stable_identifier (identifier) @type) (#lua-match? @type "^[A-Z]"))
|
|
|
|
(export_declaration
|
|
path: (identifier) @module)
|
|
((stable_identifier (identifier) @module))
|
|
|
|
((export_declaration
|
|
path: (identifier) @type) (#lua-match? @type "^[A-Z]"))
|
|
((stable_identifier (identifier) @type) (#lua-match? @type "^[A-Z]"))
|
|
|
|
((namespace_selectors (identifier) @type) (#lua-match? @type "^[A-Z]"))
|
|
|
|
; method invocation
|
|
|
|
(call_expression
|
|
function: (identifier) @function.call)
|
|
|
|
(call_expression
|
|
function: (operator_identifier) @function.call)
|
|
|
|
(call_expression
|
|
function: (field_expression
|
|
field: (identifier) @function.method.call))
|
|
|
|
((call_expression
|
|
function: (identifier) @constructor)
|
|
(#lua-match? @constructor "^[A-Z]"))
|
|
|
|
(generic_function
|
|
function: (identifier) @function.call)
|
|
|
|
(interpolated_string_expression
|
|
interpolator: (identifier) @function.call)
|
|
|
|
; function definitions
|
|
|
|
(function_definition
|
|
name: (identifier) @function)
|
|
|
|
(parameter
|
|
name: (identifier) @variable.parameter)
|
|
|
|
(binding
|
|
name: (identifier) @variable.parameter)
|
|
|
|
; expressions
|
|
|
|
(field_expression field: (identifier) @property)
|
|
(field_expression value: (identifier) @type
|
|
(#lua-match? @type "^[A-Z]"))
|
|
|
|
(infix_expression operator: (identifier) @operator)
|
|
(infix_expression operator: (operator_identifier) @operator)
|
|
(infix_type operator: (operator_identifier) @operator)
|
|
(infix_type operator: (operator_identifier) @operator)
|
|
|
|
; literals
|
|
|
|
(boolean_literal) @boolean
|
|
(integer_literal) @number
|
|
(floating_point_literal) @number.float
|
|
|
|
[
|
|
(string)
|
|
(character_literal)
|
|
(interpolated_string_expression)
|
|
] @string
|
|
|
|
(symbol_literal) @string.special.symbol
|
|
|
|
(interpolation "$" @punctuation.special)
|
|
|
|
;; keywords
|
|
|
|
(opaque_modifier) @type.qualifier
|
|
(infix_modifier) @keyword
|
|
(transparent_modifier) @type.qualifier
|
|
(open_modifier) @type.qualifier
|
|
|
|
[
|
|
"case"
|
|
"class"
|
|
"enum"
|
|
"extends"
|
|
"derives"
|
|
"finally"
|
|
;; `forSome` existential types not implemented yet
|
|
;; `macro` not implemented yet
|
|
"object"
|
|
"override"
|
|
"package"
|
|
"trait"
|
|
"type"
|
|
"val"
|
|
"var"
|
|
"with"
|
|
"given"
|
|
"using"
|
|
"end"
|
|
"implicit"
|
|
"extension"
|
|
"with"
|
|
] @keyword
|
|
|
|
[
|
|
"abstract"
|
|
"final"
|
|
"lazy"
|
|
"sealed"
|
|
"private"
|
|
"protected"
|
|
] @type.qualifier
|
|
|
|
(inline_modifier) @keyword.storage
|
|
|
|
(null_literal) @constant.builtin
|
|
|
|
(wildcard) @variable.parameter
|
|
|
|
(annotation) @attribute
|
|
|
|
;; special keywords
|
|
|
|
"new" @keyword.operator
|
|
|
|
[
|
|
"else"
|
|
"if"
|
|
"match"
|
|
"then"
|
|
] @keyword.conditional
|
|
|
|
[
|
|
"("
|
|
")"
|
|
"["
|
|
"]"
|
|
"{"
|
|
"}"
|
|
] @punctuation.bracket
|
|
|
|
[
|
|
"."
|
|
","
|
|
] @punctuation.delimiter
|
|
|
|
[
|
|
"do"
|
|
"for"
|
|
"while"
|
|
"yield"
|
|
] @keyword.repeat
|
|
|
|
"def" @keyword.function
|
|
|
|
[
|
|
"=>"
|
|
"<-"
|
|
"@"
|
|
] @operator
|
|
|
|
["import" "export"] @keyword.import
|
|
|
|
[
|
|
"try"
|
|
"catch"
|
|
"throw"
|
|
] @keyword.exception
|
|
|
|
"return" @keyword.return
|
|
|
|
[
|
|
(comment)
|
|
(block_comment)
|
|
] @comment @spell
|
|
|
|
((block_comment) @comment.documentation
|
|
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
|
|
|
|
;; `case` is a conditional keyword in case_block
|
|
|
|
(case_block
|
|
(case_clause ("case") @keyword.conditional))
|
|
|
|
(operator_identifier) @operator
|
|
|
|
((identifier) @type (#lua-match? @type "^[A-Z]"))
|
|
((identifier) @variable.builtin
|
|
(#lua-match? @variable.builtin "^this$"))
|
|
|
|
(
|
|
(identifier) @function.builtin
|
|
(#lua-match? @function.builtin "^super$")
|
|
)
|
|
|
|
;; Scala CLI using directives
|
|
(using_directive_key) @variable.parameter
|
|
(using_directive_value) @string
|