diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2024-01-17 16:55:52 +0100 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2024-01-21 10:41:18 +0100 |
| commit | f5dc45310941dff6efc02d955fc0c110190e9b85 (patch) | |
| tree | ee4f96087a641dbd0df21cc9db46061c5864dae2 /runtime/queries/vim | |
| parent | fa9a85ae468b9df30ae9e5c05a08c0f124e267df (diff) | |
| download | rneovim-f5dc45310941dff6efc02d955fc0c110190e9b85.tar.gz rneovim-f5dc45310941dff6efc02d955fc0c110190e9b85.tar.bz2 rneovim-f5dc45310941dff6efc02d955fc0c110190e9b85.zip | |
feat(treesitter)!: new standard capture names
Problem: Sharing queries with upstream and Helix is difficult due to
different capture names.
Solution: Define and document a new set of standard captures that
matches tree-sitter "standard captures" (where defined) and is closer to
Helix' Atom-style nested groups.
This is a breaking change for colorschemes that defined highlights based
on the old captures. On the other hand, the default colorscheme now
defines links for all standard captures (not just those used in bundled
queries), improving the out-of-the-box experience.
Diffstat (limited to 'runtime/queries/vim')
| -rw-r--r-- | runtime/queries/vim/folds.scm | 4 | ||||
| -rw-r--r-- | runtime/queries/vim/highlights.scm | 254 | ||||
| -rw-r--r-- | runtime/queries/vim/injections.scm | 64 |
3 files changed, 182 insertions, 140 deletions
diff --git a/runtime/queries/vim/folds.scm b/runtime/queries/vim/folds.scm index 4c99735836..0a1fb695f3 100644 --- a/runtime/queries/vim/folds.scm +++ b/runtime/queries/vim/folds.scm @@ -1,4 +1,4 @@ [ - (if_statement) - (function_definition) + (if_statement) + (function_definition) ] @fold diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm index 09188ddb68..54832ffa56 100644 --- a/runtime/queries/vim/highlights.scm +++ b/runtime/queries/vim/highlights.scm @@ -1,15 +1,15 @@ (identifier) @variable -((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) -;; Keywords +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) +; Keywords [ "if" "else" "elseif" "endif" -] @conditional +] @keyword.conditional [ "try" @@ -17,7 +17,7 @@ "finally" "endtry" "throw" -] @exception +] @keyword.exception [ "for" @@ -27,31 +27,50 @@ "endwhile" "break" "continue" -] @repeat +] @keyword.repeat [ "function" "endfunction" ] @keyword.function -;; Function related -(function_declaration name: (_) @function) -(call_expression function: (identifier) @function.call) -(call_expression function: (scoped_identifier (identifier) @function.call)) -(parameters (identifier) @parameter) -(default_parameter (identifier) @parameter) +; Function related +(function_declaration + name: (_) @function) + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: + (scoped_identifier + (identifier) @function.call)) -[ (bang) (spread) ] @punctuation.special +(parameters + (identifier) @variable.parameter) + +(default_parameter + (identifier) @variable.parameter) + +[ + (bang) + (spread) +] @punctuation.special + +[ + (no_option) + (inv_option) + (default_option) + (option_name) +] @variable.builtin -[ (no_option) (inv_option) (default_option) (option_name) ] @variable.builtin [ (scope) "a:" "$" -] @namespace - -;; Commands and user defined commands +] @module +; Commands and user defined commands [ "let" "unlet" @@ -83,6 +102,7 @@ "delcommand" "comclear" "colorscheme" + "scriptencoding" "startinsert" "stopinsert" "global" @@ -106,41 +126,48 @@ "visual" "view" "eval" + "sign" ] @keyword -(map_statement cmd: _ @keyword) + +(map_statement + cmd: _ @keyword) + (command_name) @function.macro -;; Filetype command - -(filetype_statement [ - "detect" - "plugin" - "indent" - "on" - "off" -] @keyword) - -;; Syntax command - -(syntax_statement (keyword) @string) -(syntax_statement [ - "enable" - "on" - "off" - "reset" - "case" - "spell" - "foldlevel" - "iskeyword" - "keyword" - "match" - "cluster" - "region" - "clear" - "include" -] @keyword) - -(syntax_argument name: _ @keyword) +; Filetype command +(filetype_statement + [ + "detect" + "plugin" + "indent" + "on" + "off" + ] @keyword) + +; Syntax command +(syntax_statement + (keyword) @string) + +(syntax_statement + [ + "enable" + "on" + "off" + "reset" + "case" + "spell" + "foldlevel" + "iskeyword" + "keyword" + "match" + "cluster" + "region" + "clear" + "include" + ] @keyword) + +(syntax_argument + name: _ @keyword) [ "<buffer>" @@ -151,70 +178,96 @@ "<unique>" ] @constant.builtin -(augroup_name) @namespace +(augroup_name) @module (au_event) @constant -(normal_statement (commands) @constant) -;; Highlight command +(normal_statement + (commands) @constant) +; Highlight command (hl_attribute key: _ @property val: _ @constant) (hl_group) @type -(highlight_statement [ - "default" - "link" - "clear" -] @keyword) - -;; Command command +(highlight_statement + [ + "default" + "link" + "clear" + ] @keyword) +; Command command (command) @string (command_attribute name: _ @property - val: (behavior - name: _ @constant - val: (identifier)? @function)?) + val: + (behavior + name: _ @constant + val: (identifier)? @function)?) -;; Edit command +; Edit command (plus_plus_opt val: _? @constant) @property -(plus_cmd "+" @property) @property - -;; Runtime command -(runtime_statement (where) @keyword.operator) +(plus_cmd + "+" @property) @property -;; Colorscheme command +; Runtime command +(runtime_statement + (where) @keyword.operator) -(colorscheme_statement (name) @string) +; Colorscheme command +(colorscheme_statement + (name) @string) -;; Literals +; Scriptencoding command +(scriptencoding_statement + (encoding) @string.special) +; Literals (string_literal) @string + (integer_literal) @number -(float_literal) @float + +(float_literal) @number.float + (comment) @comment @spell + (line_continuation_comment) @comment @spell + (pattern) @string.special -(pattern_multi) @string.regex -(filename) @string -(heredoc (body) @string) -(heredoc (parameter) @keyword) -[ (marker_definition) (endmarker) ] @label -(literal_dictionary (literal_key) @label) -((scoped_identifier - (scope) @_scope . (identifier) @boolean) - (#eq? @_scope "v:") - (#any-of? @boolean "true" "false")) -;; Operators +(pattern_multi) @string.regexp + +(filename) @string.special.path + +(heredoc + (body) @string) + +(heredoc + (parameter) @keyword) [ + (marker_definition) + (endmarker) +] @label + +(literal_dictionary + (literal_key) @property) + +((scoped_identifier + (scope) @_scope + . + (identifier) @boolean) + (#eq? @_scope "v:") + (#any-of? @boolean "true" "false")) + +; Operators +[ "||" "&&" "&" @@ -248,12 +301,13 @@ ] @operator ; Some characters have different meanings based on the context -(unary_operation "!" @operator) -(binary_operation "." @operator) - +(unary_operation + "!" @operator) -;; Punctuation +(binary_operation + "." @operator) +; Punctuation [ "(" ")" @@ -264,27 +318,31 @@ "#{" ] @punctuation.bracket -(field_expression "." @punctuation.delimiter) +(field_expression + "." @punctuation.delimiter) [ "," ":" ] @punctuation.delimiter -(ternary_expression ["?" ":"] @conditional.ternary) +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) ; Options ((set_value) @number - (#lua-match? @number "^[%d]+(%.[%d]+)?$")) + (#lua-match? @number "^[%d]+(%.[%d]+)?$")) + +(inv_option + "!" @operator) -(inv_option "!" @operator) -(set_item "?" @operator) +(set_item + "?" @operator) ((set_item - option: (option_name) @_option - value: (set_value) @function) - (#any-of? @_option - "tagfunc" "tfu" - "completefunc" "cfu" - "omnifunc" "ofu" - "operatorfunc" "opfunc")) + option: (option_name) @_option + value: (set_value) @function) + (#any-of? @_option "tagfunc" "tfu" "completefunc" "cfu" "omnifunc" "ofu" "operatorfunc" "opfunc")) diff --git a/runtime/queries/vim/injections.scm b/runtime/queries/vim/injections.scm index 50f0190112..16ec57ca99 100644 --- a/runtime/queries/vim/injections.scm +++ b/runtime/queries/vim/injections.scm @@ -1,48 +1,32 @@ -((lua_statement (script (body) @injection.content)) - (#set! injection.language "lua")) +(lua_statement + (script + (body) @injection.content + (#set! injection.language "lua"))) -((lua_statement (chunk) @injection.content) - (#set! injection.language "lua")) +(lua_statement + (chunk) @injection.content + (#set! injection.language "lua")) -((ruby_statement (script (body) @injection.content)) - (#set! injection.language "ruby")) +(ruby_statement + (script + (body) @injection.content + (#set! injection.language "ruby"))) -((ruby_statement (chunk) @injection.content) - (#set! injection.language "ruby")) +(ruby_statement + (chunk) @injection.content + (#set! injection.language "ruby")) -((python_statement (script (body) @injection.content)) - (#set! injection.language "python")) +(python_statement + (script + (body) @injection.content + (#set! injection.language "python"))) -((python_statement (chunk) @injection.content) - (#set! injection.language "python")) - -;; If we support perl at some point... -;; ((perl_statement (script (body) @injection.content)) -;; (#set! injection.language "perl")) -;; ((perl_statement (chunk) @injection.content) -;; (#set! injection.language "perl")) - -((autocmd_statement (pattern) @injection.content) - (#set! injection.language "regex")) +(python_statement + (chunk) @injection.content + (#set! injection.language "python")) ((set_item - option: (option_name) @_option - value: (set_value) @injection.content) - (#any-of? @_option - "includeexpr" "inex" - "printexpr" "pexpr" - "formatexpr" "fex" - "indentexpr" "inde" - "foldtext" "fdt" - "foldexpr" "fde" - "diffexpr" "dex" - "patchexpr" "pex" - "charconvert" "ccv") + option: (option_name) @_option + value: (set_value) @injection.content) + (#any-of? @_option "includeexpr" "inex" "printexpr" "pexpr" "formatexpr" "fex" "indentexpr" "inde" "foldtext" "fdt" "foldexpr" "fde" "diffexpr" "dex" "patchexpr" "pex" "charconvert" "ccv") (#set! injection.language "vim")) - - -; ((comment) @injection.content -; (#set! injection.language "comment")) - -; ((line_continuation_comment) @injection.content -; (#set! injection.language "comment")) |