From f5dc45310941dff6efc02d955fc0c110190e9b85 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 17 Jan 2024 16:55:52 +0100 Subject: [PATCH] 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. --- runtime/doc/news.txt | 5 + runtime/doc/treesitter.txt | 149 +++++--- runtime/queries/bash/folds.scm | 1 + runtime/queries/bash/highlights.scm | 244 ++++++++----- runtime/queries/c/folds.scm | 32 +- runtime/queries/c/highlights.scm | 180 ++++++--- runtime/queries/c/injections.scm | 23 +- runtime/queries/lua/folds.scm | 18 +- runtime/queries/lua/highlights.scm | 254 +++++++------ runtime/queries/lua/injections.scm | 119 +++++- runtime/queries/markdown/folds.scm | 16 +- runtime/queries/markdown/highlights.scm | 126 +++++-- runtime/queries/markdown/injections.scm | 28 +- .../queries/markdown_inline/highlights.scm | 100 ++--- .../queries/markdown_inline/injections.scm | 9 +- runtime/queries/python/folds.scm | 5 - runtime/queries/python/highlights.scm | 342 +++++++++++------- runtime/queries/query/highlights.scm | 79 +++- runtime/queries/vim/folds.scm | 4 +- runtime/queries/vim/highlights.scm | 248 ++++++++----- runtime/queries/vim/injections.scm | 64 ++-- runtime/queries/vimdoc/highlights.scm | 67 +++- runtime/queries/vimdoc/injections.scm | 2 +- src/nvim/highlight_group.c | 132 ++++--- test/functional/treesitter/fold_spec.lua | 2 +- test/functional/treesitter/highlight_spec.lua | 6 +- test/old/testdir/test_syntax.vim | 6 +- 27 files changed, 1434 insertions(+), 827 deletions(-) diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 05cfad5af1..29b0ec1ec6 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -112,6 +112,11 @@ The following changes may require adaptations in user config or plugins. • 'termguicolors' is enabled by default when Nvim is able to determine that the host terminal emulator supports 24-bit color. +• Treesitter highlight groups have been renamed to be more in line with + upstream tree-sitter and Helix to make it easier to share queries. The full + list is documented in |treesitter-highlight-groups|. + + ============================================================================== BREAKING CHANGES IN HEAD *news-breaking-dev* diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 14dedbcbd9..d082aa8cc4 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -400,58 +400,115 @@ instance, to highlight comments differently per language: >vim hi @comment.lua guifg=DarkBlue hi link @comment.doc.java String < -The following captures are linked by default to standard |group-name|s: +The following captures are linked by default to standard |group-name|s (use +|:Inspect| on a group to see the current link): -@text.literal Comment -@text.reference Identifier -@text.title Title -@text.uri Underlined -@text.underline Underlined -@text.todo Todo +@variable various variable names +@variable.builtin built-in variable names (e.g. `this`) +@variable.parameter parameters of a function +@variable.member object and struct fields -@comment Comment -@punctuation Delimiter +@constant constant identifiers +@constant.builtin built-in constant values +@constant.macro constants defined by the preprocessor -@constant Constant -@constant.builtin Special -@constant.macro Define -@define Define -@macro Macro -@string String -@string.escape SpecialChar -@string.special SpecialChar -@character Character -@character.special SpecialChar -@number Number -@boolean Boolean -@float Float +@module modules or namespaces +@module.builtin built-in modules or namespaces +@label GOTO and other labels (e.g. `label:` in C), including heredoc labels -@function Function -@function.builtin Special -@function.macro Macro -@parameter Identifier -@method Function -@field Identifier -@property Identifier -@constructor Special +@string string literals +@string.documentation string documenting code (e.g. Python docstrings) +@string.regexp regular expressions +@string.escape escape sequences +@string.special other special strings (e.g. dates) +@string.special.symbol symbols or atoms +@string.special.path filenames +@string.special.url URIs (e.g. hyperlinks) -@conditional Conditional -@repeat Repeat -@label Label -@operator Operator -@keyword Keyword -@exception Exception +@character character literals +@character.special special characters (e.g. wildcards) -@variable Identifier -@type Type -@type.definition Typedef -@storageclass StorageClass -@structure Structure -@namespace Identifier -@include Include -@preproc PreProc -@debug Debug -@tag Tag +@boolean boolean literals +@number numeric literals +@number.float floating-point number literals + +@type type or class definitions and annotations +@type.builtin built-in types +@type.definition identifiers in type definitions (e.g. `typedef ` in C) +@type.qualifier type qualifiers (e.g. `const`) + +@attribute attribute annotations (e.g. Python decorators) +@property the key in key/value pairs + +@function function definitions +@function.builtin built-in functions +@function.call function calls +@function.macro preprocessor macros + +@function.method method definitions +@function.method.call method calls + +@constructor constructor calls and definitions +@operator symbolic operators (e.g. `+` / `*`) + +@keyword keywords not fitting into specific categories +@keyword.coroutine keywords related to coroutines (e.g. `go` in Go, `async/await` in Python) +@keyword.function keywords that define a function (e.g. `func` in Go, `def` in Python) +@keyword.operator operators that are English words (e.g. `and` / `or`) +@keyword.import keywords for including modules (e.g. `import` / `from` in Python) +@keyword.storage modifiers that affect storage in memory or life-time +@keyword.repeat keywords related to loops (e.g. `for` / `while`) +@keyword.return keywords like `return` and `yield` +@keyword.debug keywords related to debugging +@keyword.exception keywords related to exceptions (e.g. `throw` / `catch`) + +@keyword.conditional keywords related to conditionals (e.g. `if` / `else`) +@keyword.conditional.ternary ternary operator (e.g. `?` / `:`) + +@keyword.directive various preprocessor directives and shebangs +@keyword.directive.define preprocessor definition directives + +@punctuation.delimiter delimiters (e.g. `;` / `.` / `,`) +@punctuation.bracket brackets (e.g. `()` / `{}` / `[]`) +@punctuation.special special symbols (e.g. `{}` in string interpolation) + +@comment line and block comments +@comment.documentation comments documenting code + +@comment.error error-type comments (e.g. `ERROR`, `FIXME`, `DEPRECATED:`) +@comment.warning warning-type comments (e.g. `WARNING:`, `FIX:`, `HACK:`) +@comment.todo todo-type comments (e.g. `TODO:`, `WIP:`, `FIXME:`) +@comment.note note-type comments (e.g. `NOTE:`, `INFO:`, `XXX`) + +@markup.strong bold text +@markup.italic italic text +@markup.strikethrough struck-through text +@markup.underline underlined text (only for literal underline markup!) + +@markup.heading headings, titles (including markers) + +@markup.quote block quotes +@markup.math math environments (e.g. `$ ... $` in LaTeX) +@markup.environment environments (e.g. in LaTeX) + +@markup.link text references, footnotes, citations, etc. +@markup.link.label link, reference descriptions +@markup.link.url URL-style links + +@markup.raw literal or verbatim text (e.g. inline code) +@markup.raw.block literal or verbatim text as a stand-alone block + +@markup.list list markers +@markup.list.checked checked todo-style list markers +@markup.list.unchecked unchecked todo-style list markers + +@diff.plus added text (for diff files) +@diff.minus deleted text (for diff files) +@diff.delta changed text (for diff files) + +@tag XML-style tag names (e.g. in XML, HTML, etc.) +@tag.attribute XML-style tag attributes +@tag.delimiter XML-style tag delimiters *treesitter-highlight-spell* The special `@spell` capture can be used to indicate that a node should be diff --git a/runtime/queries/bash/folds.scm b/runtime/queries/bash/folds.scm index 851c67eed4..766dbe598b 100644 --- a/runtime/queries/bash/folds.scm +++ b/runtime/queries/bash/folds.scm @@ -5,4 +5,5 @@ (for_statement) (while_statement) (c_style_for_statement) + (heredoc_redirect) ] @fold diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm index 23bf03e697..21346ded8f 100644 --- a/runtime/queries/bash/highlights.scm +++ b/runtime/queries/bash/highlights.scm @@ -1,81 +1,100 @@ -(simple_expansion) @none -(expansion - "${" @punctuation.special - "}" @punctuation.special) @none [ - "(" - ")" - "((" - "))" - "{" - "}" - "[" - "]" - "[[" - "]]" - ] @punctuation.bracket + "(" + ")" + "{" + "}" + "[" + "]" + "[[" + "]]" + "((" + "))" +] @punctuation.bracket [ - ";" - ";;" - (heredoc_start) - ] @punctuation.delimiter + ";" + ";;" + ";&" + ";;&" + "&" +] @punctuation.delimiter [ - "$" -] @punctuation.special + ">" + ">>" + "<" + "<<" + "&&" + "|" + "|&" + "||" + "=" + "+=" + "=~" + "==" + "!=" + "&>" + "&>>" + "<&" + ">&" + ">|" + "<&-" + ">&-" + "<<-" + "<<<" + ".." +] @operator + +; Do *not* spell check strings since they typically have some sort of +; interpolation in them, or, are typically used for things like filenames, URLs, +; flags and file content. +[ + (string) + (raw_string) + (ansi_c_string) + (heredoc_body) +] @string [ - ">" - ">>" - "<" - "<<" - "&" - "&&" - "|" - "||" - "=" - "=~" - "==" - "!=" - ] @operator + (heredoc_start) + (heredoc_end) +] @label + +(variable_assignment + (word) @string) + +(command + argument: "$" @string) ; bare dollar [ - (string) - (raw_string) - (ansi_c_string) - (heredoc_body) -] @string @spell - -(variable_assignment (word) @string) + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" +] @keyword.conditional [ - "if" - "then" - "else" - "elif" - "fi" - "case" - "in" - "esac" - ] @conditional + "for" + "do" + "done" + "select" + "until" + "while" +] @keyword.repeat [ - "for" - "do" - "done" - "select" - "until" - "while" - ] @repeat - -[ - "declare" - "export" - "local" - "readonly" - "unset" - ] @keyword + "declare" + "typeset" + "export" + "readonly" + "local" + "unset" + "unsetenv" +] @keyword "function" @keyword.function @@ -83,28 +102,56 @@ ; trap -l ((word) @constant.builtin - (#match? @constant.builtin "^SIG(HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR[12]|SEGV|PIPE|ALRM|TERM|STKFLT|CHLD|CONT|STOP|TSTP|TT(IN|OU)|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS|RTMIN([+]([1-9]|1[0-5]))?|RTMAX(-([1-9]|1[0-4]))?)$")) + (#match? @constant.builtin "^SIG(HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR[12]|SEGV|PIPE|ALRM|TERM|STKFLT|CHLD|CONT|STOP|TSTP|TT(IN|OU)|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS|RTMIN([+]([1-9]|1[0-5]))?|RTMAX(-([1-9]|1[0-4]))?)$")) ((word) @boolean (#any-of? @boolean "true" "false")) (comment) @comment @spell -(test_operator) @string + +(test_operator) @operator (command_substitution - [ "$(" ")" ] @punctuation.bracket) + "$(" @punctuation.bracket) (process_substitution - [ "<(" ")" ] @punctuation.bracket) + "<(" @punctuation.bracket) +(arithmetic_expansion + [ + "$((" + "((" + ] @punctuation.special + "))" @punctuation.special) + +(arithmetic_expansion + "," @punctuation.delimiter) + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(binary_expression + operator: _ @operator) + +(unary_expression + operator: _ @operator) + +(postfix_expression + operator: _ @operator) (function_definition name: (word) @function) -(command_name (word) @function.call) +(command_name + (word) @function.call) -((command_name (word) @function.builtin) - (#any-of? @function.builtin +((command_name + (word) @function.builtin) + ; format-ignore + (#any-of? @function.builtin "alias" "bg" "bind" "break" "builtin" "caller" "cd" "command" "compgen" "complete" "compopt" "continue" "coproc" "dirs" "disown" "echo" "enable" "eval" @@ -116,30 +163,59 @@ "ulimit" "umask" "unalias" "wait")) (command - argument: [ - (word) @parameter - (concatenation (word) @parameter) - ]) + argument: + [ + (word) @variable.parameter + (concatenation + (word) @variable.parameter) + ]) + +(number) @number ((word) @number (#lua-match? @number "^[0-9]+$")) (file_redirect - descriptor: (file_descriptor) @operator - destination: (word) @parameter) + destination: (word) @variable.parameter) + +(file_descriptor) @operator + +(simple_expansion + "$" @punctuation.special) @none (expansion - [ "${" "}" ] @punctuation.bracket) + "${" @punctuation.special + "}" @punctuation.special) @none + +(expansion + operator: _ @punctuation.special) + +(expansion + "@" + . + operator: _ @character.special) + +((expansion + (subscript + index: (word) @character.special)) + (#any-of? @character.special "@" "*")) + +"``" @punctuation.special (variable_name) @variable ((variable_name) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) (case_item - value: (word) @parameter) + value: (word) @variable.parameter) -(regex) @string.regex +[ + (regex) + (extglob_pattern) +] @string.regexp -((program . (comment) @preproc) - (#lua-match? @preproc "^#!/")) +((program + . + (comment) @keyword.directive) + (#lua-match? @keyword.directive "^#!/")) diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm index 5a35334a24..2e2a6b4d0c 100644 --- a/runtime/queries/c/folds.scm +++ b/runtime/queries/c/folds.scm @@ -1,19 +1,21 @@ [ - (for_statement) - (if_statement) - (while_statement) - (switch_statement) - (case_statement) - (function_definition) - (struct_specifier) - (enum_specifier) - (comment) - (preproc_if) - (preproc_elif) - (preproc_else) - (preproc_ifdef) - (initializer_list) - (gnu_asm_expression) + (for_statement) + (if_statement) + (while_statement) + (do_statement) + (switch_statement) + (case_statement) + (function_definition) + (struct_specifier) + (enum_specifier) + (comment) + (preproc_if) + (preproc_elif) + (preproc_else) + (preproc_ifdef) + (preproc_function_def) + (initializer_list) + (gnu_asm_expression) ] @fold (compound_statement diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 29fb5747ca..c848f68dca 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,6 +1,9 @@ -; Lower priority to prefer @parameter when identifier appears in parameter_declaration. -((identifier) @variable (#set! "priority" 95)) -(preproc_def (preproc_arg) @variable) +; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration. +((identifier) @variable + (#set! "priority" 95)) + +(preproc_def + (preproc_arg) @variable) [ "default" @@ -17,7 +20,10 @@ "sizeof" "offsetof" ] @keyword.operator -(alignof_expression . _ @keyword.operator) + +(alignof_expression + . + _ @keyword.operator) "return" @keyword.return @@ -27,14 +33,14 @@ "do" "continue" "break" -] @repeat +] @keyword.repeat [ - "if" - "else" - "case" - "switch" -] @conditional + "if" + "else" + "case" + "switch" +] @keyword.conditional [ "#if" @@ -46,48 +52,54 @@ "#elifdef" "#elifndef" (preproc_directive) -] @preproc +] @keyword.directive -"#define" @define +"#define" @keyword.directive.define -"#include" @include +"#include" @keyword.import -[ ";" ":" "," "::" ] @punctuation.delimiter +[ + ";" + ":" + "," + "::" +] @punctuation.delimiter "..." @punctuation.special -[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket [ "=" - "-" "*" "/" "+" "%" - "~" "|" "&" "^" "<<" ">>" - "->" "." - "<" "<=" ">=" ">" "==" "!=" - "!" "&&" "||" - "-=" "+=" "*=" @@ -102,45 +114,57 @@ "++" ] @operator -;; Make sure the comma operator is given a highlight group after the comma -;; punctuator so the operator is highlighted properly. -(comma_expression [ "," ] @operator) +; Make sure the comma operator is given a highlight group after the comma +; punctuator so the operator is highlighted properly. +(comma_expression + "," @operator) [ (true) (false) ] @boolean -(conditional_expression [ "?" ":" ] @conditional.ternary) +(conditional_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) (string_literal) @string + (system_lib_string) @string + (escape_sequence) @string.escape (null) @constant.builtin + (number_literal) @number + (char_literal) @character -((preproc_arg) @function.macro (#set! "priority" 90)) +((preproc_arg) @function.macro + (#set! "priority" 90)) + (preproc_defined) @function.macro -(((field_expression - (field_identifier) @property)) @_parent - (#not-has-parent? @_parent template_method function_declarator call_expression)) +((field_expression + (field_identifier) @property) @_parent + (#not-has-parent? @_parent template_method function_declarator call_expression)) (field_designator) @property -(((field_identifier) @property) - (#has-ancestor? @property field_declaration) - (#not-has-ancestor? @property function_declarator)) + +((field_identifier) @property + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) (statement_identifier) @label [ - (type_identifier) - (type_descriptor) + (type_identifier) + (type_descriptor) ] @type -(storage_class_specifier) @storageclass +(storage_class_specifier) @keyword.storage [ (type_qualifier) @@ -149,25 +173,32 @@ ] @type.qualifier (linkage_specification - "extern" @storageclass) + "extern" @keyword.storage) (type_definition declarator: (type_identifier) @type.definition) (primitive_type) @type.builtin -(sized_type_specifier _ @type.builtin type: _?) +(sized_type_specifier + _ @type.builtin + type: _?) ((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) -(preproc_def (preproc_arg) @constant (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(preproc_def + (preproc_arg) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + (enumerator name: (identifier) @constant) + (case_statement value: (identifier) @constant) ((identifier) @constant.builtin + ; format-ignore (#any-of? @constant.builtin "stderr" "stdin" "stdout" "__FILE__" "__LINE__" "__DATE__" "__TIME__" @@ -180,7 +211,10 @@ "__clang_wide_literal_encoding__" "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" "__VA_ARGS__" "__VA_OPT__")) -(preproc_def (preproc_arg) @constant.builtin + +(preproc_def + (preproc_arg) @constant.builtin + ; format-ignore (#any-of? @constant.builtin "stderr" "stdin" "stdout" "__FILE__" "__LINE__" "__DATE__" "__TIME__" @@ -195,21 +229,26 @@ "__VA_ARGS__" "__VA_OPT__")) (attribute_specifier - (argument_list (identifier) @variable.builtin)) + (argument_list + (identifier) @variable.builtin)) + ((attribute_specifier - (argument_list (call_expression - function: (identifier) @variable.builtin)))) + (argument_list + (call_expression + function: (identifier) @variable.builtin)))) ((call_expression function: (identifier) @function.builtin) (#lua-match? @function.builtin "^__builtin_")) + ((call_expression - function: (identifier) @function.builtin) + function: (identifier) @function.builtin) (#has-ancestor? @function.builtin attribute_specifier)) -;; Preproc def / undef +; Preproc def / undef (preproc_def name: (_) @constant) + (preproc_call directive: (preproc_directive) @_u argument: (_) @constant @@ -217,15 +256,21 @@ (call_expression function: (identifier) @function.call) + (call_expression - function: (field_expression - field: (field_identifier) @function.call)) + function: + (field_expression + field: (field_identifier) @function.call)) + (function_declarator declarator: (identifier) @function) + (function_declarator - declarator: (parenthesized_declarator - (pointer_declarator - declarator: (field_identifier) @function))) + declarator: + (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) + (preproc_function_def name: (identifier) @function.macro) @@ -234,17 +279,40 @@ ((comment) @comment.documentation (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) -;; Parameters +; Parameters (parameter_declaration - declarator: (identifier) @parameter) + declarator: (identifier) @variable.parameter) (parameter_declaration - declarator: (array_declarator) @parameter) + declarator: (array_declarator) @variable.parameter) (parameter_declaration - declarator: (pointer_declarator) @parameter) + declarator: (pointer_declarator) @variable.parameter) -(preproc_params (identifier) @parameter) +; K&R functions +; To enable support for K&R functions, +; add the following lines to your own query config and uncomment them. +; They are commented out as they'll conflict with C++ +; Note that you'll need to have `; extends` at the top of your query file. +; +; (parameter_list (identifier) @variable.parameter) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (identifier) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (array_declarator) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (pointer_declarator) @variable.parameter)) +(preproc_params + (identifier) @variable.parameter) [ "__attribute__" @@ -259,5 +327,3 @@ (ms_pointer_modifier) (attribute_declaration) ] @attribute - -(ERROR) @error diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 5a49e20df5..ce2f88a215 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,21 +1,2 @@ -((preproc_def - (preproc_arg) @injection.content) - (#lua-match? @injection.content "\n") - (#set! injection.language "c")) - -(preproc_function_def - (preproc_arg) @injection.content - (#set! injection.language "c")) - -(preproc_call - (preproc_arg) @injection.content - (#set! injection.language "c")) - -; ((comment) @injection.content -; (#set! injection.language "comment")) - -; TODO: add when asm is added -; (gnu_asm_expression assembly_code: (string_literal) @injection.content -; (#set! injection.language "asm")) -; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content) -; (#set! injection.language "asm")) +((preproc_arg) @injection.content + (#set! injection.self)) diff --git a/runtime/queries/lua/folds.scm b/runtime/queries/lua/folds.scm index d8f0b42df3..9dfac3abc6 100644 --- a/runtime/queries/lua/folds.scm +++ b/runtime/queries/lua/folds.scm @@ -1,10 +1,12 @@ [ - (do_statement) - (while_statement) - (repeat_statement) - (if_statement) - (for_statement) - (function_declaration) - (function_definition) - (table_constructor) + (do_statement) + (while_statement) + (repeat_statement) + (if_statement) + (for_statement) + (function_declaration) + (function_definition) + (parameters) + (arguments) + (table_constructor) ] @fold diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 96ffeae793..0b0bf35a8b 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -1,81 +1,79 @@ -;; Keywords - +; Keywords "return" @keyword.return [ - "goto" - "in" - "local" + "goto" + "in" + "local" ] @keyword (break_statement) @keyword (do_statement -[ - "do" - "end" -] @keyword) + [ + "do" + "end" + ] @keyword) (while_statement -[ - "while" - "do" - "end" -] @repeat) + [ + "while" + "do" + "end" + ] @keyword.repeat) (repeat_statement -[ - "repeat" - "until" -] @repeat) + [ + "repeat" + "until" + ] @keyword.repeat) (if_statement -[ - "if" - "elseif" - "else" - "then" - "end" -] @conditional) + [ + "if" + "elseif" + "else" + "then" + "end" + ] @keyword.conditional) (elseif_statement -[ - "elseif" - "then" - "end" -] @conditional) + [ + "elseif" + "then" + "end" + ] @keyword.conditional) (else_statement -[ - "else" - "end" -] @conditional) + [ + "else" + "end" + ] @keyword.conditional) (for_statement -[ - "for" - "do" - "end" -] @repeat) + [ + "for" + "do" + "end" + ] @keyword.repeat) (function_declaration -[ - "function" - "end" -] @keyword.function) + [ + "function" + "end" + ] @keyword.function) (function_definition -[ - "function" - "end" -] @keyword.function) - -;; Operators + [ + "function" + "end" + ] @keyword.function) +; Operators [ - "and" - "not" - "or" + "and" + "not" + "or" ] @keyword.operator [ @@ -102,8 +100,7 @@ ".." ] @operator -;; Punctuations - +; Punctuations [ ";" ":" @@ -112,19 +109,17 @@ "." ] @punctuation.delimiter -;; Brackets - +; Brackets [ - "(" - ")" - "[" - "]" - "{" - "}" + "(" + ")" + "[" + "]" + "{" + "}" ] @punctuation.bracket -;; Variables - +; Variables (identifier) @variable ((identifier) @constant.builtin @@ -133,27 +128,28 @@ ((identifier) @variable.builtin (#eq? @variable.builtin "self")) -((identifier) @namespace.builtin - (#any-of? @namespace.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8")) +((identifier) @module.builtin + (#any-of? @module.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8")) ((identifier) @keyword.coroutine (#eq? @keyword.coroutine "coroutine")) (variable_list - attribute: (attribute - (["<" ">"] @punctuation.bracket - (identifier) @attribute))) + (attribute + "<" @punctuation.bracket + (identifier) @attribute + ">" @punctuation.bracket)) -;; Labels +; Labels +(label_statement + (identifier) @label) -(label_statement (identifier) @label) - -(goto_statement (identifier) @label) - -;; Constants +(goto_statement + (identifier) @label) +; Constants ((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) (vararg_expression) @constant @@ -164,41 +160,49 @@ (true) ] @boolean -;; Tables +; Tables +(field + name: (identifier) @variable.member) -(field name: (identifier) @field) - -(dot_index_expression field: (identifier) @field) +(dot_index_expression + field: (identifier) @variable.member) (table_constructor -[ - "{" - "}" -] @constructor) + [ + "{" + "}" + ] @constructor) -;; Functions +; Functions +(parameters + (identifier) @variable.parameter) -(parameters (identifier) @parameter) +(vararg_expression) @variable.parameter.builtin (function_declaration - name: [ - (identifier) @function - (dot_index_expression - field: (identifier) @function) - ]) - -(function_declaration - name: (method_index_expression - method: (identifier) @method)) - -(assignment_statement - (variable_list . - name: [ + name: + [ (identifier) @function (dot_index_expression field: (identifier) @function) ]) - (expression_list . + +(function_declaration + name: + (method_index_expression + method: (identifier) @function.method)) + +(assignment_statement + (variable_list + . + name: + [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) + (expression_list + . value: (function_definition))) (table_constructor @@ -207,18 +211,20 @@ value: (function_definition))) (function_call - name: [ - (identifier) @function.call - (dot_index_expression - field: (identifier) @function.call) - (method_index_expression - method: (identifier) @method.call) - ]) + name: + [ + (identifier) @function.call + (dot_index_expression + field: (identifier) @function.call) + (method_index_expression + method: (identifier) @function.method.call) + ]) (function_call (identifier) @function.builtin + ; format-ignore (#any-of? @function.builtin - ;; built-in functions in Lua 5.1 + ; 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" @@ -227,8 +233,7 @@ "__idiv" "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" "__pairs" "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm")) -;; Others - +; Others (comment) @comment @spell ((comment) @comment.documentation @@ -237,13 +242,34 @@ ((comment) @comment.documentation (#lua-match? @comment.documentation "^[-][-](%s?)@")) -(hash_bang_line) @preproc +(hash_bang_line) @keyword.directive (number) @number -(string) @string @spell +(string) @string (escape_sequence) @string.escape -;; Error -(ERROR) @error +; string.match("123", "%d+") +(function_call + (dot_index_expression + field: (identifier) @_method + (#any-of? @_method "find" "match" "gmatch" "gsub")) + arguments: + (arguments + . + (_) + . + (string + content: (string_content) @string.regexp))) + +;("123"):match("%d+") +(function_call + (method_index_expression + method: (identifier) @_method + (#any-of? @_method "find" "match" "gmatch" "gsub")) + arguments: + (arguments + . + (string + content: (string_content) @string.regexp))) diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index dbfe75ae31..c8a1843c84 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -1,35 +1,130 @@ ((function_call - name: [ - (identifier) @_cdef_identifier - (_ _ (identifier) @_cdef_identifier) - ] + name: + [ + (identifier) @_cdef_identifier + (_ + _ + (identifier) @_cdef_identifier) + ] arguments: (arguments - (string content: _ @injection.content))) + (string + content: _ @injection.content))) (#set! injection.language "c") (#eq? @_cdef_identifier "cdef")) ((function_call name: (_) @_vimcmd_identifier - arguments: (arguments (string content: _ @injection.content))) + arguments: + (arguments + (string + content: _ @injection.content))) (#set! injection.language "vim") (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_command" "vim.api.nvim_exec2")) ((function_call name: (_) @_vimcmd_identifier - arguments: (arguments (string content: _ @injection.content) .)) + arguments: + (arguments + (string + content: _ @injection.content) .)) (#set! injection.language "query") (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse")) ((function_call name: (_) @_vimcmd_identifier - arguments: (arguments . (_) . (string content: _ @_method) . (string content: _ @injection.content))) + arguments: + (arguments + . + (_) + . + (string + content: _ @_method) + . + (string + content: _ @injection.content))) (#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify") (#eq? @_method "nvim_exec_lua") (#set! injection.language "lua")) -;; highlight string as query if starts with `;; query` -(string content: _ @injection.content - (#lua-match? @injection.content "^%s*;+%s?query") - (#set! injection.language "query")) +; vim.api.nvim_create_autocmd("FileType", { command = "injected here" }) +(function_call + name: (_) @_vimcmd_identifier + arguments: + (arguments + . + (_) + . + (table_constructor + (field + name: (identifier) @_command + value: + (string + content: (_) @injection.content))) .) + ; limit so only 2-argument functions gets matched before pred handle + (#eq? @_vimcmd_identifier "vim.api.nvim_create_autocmd") + (#eq? @_command "command") + (#set! injection.language "vim")) +(function_call + name: (_) @_user_cmd + arguments: + (arguments + . + (_) + . + (string + content: (_) @injection.content) + . + (_) .) + (#eq? @_user_cmd "vim.api.nvim_create_user_command") + (#set! injection.language "vim")) + +(function_call + name: (_) @_user_cmd + arguments: + (arguments + . + (_) + . + (_) + . + (string + content: (_) @injection.content) + . + (_) .) + ; Limiting predicate handling to only functions with 4 arguments + (#eq? @_user_cmd "vim.api.nvim_buf_create_user_command") + (#set! injection.language "vim")) + +; rhs highlighting for vim.keymap.set/vim.api.nvim_set_keymap/vim.api.nvim_buf_set_keymap +; (function_call +; name: (_) @_map +; arguments: +; (arguments +; . (_) +; . (_) +; . +; (string +; content: (_) @injection.content)) +; (#any-of? @_map "vim.api.nvim_set_keymap" "vim.keymap.set") +; (#set! injection.language "vim")) +; +; (function_call +; name: (_) @_map +; arguments: +; (arguments +; . (_) +; . (_) +; . (_) +; . +; (string +; content: (_) @injection.content) +; . (_) .) +; (#eq? @_map "vim.api.nvim_buf_set_keymap") +; (#set! injection.language "vim")) +; highlight string as query if starts with `;; query` +(string + content: _ @injection.content + (#lua-match? @injection.content "^%s*;+%s?query") + (#set! injection.language "query")) diff --git a/runtime/queries/markdown/folds.scm b/runtime/queries/markdown/folds.scm index 5900f7ffbe..a682e20e00 100644 --- a/runtime/queries/markdown/folds.scm +++ b/runtime/queries/markdown/folds.scm @@ -1,9 +1,7 @@ -( - [ - (fenced_code_block) - (indented_code_block) - (list) - (section) - ] @fold - (#trim! @fold) -) +([ + (fenced_code_block) + (indented_code_block) + (list) + (section) +] @fold + (#trim! @fold)) diff --git a/runtime/queries/markdown/highlights.scm b/runtime/queries/markdown/highlights.scm index 2cc5546bac..7c26fd710c 100644 --- a/runtime/queries/markdown/highlights.scm +++ b/runtime/queries/markdown/highlights.scm @@ -1,40 +1,73 @@ ;From MDeiml/tree-sitter-markdown & Helix -(setext_heading (paragraph) @text.title.1 (setext_h1_underline) @text.title.1.marker) -(setext_heading (paragraph) @text.title.2 (setext_h2_underline) @text.title.2.marker) +(setext_heading + (paragraph) @markup.heading.1 + (setext_h1_underline) @markup.heading.1.marker) -(atx_heading (atx_h1_marker) @text.title.1.marker (inline) @text.title.1) -(atx_heading (atx_h2_marker) @text.title.2.marker (inline) @text.title.2) -(atx_heading (atx_h3_marker) @text.title.3.marker (inline) @text.title.3) -(atx_heading (atx_h4_marker) @text.title.4.marker (inline) @text.title.4) -(atx_heading (atx_h5_marker) @text.title.5.marker (inline) @text.title.5) -(atx_heading (atx_h6_marker) @text.title.6.marker (inline) @text.title.6) +(setext_heading + (paragraph) @markup.heading.2 + (setext_h2_underline) @markup.heading.2.marker) -(link_title) @text.literal -(indented_code_block) @text.literal.block -((fenced_code_block) @text.literal.block (#set! "priority" 90)) +(atx_heading + (atx_h1_marker) @markup.heading.1.marker + (inline) @markup.heading.1) + +(atx_heading + (atx_h2_marker) @markup.heading.2.marker + (inline) @markup.heading.2) + +(atx_heading + (atx_h3_marker) @markup.heading.3.marker + (inline) @markup.heading.3) + +(atx_heading + (atx_h4_marker) @markup.heading.4.marker + (inline) @markup.heading.4) + +(atx_heading + (atx_h5_marker) @markup.heading.5.marker + (inline) @markup.heading.5) + +(atx_heading + (atx_h6_marker) @markup.heading.6.marker + (inline) @markup.heading.6) (info_string) @label -(pipe_table_header (pipe_table_cell) @text.title) +(pipe_table_header + (pipe_table_cell) @markup.heading) + +(pipe_table_header + "|" @punctuation.special) + +(pipe_table_row + "|" @punctuation.special) + +(pipe_table_delimiter_row + "|" @punctuation.special) -(pipe_table_header "|" @punctuation.special) -(pipe_table_row "|" @punctuation.special) -(pipe_table_delimiter_row "|" @punctuation.special) (pipe_table_delimiter_cell) @punctuation.special -[ - (fenced_code_block_delimiter) -] @punctuation.delimiter +; Code blocks (conceal backticks and language annotation) +(indented_code_block) @markup.raw.block -(code_fence_content) @none - -[ - (link_destination) -] @text.uri +((fenced_code_block) @markup.raw.block + (#set! "priority" 90)) + +(fenced_code_block + (fenced_code_block_delimiter) @markup.raw.delimiter + (#set! conceal "")) + +(fenced_code_block + (info_string + (language) @conceal + (#set! conceal ""))) + +(link_destination) @markup.link.url [ + (link_title) (link_label) -] @text.reference +] @markup.link.label [ (list_marker_plus) @@ -42,30 +75,43 @@ (list_marker_star) (list_marker_dot) (list_marker_parenthesis) - (thematic_break) -] @punctuation.special +] @markup.list +; NOTE: The following has been commented out due to issues with spaces in the +; list marker nodes generated by the parser. If those spaces ever get captured +; by a different node (e.g. block_continuation) we can safely readd these +; conceals. +; ;; Conceal bullet points +; ([(list_marker_plus) (list_marker_star)] +; @punctuation.special +; (#offset! @punctuation.special 0 0 0 -1) +; (#set! conceal "•")) +; ([(list_marker_plus) (list_marker_star)] +; @punctuation.special +; (#any-of? @punctuation.special "+" "*") +; (#set! conceal "•")) +; ((list_marker_minus) +; @punctuation.special +; (#offset! @punctuation.special 0 0 0 -1) +; (#set! conceal "—")) +; ((list_marker_minus) +; @punctuation.special +; (#eq? @punctuation.special "-") +; (#set! conceal "—")) +(thematic_break) @punctuation.special -(task_list_marker_unchecked) @text.todo.unchecked -(task_list_marker_checked) @text.todo.checked +(task_list_marker_unchecked) @markup.list.unchecked -(block_quote) @text.quote +(task_list_marker_checked) @markup.list.checked + +((block_quote) @markup.quote + (#set! "priority" 90)) [ (block_continuation) (block_quote_marker) ] @punctuation.special -[ - (backslash_escape) -] @string.escape +(backslash_escape) @string.escape (inline) @spell - -;; Conceal backticks -(fenced_code_block - (fenced_code_block_delimiter) @conceal - (#set! conceal "")) -(fenced_code_block - (info_string (language) @conceal - (#set! conceal ""))) diff --git a/runtime/queries/markdown/injections.scm b/runtime/queries/markdown/injections.scm index fda7036830..1f33c30b63 100644 --- a/runtime/queries/markdown/injections.scm +++ b/runtime/queries/markdown/injections.scm @@ -3,23 +3,23 @@ (language) @injection.language) (code_fence_content) @injection.content) -((html_block) @injection.content - (#set! injection.language "html") - (#set! injection.combined) - (#set! injection.include-children)) +((html_block) @injection.content + (#set! injection.language "html") + (#set! injection.combined) + (#set! injection.include-children)) -((minus_metadata) @injection.content - (#set! injection.language "yaml") - (#offset! @injection.content 1 0 -1 0) - (#set! injection.include-children)) +((minus_metadata) @injection.content + (#set! injection.language "yaml") + (#offset! @injection.content 1 0 -1 0) + (#set! injection.include-children)) -((plus_metadata) @injection.content - (#set! injection.language "toml") - (#offset! @injection.content 1 0 -1 0) - (#set! injection.include-children)) +((plus_metadata) @injection.content + (#set! injection.language "toml") + (#offset! @injection.content 1 0 -1 0) + (#set! injection.include-children)) ([ (inline) (pipe_table_cell) - ] @injection.content - (#set! injection.language "markdown_inline")) +] @injection.content + (#set! injection.language "markdown_inline")) diff --git a/runtime/queries/markdown_inline/highlights.scm b/runtime/queries/markdown_inline/highlights.scm index c75da478af..e9b41c31d5 100644 --- a/runtime/queries/markdown_inline/highlights.scm +++ b/runtime/queries/markdown_inline/highlights.scm @@ -1,49 +1,26 @@ -;; From MDeiml/tree-sitter-markdown -[ - (code_span) - (link_title) -] @text.literal @nospell +; From MDeiml/tree-sitter-markdown +(code_span) @markup.raw @nospell -[ - (emphasis_delimiter) - (code_span_delimiter) -] @punctuation.delimiter +(emphasis) @markup.italic -(emphasis) @text.emphasis +(strong_emphasis) @markup.strong -(strong_emphasis) @text.strong +(strikethrough) @markup.strikethrough -(strikethrough) @text.strike - -[ - (link_destination) - (uri_autolink) -] @text.uri @nospell - -(shortcut_link (link_text) @nospell) - -[ - (link_label) - (link_text) - (image_description) -] @text.reference +(shortcut_link + (link_text) @nospell) [ (backslash_escape) (hard_line_break) ] @string.escape -(image "!" @punctuation.special) -(image ["[" "]" "(" ")"] @punctuation.bracket) -(inline_link ["[" "]" "(" ")"] @punctuation.bracket) -(shortcut_link ["[" "]"] @punctuation.bracket) - ; Conceal codeblock and text style markers -([ - (code_span_delimiter) - (emphasis_delimiter) -] @conceal -(#set! conceal "")) +((code_span_delimiter) @markup.raw.delimiter + (#set! conceal "")) + +((emphasis_delimiter) @conceal + (#set! conceal "")) ; Conceal inline links (inline_link @@ -53,7 +30,7 @@ "(" (link_destination) ")" - ] @conceal + ] @markup.link (#set! conceal "")) ; Conceal image links @@ -65,7 +42,7 @@ "(" (link_destination) ")" - ] @conceal + ] @markup.link (#set! conceal "")) ; Conceal full reference links @@ -74,7 +51,7 @@ "[" "]" (link_label) - ] @conceal + ] @markup.link (#set! conceal "")) ; Conceal collapsed reference links @@ -82,7 +59,7 @@ [ "[" "]" - ] @conceal + ] @markup.link (#set! conceal "")) ; Conceal shortcut links @@ -90,13 +67,42 @@ [ "[" "]" - ] @conceal + ] @markup.link (#set! conceal "")) -;; Replace common HTML entities. -((entity_reference) @conceal (#eq? @conceal " ") (#set! conceal "")) -((entity_reference) @conceal (#eq? @conceal "<") (#set! conceal "<")) -((entity_reference) @conceal (#eq? @conceal ">") (#set! conceal ">")) -((entity_reference) @conceal (#eq? @conceal "&") (#set! conceal "&")) -((entity_reference) @conceal (#eq? @conceal """) (#set! conceal "\"")) -((entity_reference) @conceal (#any-of? @conceal " " " ") (#set! conceal " ")) +[ + (link_destination) + (uri_autolink) +] @markup.link.url @nospell + +[ + (link_label) + (link_text) + (link_title) + (image_description) +] @markup.link.label + +; Replace common HTML entities. +((entity_reference) @character.special + (#eq? @character.special " ") + (#set! conceal "")) + +((entity_reference) @character.special + (#eq? @character.special "<") + (#set! conceal "<")) + +((entity_reference) @character.special + (#eq? @character.special ">") + (#set! conceal ">")) + +((entity_reference) @character.special + (#eq? @character.special "&") + (#set! conceal "&")) + +((entity_reference) @character.special + (#eq? @character.special """) + (#set! conceal "\"")) + +((entity_reference) @character.special + (#any-of? @character.special " " " ") + (#set! conceal " ")) diff --git a/runtime/queries/markdown_inline/injections.scm b/runtime/queries/markdown_inline/injections.scm index f7aa19caff..6448b77c1b 100644 --- a/runtime/queries/markdown_inline/injections.scm +++ b/runtime/queries/markdown_inline/injections.scm @@ -1,8 +1,7 @@ ((html_tag) @injection.content - (#set! injection.language "html") - (#set! injection.combined) - (#set! injection.include-children)) + (#set! injection.language "html") + (#set! injection.combined)) ((latex_block) @injection.content - (#set! injection.language "latex") - (#set! injection.include-children)) + (#set! injection.language "latex") + (#set! injection.include-children)) diff --git a/runtime/queries/python/folds.scm b/runtime/queries/python/folds.scm index 78e1e2c00d..7c547db38f 100644 --- a/runtime/queries/python/folds.scm +++ b/runtime/queries/python/folds.scm @@ -1,28 +1,23 @@ [ (function_definition) (class_definition) - (while_statement) (for_statement) (if_statement) (with_statement) (try_statement) (match_statement) - (import_from_statement) (parameters) (argument_list) - (parenthesized_expression) (generator_expression) (list_comprehension) (set_comprehension) (dictionary_comprehension) - (tuple) (list) (set) (dictionary) - (string) ] @fold diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 04398668e9..764521c7be 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -1,183 +1,223 @@ -;; From tree-sitter-python licensed under MIT License +; From tree-sitter-python licensed under MIT License ; Copyright (c) 2016 Max Brunsfeld - ; Variables (identifier) @variable ; Reset highlighting in f-string interpolations (interpolation) @none -;; Identifier naming conventions +; Identifier naming conventions ((identifier) @type - (#lua-match? @type "^[A-Z].*[a-z]")) + (#lua-match? @type "^[A-Z].*[a-z]")) + ((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) ((identifier) @constant.builtin - (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) ((identifier) @constant.builtin - (#any-of? @constant.builtin - ;; https://docs.python.org/3/library/constants.html - "NotImplemented" - "Ellipsis" - "quit" - "exit" - "copyright" - "credits" - "license")) + ; format-ignore + (#any-of? @constant.builtin + ; https://docs.python.org/3/library/constants.html + "NotImplemented" "Ellipsis" + "quit" "exit" "copyright" "credits" "license")) "_" @constant.builtin ; match wildcard ((attribute - attribute: (identifier) @field) - (#lua-match? @field "^[%l_].*$")) + attribute: (identifier) @variable.member) + (#lua-match? @variable.member "^[%l_].*$")) ((assignment left: (identifier) @type.definition - (type (identifier) @_annotation)) - (#eq? @_annotation "TypeAlias")) + (type + (identifier) @_annotation)) + (#eq? @_annotation "TypeAlias")) ((assignment left: (identifier) @type.definition - right: (call - function: (identifier) @_func)) - (#any-of? @_func "TypeVar" "NewType")) + right: + (call + function: (identifier) @_func)) + (#any-of? @_func "TypeVar" "NewType")) ; Function calls - (call function: (identifier) @function.call) (call - function: (attribute - attribute: (identifier) @method.call)) + function: + (attribute + attribute: (identifier) @function.method.call)) ((call - function: (identifier) @constructor) - (#lua-match? @constructor "^%u")) + function: (identifier) @constructor) + (#lua-match? @constructor "^%u")) ((call - function: (attribute - attribute: (identifier) @constructor)) - (#lua-match? @constructor "^%u")) + function: + (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) -;; Decorators - -((decorator "@" @attribute) - (#set! "priority" 101)) +; Decorators +((decorator + "@" @attribute) + (#set! "priority" 101)) (decorator (identifier) @attribute) + (decorator (attribute attribute: (identifier) @attribute)) + (decorator - (call (identifier) @attribute)) + (call + (identifier) @attribute)) + (decorator - (call (attribute - attribute: (identifier) @attribute))) + (call + (attribute + attribute: (identifier) @attribute))) ((decorator (identifier) @attribute.builtin) - (#any-of? @attribute.builtin "classmethod" "property")) - -;; Builtin functions + (#any-of? @attribute.builtin "classmethod" "property")) +; Builtin functions ((call function: (identifier) @function.builtin) - (#any-of? @function.builtin - "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" "classmethod" - "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" "filter" "float" "format" - "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance" "issubclass" - "iter" "len" "list" "locals" "map" "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow" - "print" "property" "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" - "sum" "super" "tuple" "type" "vars" "zip" "__import__")) - -;; Function definitions + (#any-of? @function.builtin "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip" "__import__")) +; Function definitions (function_definition name: (identifier) @function) -(type (identifier) @type) +(type + (identifier) @type) + (type (subscript (identifier) @type)) ; type subscript: Tuple[int] ((call function: (identifier) @_isinstance - arguments: (argument_list - (_) - (identifier) @type)) - (#eq? @_isinstance "isinstance")) + arguments: + (argument_list + (_) + (identifier) @type)) + (#eq? @_isinstance "isinstance")) -;; Normal parameters +; Normal parameters (parameters - (identifier) @parameter) -;; Lambda parameters + (identifier) @variable.parameter) + +; Lambda parameters (lambda_parameters - (identifier) @parameter) + (identifier) @variable.parameter) + (lambda_parameters (tuple_pattern - (identifier) @parameter)) + (identifier) @variable.parameter)) + ; Default parameters (keyword_argument - name: (identifier) @parameter) + name: (identifier) @variable.parameter) + ; Naming parameters on call-site (default_parameter - name: (identifier) @parameter) + name: (identifier) @variable.parameter) + (typed_parameter - (identifier) @parameter) + (identifier) @variable.parameter) + (typed_default_parameter - (identifier) @parameter) + name: (identifier) @variable.parameter) + ; Variadic parameters *args, **kwargs (parameters (list_splat_pattern ; *args - (identifier) @parameter)) + (identifier) @variable.parameter)) + (parameters (dictionary_splat_pattern ; **kwargs - (identifier) @parameter)) + (identifier) @variable.parameter)) +; Typed variadic parameters +(parameters + (typed_parameter + (list_splat_pattern ; *args: type + (identifier) @variable.parameter))) -;; Literals +(parameters + (typed_parameter + (dictionary_splat_pattern ; *kwargs: type + (identifier) @variable.parameter))) +; Lambda parameters +(lambda_parameters + (list_splat_pattern + (identifier) @variable.parameter)) + +(lambda_parameters + (dictionary_splat_pattern + (identifier) @variable.parameter)) + +; Literals (none) @constant.builtin -[(true) (false)] @boolean + +[ + (true) + (false) +] @boolean + ((identifier) @variable.builtin - (#eq? @variable.builtin "self")) + (#eq? @variable.builtin "self")) + ((identifier) @variable.builtin - (#eq? @variable.builtin "cls")) + (#eq? @variable.builtin "cls")) (integer) @number -(float) @float + +(float) @number.float (comment) @comment @spell -((module . (comment) @preproc) - (#lua-match? @preproc "^#!/")) +((module + . + (comment) @keyword.directive) + (#lua-match? @keyword.directive "^#!/")) (string) @string + [ (escape_sequence) (escape_interpolation) ] @string.escape ; doc-strings - -(module . (expression_statement (string) @string.documentation @spell)) +(module + . + (expression_statement + (string) @string.documentation @spell)) (class_definition body: (block - . (expression_statement (string) @string.documentation @spell))) + . + (expression_statement + (string) @string.documentation @spell))) (function_definition body: (block - . (expression_statement (string) @string.documentation @spell))) + . + (expression_statement + (string) @string.documentation @spell))) ; Tokens - [ "-" "-=" @@ -227,7 +267,6 @@ "or" "is not" "not in" - "del" ] @keyword.operator @@ -258,19 +297,36 @@ "return" "yield" ] @keyword.return -(yield "from" @keyword.return) + +(yield + "from" @keyword.return) (future_import_statement - "from" @include + "from" @keyword.import "__future__" @constant.builtin) -(import_from_statement "from" @include) -"import" @include -(aliased_import "as" @include) +(import_from_statement + "from" @keyword.import) -["if" "elif" "else" "match" "case"] @conditional +"import" @keyword.import -["for" "while" "break" "continue"] @repeat +(aliased_import + "as" @keyword.import) + +[ + "if" + "elif" + "else" + "match" + "case" +] @keyword.conditional + +[ + "for" + "while" + "break" + "continue" +] @keyword.repeat [ "try" @@ -278,15 +334,23 @@ "except*" "raise" "finally" -] @exception +] @keyword.exception -(raise_statement "from" @exception) +(raise_statement + "from" @keyword.exception) (try_statement (else_clause - "else" @exception)) + "else" @keyword.exception)) -["(" ")" "[" "]" "{" "}"] @punctuation.bracket +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket (interpolation "{" @punctuation.special @@ -294,58 +358,80 @@ (type_conversion) @function.macro -["," "." ":" ";" (ellipsis)] @punctuation.delimiter +[ + "," + "." + ":" + ";" + (ellipsis) +] @punctuation.delimiter -;; Class definitions - -(class_definition name: (identifier) @type) +; Class definitions +(class_definition + name: (identifier) @type) (class_definition - body: (block - (function_definition - name: (identifier) @method))) + body: + (block + (function_definition + name: (identifier) @function.method))) (class_definition - superclasses: (argument_list - (identifier) @type)) + superclasses: + (argument_list + (identifier) @type)) ((class_definition - body: (block - (expression_statement - (assignment - left: (identifier) @field)))) - (#lua-match? @field "^%l.*$")) + body: + (block + (expression_statement + (assignment + left: (identifier) @variable.member)))) + (#lua-match? @variable.member "^%l.*$")) + ((class_definition - body: (block - (expression_statement - (assignment - left: (_ - (identifier) @field))))) - (#lua-match? @field "^%l.*$")) + body: + (block + (expression_statement + (assignment + left: + (_ + (identifier) @variable.member))))) + (#lua-match? @variable.member "^%l.*$")) ((class_definition (block (function_definition name: (identifier) @constructor))) - (#any-of? @constructor "__new__" "__init__")) + (#any-of? @constructor "__new__" "__init__")) ((identifier) @type.builtin - (#any-of? @type.builtin - ;; https://docs.python.org/3/library/exceptions.html - "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError" - "EOFError" "FloatingPointError" "GeneratorExit" "ImportError" "ModuleNotFoundError" "IndexError" "KeyError" - "KeyboardInterrupt" "MemoryError" "NameError" "NotImplementedError" "OSError" "OverflowError" "RecursionError" - "ReferenceError" "RuntimeError" "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" - "SystemError" "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" "UnicodeDecodeError" - "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" "IOError" "WindowsError" - "BlockingIOError" "ChildProcessError" "ConnectionError" "BrokenPipeError" "ConnectionAbortedError" - "ConnectionRefusedError" "ConnectionResetError" "FileExistsError" "FileNotFoundError" "InterruptedError" - "IsADirectoryError" "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning" - "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning" - "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning" - ;; https://docs.python.org/3/library/stdtypes.html - "bool" "int" "float" "complex" "list" "tuple" "range" "str" - "bytes" "bytearray" "memoryview" "set" "frozenset" "dict" "type" "object")) + ; format-ignore + (#any-of? @type.builtin + ; https://docs.python.org/3/library/exceptions.html + "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError" + "EOFError" "FloatingPointError" "GeneratorExit" "ImportError" "ModuleNotFoundError" "IndexError" "KeyError" + "KeyboardInterrupt" "MemoryError" "NameError" "NotImplementedError" "OSError" "OverflowError" "RecursionError" + "ReferenceError" "RuntimeError" "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" + "SystemError" "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" "UnicodeDecodeError" + "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" "IOError" "WindowsError" + "BlockingIOError" "ChildProcessError" "ConnectionError" "BrokenPipeError" "ConnectionAbortedError" + "ConnectionRefusedError" "ConnectionResetError" "FileExistsError" "FileNotFoundError" "InterruptedError" + "IsADirectoryError" "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning" + "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning" + "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning" + ; https://docs.python.org/3/library/stdtypes.html + "bool" "int" "float" "complex" "list" "tuple" "range" "str" + "bytes" "bytearray" "memoryview" "set" "frozenset" "dict" "type" "object")) -;; Error -(ERROR) @error +; Regex from the `re` module +(call + function: + (attribute + object: (identifier) @_re) + arguments: + (argument_list + . + (string + (string_content) @string.regexp)) + (#eq? @_re "re")) diff --git a/runtime/queries/query/highlights.scm b/runtime/queries/query/highlights.scm index f2d2ef6c7f..cdedb23e29 100644 --- a/runtime/queries/query/highlights.scm +++ b/runtime/queries/query/highlights.scm @@ -1,14 +1,30 @@ (string) @string + (escape_sequence) @string.escape -(capture (identifier) @type) -(anonymous_node (identifier) @string) -(predicate name: (identifier) @function) -(named_node name: (identifier) @variable) -(field_definition name: (identifier) @property) -(negated_field "!" @operator (identifier) @property) + +(capture + (identifier) @type) + +(anonymous_node + (identifier) @string) + +(predicate + name: (identifier) @function.call) + +(named_node + name: (identifier) @variable) + +(field_definition + name: (identifier) @property) + +(negated_field + "!" @operator + (identifier) @property) + (comment) @comment @spell (quantifier) @operator + (predicate_type) @punctuation.special "." @operator @@ -21,14 +37,51 @@ ] @punctuation.bracket ":" @punctuation.delimiter -["@" "#"] @punctuation.special + +[ + "@" + "#" +] @punctuation.special + "_" @constant -((parameters (identifier) @number) - (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) +((parameters + (identifier) @number) + (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) -((program . (comment)* . (comment) @include) - (#lua-match? @include "^;+ *inherits *:")) +((program + . + (comment)* + . + (comment) @keyword.import) + (#lua-match? @keyword.import "^;+ *inherits *:")) -((program . (comment)* . (comment) @preproc) - (#lua-match? @preproc "^;+ *extends")) +((program + . + (comment)* + . + (comment) @keyword.directive) + (#lua-match? @keyword.directive "^;+ *extends *$")) + +((comment) @keyword.directive + (#lua-match? @keyword.directive "^;+%s*format%-ignore%s*$")) + +((predicate + name: (identifier) @_name + parameters: + (parameters + (string + "\"" @string + "\"" @string) @string.regexp)) + (#any-of? @_name "match" "not-match" "vim-match" "not-vim-match" "lua-match" "not-lua-match")) + +((predicate + name: (identifier) @_name + parameters: + (parameters + (string + "\"" @string + "\"" @string) @string.regexp + . + (string) .)) + (#any-of? @_name "gsub" "not-gsub")) 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 + (#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) -[ (bang) (spread) ] @punctuation.special +(call_expression + function: (identifier) @function.call) + +(call_expression + function: + (scoped_identifier + (identifier) @function.call)) + +(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 command +(filetype_statement + [ + "detect" + "plugin" + "indent" + "on" + "off" + ] @keyword) -(filetype_statement [ - "detect" - "plugin" - "indent" - "on" - "off" -] @keyword) +; Syntax command +(syntax_statement + (keyword) @string) -;; Syntax command +(syntax_statement + [ + "enable" + "on" + "off" + "reset" + "case" + "spell" + "foldlevel" + "iskeyword" + "keyword" + "match" + "cluster" + "region" + "clear" + "include" + ] @keyword) -(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) +(syntax_argument + name: _ @keyword) [ "" @@ -151,69 +178,95 @@ "" ] @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 +(plus_cmd + "+" @property) @property -(runtime_statement (where) @keyword.operator) +; Runtime command +(runtime_statement + (where) @keyword.operator) -;; Colorscheme command +; Colorscheme command +(colorscheme_statement + (name) @string) -(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) + +(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 + (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) +(binary_operation + "." @operator) -;; Punctuation - +; 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) -(set_item "?" @operator) +(inv_option + "!" @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")) diff --git a/runtime/queries/vimdoc/highlights.scm b/runtime/queries/vimdoc/highlights.scm index e0dce49b2a..294fa94f10 100644 --- a/runtime/queries/vimdoc/highlights.scm +++ b/runtime/queries/vimdoc/highlights.scm @@ -1,25 +1,58 @@ -(h1) @text.title.1 -(h2) @text.title.2 -(h3) @text.title.3 -(column_heading) @text.title.4 +(h1) @markup.heading.1 + +(h2) @markup.heading.2 + +(h3) @markup.heading.3 + +(column_heading) @markup.heading.4 + (column_heading - "~" @conceal (#set! conceal "")) + "~" @markup.heading.4.marker + (#set! conceal "")) + (tag - "*" @conceal (#set! conceal "") - text: (_) @label) + "*" @markup.heading.5.marker + (#set! conceal "") + text: (_) @label) + (taglink - "|" @conceal (#set! conceal "") - text: (_) @text.reference) + "|" @markup.link + (#set! conceal "") + text: (_) @markup.link) + (optionlink - text: (_) @text.reference) + text: (_) @markup.link) + (codespan - "`" @conceal (#set! conceal "") - text: (_) @text.literal) -(codeblock) @text.literal + "`" @markup.raw.delimiter + (#set! conceal "") + text: (_) @markup.raw) + +((codeblock) @markup.raw.block + (#set! "priority" 90)) + (codeblock - [">" (language)] @conceal (#set! conceal "")) + [ + ">" + (language) + ] @markup.raw.delimiter + (#set! conceal "")) + (block - "<" @conceal (#set! conceal "")) -(argument) @parameter + "<" @markup.raw.delimiter + (#set! conceal "")) + +(argument) @variable.parameter + (keycode) @string.special -(url) @text.uri + +(url) @string.special.url + +((note) @comment.note + (#any-of? @comment.note "Note:" "NOTE:" "Notes:")) + +((note) @comment.warning + (#any-of? @comment.warning "Warning:" "WARNING:")) + +((note) @comment.error + (#any-of? @comment.error "Deprecated:" "DEPRECATED:")) diff --git a/runtime/queries/vimdoc/injections.scm b/runtime/queries/vimdoc/injections.scm index 260a05d863..3b8fbf0f36 100644 --- a/runtime/queries/vimdoc/injections.scm +++ b/runtime/queries/vimdoc/injections.scm @@ -1,4 +1,4 @@ ((codeblock (language) @injection.language (code) @injection.content) - (#set! injection.include-children)) + (#set! injection.include-children)) diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 9c12a5bda1..e9fd1c3f44 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -230,60 +230,98 @@ static const char *highlight_init_both[] = { "default link DiagnosticSignOk DiagnosticOk", "default link DiagnosticUnnecessary Comment", - // Text - "default link @text.literal Comment", - "default link @text.reference Identifier", - "default link @text.title Title", - "default link @text.uri Underlined", - "default link @text.underline Underlined", - "default link @text.todo Todo", + // Treesitter standard groups + "default link @variable NONE", // don't highlight to reduce visual overload + "default link @variable.builtin Special", + "default link @variable.parameter Identifier", + "default link @variable.member Identifier", - // Miscs - "default link @comment Comment", - "default link @punctuation Delimiter", - - // Constants "default link @constant Constant", "default link @constant.builtin Special", "default link @constant.macro Define", - "default link @define Define", - "default link @macro Macro", - "default link @string String", - "default link @string.escape SpecialChar", - "default link @string.special SpecialChar", - "default link @character Character", - "default link @character.special SpecialChar", - "default link @number Number", - "default link @boolean Boolean", - "default link @float Float", - // Functions - "default link @function Function", - "default link @function.builtin Special", - "default link @function.macro Macro", - "default link @parameter Identifier", - "default link @method Function", - "default link @field Identifier", - "default link @property Identifier", - "default link @constructor Special", + "default link @module Structure", + "default link @label Label", - // Keywords - "default link @conditional Conditional", - "default link @repeat Repeat", - "default link @label Label", - "default link @operator Operator", - "default link @keyword Keyword", - "default link @exception Exception", + "default link @string String", + "default link @string.regexp SpecialChar", + "default link @string.escape SpecialChar", + "default link @string.special SpecialChar", + "default link @string.special.symbol Constant", + "default link @string.special.url Underlined", - "default link @variable NONE", // don't highlight to reduce visual overload - "default link @type Type", - "default link @type.definition Typedef", - "default link @storageclass StorageClass", - "default link @namespace Identifier", - "default link @include Include", - "default link @preproc PreProc", - "default link @debug Debug", - "default link @tag Tag", + "default link @character Character", + "default link @character.special SpecialChar", + + "default link @boolean Boolean", + "default link @number Number", + "default link @number.float Float", + + "default link @type Type", + "default link @type.builtin Special", + "default link @type.definition Typedef", + "default link @type.qualifier StorageClass", + + "default link @attribute Macro", + "default link @property Identifier", + + "default link @function Function", + "default link @function.builtin Special", + "default link @function.macro Macro", + + "default link @constructor Special", + "default link @operator Operator", + + "default link @keyword Keyword", + "default link @keyword.function Statement", + "default link @keyword.operator Operator", + "default link @keyword.import Include", + "default link @keyword.storage StorageClass", + "default link @keyword.repeat Repeat", + "default link @keyword.debug Debug", + "default link @keyword.exception Exception", + + "default link @keyword.conditional Conditional", + + "default link @keyword.directive Preproc", + "default link @keyword.directive.define Define", + + "default link @punctuation.delimiter Delimiter", + "default link @punctuation.bracket Delimiter", + "default link @punctuation.special Special", + + "default link @comment Comment", + + "default link @comment.error DiagnosticError", + "default link @comment.warning DiagnosticWarn", + "default link @comment.note DiagnosticInfo", + "default link @comment.todo Todo", + + "@markup.strong gui=bold cterm=bold", + "@markup.italic gui=italic cterm=italic", + "@markup.strikethrough gui=strikethrough, cterm=strikethrough", + "@markup.underline gui=underline, cterm=underline", + + "default link @markup.heading Title", + + "default link @markup.raw Comment", + "default link @markup.quote Comment", + "default link @markup.math Comment", + "default link @markup.environment Comment", + + "default link @markup.link Underlined", + "default link @markup.link.label Identifier", + + "default link @markup.list Special", + "default link @markup.list.checked DiagnosticOk", + "default link @markup.list.unchecked DiagnosticWarn", + + "default link @diff.plus Added", + "default link @diff.minus Removed", + "default link @diff.delta Changed", + + "default link @tag Tag", + "default link @tag.delimiter Delimiter", // LSP semantic tokens "default link @lsp.type.class Structure", diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua index 2302cf869e..ac9d227bb6 100644 --- a/test/functional/treesitter/fold_spec.lua +++ b/test/functional/treesitter/fold_spec.lua @@ -729,7 +729,7 @@ void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, con feed('ggVGzf') screen:expect { grid = [[ - {2:^void}{1: }{3:qsort}{4:(}{2:void}{1: }{5:*}{3:base}{4:,}{1: }{2:size_t}{1: }{3:nel}{4:,}{1: }{2:size_t}{1: }{3:width}{4:,}{1: }{2:int}{1: }{4:(}{5:*}{3:compa}| + {4:^void}{1: }{3:qsort}{4:(void}{1: }{5:*}{3:base}{4:,}{1: }{4:size_t}{1: }{3:nel}{4:,}{1: }{4:size_t}{1: }{3:width}{4:,}{1: }{4:int}{1: }{4:(}{5:*}{3:compa}| {0:~ }|*3 | ]], diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index f4f7bc691c..932af0332b 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -766,7 +766,7 @@ describe('treesitter highlighting (help)', function() {1:>ruby} | {1: -- comment} | {1: local this_is = 'actually_lua'} | - < | + {1:<} | ^ | | ]], @@ -779,7 +779,7 @@ describe('treesitter highlighting (help)', function() {1:>lua} | {1: -- comment} | {1: }{3:local}{1: }{4:this_is}{1: }{3:=}{1: }{5:'actually_lua'} | - < | + {1:<} | ^ | | ]], @@ -792,7 +792,7 @@ describe('treesitter highlighting (help)', function() {1:>ruby} | {1: -- comment} | {1: local this_is = 'actually_lua'} | - < | + {1:<} | ^ | | ]], diff --git a/test/old/testdir/test_syntax.vim b/test/old/testdir/test_syntax.vim index 10dc798df7..711b2adf7c 100644 --- a/test/old/testdir/test_syntax.vim +++ b/test/old/testdir/test_syntax.vim @@ -197,14 +197,14 @@ func Test_syntax_completion() " Check that clearing "Aap" avoids it showing up before Boolean. hi @Aap ctermfg=blue call feedkeys(":syn list \\\"\", 'tx') - call assert_match('^"syn list @Aap @boolean @character ', @:) + call assert_match('^"syn list @Aap @attribute @boolean @character ', @:) hi clear @Aap call feedkeys(":syn list \\\"\", 'tx') - call assert_match('^"syn list @boolean @character ', @:) + call assert_match('^"syn list @attribute @boolean @character ', @:) call feedkeys(":syn match \\\"\", 'tx') - call assert_match('^"syn match @boolean @character ', @:) + call assert_match('^"syn match @attribute @boolean @character ', @:) syn cluster Aax contains=Aap call feedkeys(":syn list @A\\\"\", 'tx')