diff options
Diffstat (limited to 'runtime/queries')
21 files changed, 1249 insertions, 734 deletions
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..b4360ce7e1 100644 --- a/runtime/queries/bash/highlights.scm +++ b/runtime/queries/bash/highlights.scm @@ -1,81 +1,108 @@ -(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. [ - ">" - ">>" - "<" - "<<" - "&" - "&&" - "|" - "||" - "=" - "=~" - "==" - "!=" - ] @operator + (string) + (raw_string) + (ansi_c_string) + (heredoc_body) +] @string [ - (string) - (raw_string) - (ansi_c_string) - (heredoc_body) -] @string @spell + (heredoc_start) + (heredoc_end) +] @label + +(variable_assignment + (word) @string) + +(command + argument: "$" @string) ; bare dollar -(variable_assignment (word) @string) +(concatenation + [ + (simple_expansion) + (expansion) + ] + (word) @string) [ - "if" - "then" - "else" - "elif" - "fi" - "case" - "in" - "esac" - ] @conditional + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" +] @keyword.conditional [ - "for" - "do" - "done" - "select" - "until" - "while" - ] @repeat + "for" + "do" + "done" + "select" + "until" + "while" +] @keyword.repeat [ - "declare" - "export" - "local" - "readonly" - "unset" - ] @keyword + "declare" + "typeset" + "export" + "readonly" + "local" + "unset" + "unsetenv" +] @keyword "function" @keyword.function @@ -83,28 +110,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 +171,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.special + "}" @punctuation.special) @none (expansion - [ "${" "}" ] @punctuation.bracket) + 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) - -(regex) @string.regex + value: (word) @variable.parameter) -((program . (comment) @preproc) - (#lua-match? @preproc "^#!/")) +[ + (regex) + (extglob_pattern) +] @string.regexp + +((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) - -(preproc_params (identifier) @parameter) + declarator: (pointer_declarator) @variable.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))) - -;; Labels + (attribute + "<" @punctuation.bracket + (identifier) @attribute + ">" @punctuation.bracket)) -(label_statement (identifier) @label) +; Labels +(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 - -(field name: (identifier) @field) +; Tables +(field + name: (identifier) @variable.member) -(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) - -(function_declaration - name: [ - (identifier) @function - (dot_index_expression - field: (identifier) @function) - ]) +(vararg_expression) @variable.parameter.builtin (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 +((fenced_code_block) @markup.raw.block + (#set! "priority" 90)) -[ - (link_destination) -] @text.uri +(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 - - -(task_list_marker_unchecked) @text.todo.unchecked -(task_list_marker_checked) @text.todo.checked - -(block_quote) @text.quote +] @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) @markup.list.unchecked + +(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 - -[ - (emphasis_delimiter) - (code_span_delimiter) -] @punctuation.delimiter - -(emphasis) @text.emphasis +; From MDeiml/tree-sitter-markdown +(code_span) @markup.raw @nospell -(strong_emphasis) @text.strong +(emphasis) @markup.italic -(strikethrough) @text.strike - -[ - (link_destination) - (uri_autolink) -] @text.uri @nospell +(strong_emphasis) @markup.strong -(shortcut_link (link_text) @nospell) +(strikethrough) @markup.strikethrough -[ - (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")) - -;; Decorators + function: + (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) -((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) + +"import" @keyword.import -["if" "elif" "else" "match" "case"] @conditional +(aliased_import + "as" @keyword.import) -["for" "while" "break" "continue"] @repeat +[ + "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 - -;; Class definitions - -(class_definition name: (identifier) @type) +[ + "," + "." + ":" + ";" + (ellipsis) +] @punctuation.delimiter + +; 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")) - -;; Error -(ERROR) @error + ; 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")) + +; 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) @keyword.import) + (#lua-match? @keyword.import "^;+ *inherits *:")) + +((program + . + (comment)* + . + (comment) @keyword.directive) + (#lua-match? @keyword.directive "^;+ *extends *$")) + +((comment) @keyword.directive + (#lua-match? @keyword.directive "^;+%s*format%-ignore%s*$")) -((program . (comment)* . (comment) @include) - (#lua-match? @include "^;+ *inherits *:")) +((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")) -((program . (comment)* . (comment) @preproc) - (#lua-match? @preproc "^;+ *extends")) +((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 +((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")) 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)) |