diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:39:54 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:39:54 +0000 |
commit | 21cb7d04c387e4198ca8098a884c78b56ffcf4c2 (patch) | |
tree | 84fe5690df1551f0bb2bdfe1a13aacd29ebc1de7 /runtime/queries | |
parent | d9c904f85a23a496df4eb6be42aa43f007b22d50 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-colorcolchar.tar.gz rneovim-colorcolchar.tar.bz2 rneovim-colorcolchar.zip |
Merge remote-tracking branch 'upstream/master' into colorcolcharcolorcolchar
Diffstat (limited to 'runtime/queries')
23 files changed, 1122 insertions, 100 deletions
diff --git a/runtime/queries/bash/folds.scm b/runtime/queries/bash/folds.scm new file mode 100644 index 0000000000..851c67eed4 --- /dev/null +++ b/runtime/queries/bash/folds.scm @@ -0,0 +1,8 @@ +[ + (function_definition) + (if_statement) + (case_statement) + (for_statement) + (while_statement) + (c_style_for_statement) +] @fold diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm new file mode 100644 index 0000000000..23bf03e697 --- /dev/null +++ b/runtime/queries/bash/highlights.scm @@ -0,0 +1,145 @@ +(simple_expansion) @none +(expansion + "${" @punctuation.special + "}" @punctuation.special) @none +[ + "(" + ")" + "((" + "))" + "{" + "}" + "[" + "]" + "[[" + "]]" + ] @punctuation.bracket + +[ + ";" + ";;" + (heredoc_start) + ] @punctuation.delimiter + +[ + "$" +] @punctuation.special + +[ + ">" + ">>" + "<" + "<<" + "&" + "&&" + "|" + "||" + "=" + "=~" + "==" + "!=" + ] @operator + +[ + (string) + (raw_string) + (ansi_c_string) + (heredoc_body) +] @string @spell + +(variable_assignment (word) @string) + +[ + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" + ] @conditional + +[ + "for" + "do" + "done" + "select" + "until" + "while" + ] @repeat + +[ + "declare" + "export" + "local" + "readonly" + "unset" + ] @keyword + +"function" @keyword.function + +(special_variable_name) @constant + +; 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]))?)$")) + +((word) @boolean + (#any-of? @boolean "true" "false")) + +(comment) @comment @spell +(test_operator) @string + +(command_substitution + [ "$(" ")" ] @punctuation.bracket) + +(process_substitution + [ "<(" ")" ] @punctuation.bracket) + + +(function_definition + name: (word) @function) + +(command_name (word) @function.call) + +((command_name (word) @function.builtin) + (#any-of? @function.builtin + "alias" "bg" "bind" "break" "builtin" "caller" "cd" + "command" "compgen" "complete" "compopt" "continue" + "coproc" "dirs" "disown" "echo" "enable" "eval" + "exec" "exit" "fc" "fg" "getopts" "hash" "help" + "history" "jobs" "kill" "let" "logout" "mapfile" + "popd" "printf" "pushd" "pwd" "read" "readarray" + "return" "set" "shift" "shopt" "source" "suspend" + "test" "time" "times" "trap" "type" "typeset" + "ulimit" "umask" "unalias" "wait")) + +(command + argument: [ + (word) @parameter + (concatenation (word) @parameter) + ]) + +((word) @number + (#lua-match? @number "^[0-9]+$")) + +(file_redirect + descriptor: (file_descriptor) @operator + destination: (word) @parameter) + +(expansion + [ "${" "}" ] @punctuation.bracket) + +(variable_name) @variable + +((variable_name) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +(case_item + value: (word) @parameter) + +(regex) @string.regex + +((program . (comment) @preproc) + (#lua-match? @preproc "^#!/")) diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm new file mode 100644 index 0000000000..5a35334a24 --- /dev/null +++ b/runtime/queries/c/folds.scm @@ -0,0 +1,20 @@ +[ + (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) +] @fold + +(compound_statement + (compound_statement) @fold) diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 33e6df74ab..29fb5747ca 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,23 +1,27 @@ -(identifier) @variable +; Lower priority to prefer @parameter when identifier appears in parameter_declaration. +((identifier) @variable (#set! "priority" 95)) +(preproc_def (preproc_arg) @variable) [ - "const" "default" "enum" - "extern" - "inline" - "return" - "sizeof" - "static" "struct" "typedef" "union" - "volatile" "goto" - "register" + "asm" + "__asm__" ] @keyword [ + "sizeof" + "offsetof" +] @keyword.operator +(alignof_expression . _ @keyword.operator) + +"return" @keyword.return + +[ "while" "for" "do" @@ -32,7 +36,6 @@ "switch" ] @conditional -"#define" @constant.macro [ "#if" "#ifdef" @@ -40,11 +43,21 @@ "#else" "#elif" "#endif" + "#elifdef" + "#elifndef" (preproc_directive) -] @keyword +] @preproc + +"#define" @define "#include" @include +[ ";" ":" "," "::" ] @punctuation.delimiter + +"..." @punctuation.special + +[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket + [ "=" @@ -62,6 +75,7 @@ ">>" "->" + "." "<" "<=" @@ -88,56 +102,110 @@ "++" ] @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) + (true) + (false) ] @boolean -[ "." ";" ":" "," ] @punctuation.delimiter - -(conditional_expression [ "?" ":" ] @conditional) - - -[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket +(conditional_expression [ "?" ":" ] @conditional.ternary) (string_literal) @string -(string_literal) @spell (system_lib_string) @string +(escape_sequence) @string.escape (null) @constant.builtin (number_literal) @number -(char_literal) @number +(char_literal) @character -(call_expression - function: (identifier) @function) -(call_expression - function: (field_expression - field: (field_identifier) @function)) -(function_declarator - declarator: (identifier) @function) -(preproc_function_def - name: (identifier) @function.macro) -[ - (preproc_arg) - (preproc_defined) -] @function.macro +((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_designator) @property +(((field_identifier) @property) + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) -(field_identifier) @property (statement_identifier) @label [ -(type_identifier) -(primitive_type) -(sized_type_specifier) -(type_descriptor) - ] @type + (type_identifier) + (type_descriptor) +] @type + +(storage_class_specifier) @storageclass + +[ + (type_qualifier) + (gnu_asm_qualifier) + "__extension__" +] @type.qualifier + +(linkage_specification + "extern" @storageclass) -(declaration (type_qualifier) @type) -(cast_expression type: (type_descriptor) @type) -(sizeof_expression value: (parenthesized_expression (identifier) @type)) +(type_definition + declarator: (type_identifier) @type.definition) + +(primitive_type) @type.builtin + +(sized_type_specifier _ @type.builtin type: _?) ((identifier) @constant - (#match? @constant "^[A-Z][A-Z0-9_]+$")) + (#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 + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) +(preproc_def (preproc_arg) @constant.builtin + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(attribute_specifier + (argument_list (identifier) @variable.builtin)) +((attribute_specifier + (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) + (#has-ancestor? @function.builtin attribute_specifier)) ;; Preproc def / undef (preproc_def @@ -147,18 +215,49 @@ argument: (_) @constant (#eq? @_u "#undef")) +(call_expression + function: (identifier) @function.call) +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) +(function_declarator + declarator: (identifier) @function) +(function_declarator + declarator: (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment @spell -(comment) @comment -(comment) @spell +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) ;; Parameters (parameter_declaration declarator: (identifier) @parameter) (parameter_declaration + declarator: (array_declarator) @parameter) + +(parameter_declaration declarator: (pointer_declarator) @parameter) -(preproc_params - (identifier)) @parameter +(preproc_params (identifier) @parameter) + +[ + "__attribute__" + "__declspec" + "__based" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + (ms_pointer_modifier) + (attribute_declaration) +] @attribute (ERROR) @error diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 7e9e73449d..5a49e20df5 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,3 +1,21 @@ -(preproc_arg) @c +((preproc_def + (preproc_arg) @injection.content) + (#lua-match? @injection.content "\n") + (#set! injection.language "c")) -; (comment) @comment +(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")) diff --git a/runtime/queries/help/injections.scm b/runtime/queries/help/injections.scm deleted file mode 100644 index 09bbe44e84..0000000000 --- a/runtime/queries/help/injections.scm +++ /dev/null @@ -1,3 +0,0 @@ -(codeblock - (language) @language - (code) @content) diff --git a/runtime/queries/lua/folds.scm b/runtime/queries/lua/folds.scm new file mode 100644 index 0000000000..d8f0b42df3 --- /dev/null +++ b/runtime/queries/lua/folds.scm @@ -0,0 +1,10 @@ +[ + (do_statement) + (while_statement) + (repeat_statement) + (if_statement) + (for_statement) + (function_declaration) + (function_definition) + (table_constructor) +] @fold diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 2c0dc5447a..96ffeae793 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -8,8 +8,6 @@ "local" ] @keyword -(label_statement) @label - (break_statement) @keyword (do_statement @@ -109,6 +107,7 @@ [ ";" ":" + "::" "," "." ] @punctuation.delimiter @@ -128,13 +127,28 @@ (identifier) @variable +((identifier) @constant.builtin + (#eq? @constant.builtin "_VERSION")) + ((identifier) @variable.builtin - (#eq? @variable.builtin "self")) + (#eq? @variable.builtin "self")) + +((identifier) @namespace.builtin + (#any-of? @namespace.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: (attribute + (["<" ">"] @punctuation.bracket + (identifier) @attribute))) + +;; Labels + +(label_statement (identifier) @label) + +(goto_statement (identifier) @label) ;; Constants @@ -166,13 +180,40 @@ (parameters (identifier) @parameter) -(function_call name: (identifier) @function.call) -(function_declaration name: (identifier) @function) +(function_declaration + name: [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) -(function_call name: (dot_index_expression field: (identifier) @function.call)) -(function_declaration name: (dot_index_expression field: (identifier) @function)) +(function_declaration + name: (method_index_expression + method: (identifier) @method)) + +(assignment_statement + (variable_list . + name: [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) + (expression_list . + value: (function_definition))) + +(table_constructor + (field + name: (identifier) @function + value: (function_definition))) -(method_index_expression method: (identifier) @method) +(function_call + name: [ + (identifier) @function.call + (dot_index_expression + field: (identifier) @function.call) + (method_index_expression + method: (identifier) @method.call) + ]) (function_call (identifier) @function.builtin @@ -180,20 +221,29 @@ ;; built-in functions in Lua 5.1 "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" - "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable" - "tonumber" "tostring" "type" "unpack" "xpcall")) + "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setfenv" "setmetatable" + "tonumber" "tostring" "type" "unpack" "xpcall" + "__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc" + "__idiv" "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" + "__pairs" "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm")) ;; Others -(comment) @comment -(comment) @spell +(comment) @comment @spell -(hash_bang_line) @comment +((comment) @comment.documentation + (#lua-match? @comment.documentation "^[-][-][-]")) + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^[-][-](%s?)@")) + +(hash_bang_line) @preproc (number) @number -(string) @string -(string) @spell +(string) @string @spell + +(escape_sequence) @string.escape ;; Error (ERROR) @error diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 0e67329139..dbfe75ae31 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -3,20 +3,33 @@ (identifier) @_cdef_identifier (_ _ (identifier) @_cdef_identifier) ] - arguments: (arguments (string content: _ @c))) + arguments: + (arguments + (string content: _ @injection.content))) + (#set! injection.language "c") (#eq? @_cdef_identifier "cdef")) ((function_call name: (_) @_vimcmd_identifier - arguments: (arguments (string content: _ @vim))) - (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd")) + 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: _ @query) .)) -; (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) +((function_call + name: (_) @_vimcmd_identifier + 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))) + (#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 ("string_content") @query) (#lua-match? @query "^%s*;+%s?query")) +;; highlight string as query if starts with `;; query` +(string content: _ @injection.content + (#lua-match? @injection.content "^%s*;+%s?query") + (#set! injection.language "query")) -; (comment) @comment diff --git a/runtime/queries/markdown/folds.scm b/runtime/queries/markdown/folds.scm new file mode 100644 index 0000000000..5900f7ffbe --- /dev/null +++ b/runtime/queries/markdown/folds.scm @@ -0,0 +1,9 @@ +( + [ + (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 new file mode 100644 index 0000000000..2cc5546bac --- /dev/null +++ b/runtime/queries/markdown/highlights.scm @@ -0,0 +1,71 @@ +;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) + +(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) + +(link_title) @text.literal +(indented_code_block) @text.literal.block +((fenced_code_block) @text.literal.block (#set! "priority" 90)) + +(info_string) @label + +(pipe_table_header (pipe_table_cell) @text.title) + +(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_fence_content) @none + +[ + (link_destination) +] @text.uri + +[ + (link_label) +] @text.reference + +[ + (list_marker_plus) + (list_marker_minus) + (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 + +[ + (block_continuation) + (block_quote_marker) +] @punctuation.special + +[ + (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 new file mode 100644 index 0000000000..fda7036830 --- /dev/null +++ b/runtime/queries/markdown/injections.scm @@ -0,0 +1,25 @@ +(fenced_code_block + (info_string + (language) @injection.language) + (code_fence_content) @injection.content) + +((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)) + +((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")) diff --git a/runtime/queries/markdown_inline/highlights.scm b/runtime/queries/markdown_inline/highlights.scm new file mode 100644 index 0000000000..c75da478af --- /dev/null +++ b/runtime/queries/markdown_inline/highlights.scm @@ -0,0 +1,102 @@ +;; From MDeiml/tree-sitter-markdown +[ + (code_span) + (link_title) +] @text.literal @nospell + +[ + (emphasis_delimiter) + (code_span_delimiter) +] @punctuation.delimiter + +(emphasis) @text.emphasis + +(strong_emphasis) @text.strong + +(strikethrough) @text.strike + +[ + (link_destination) + (uri_autolink) +] @text.uri @nospell + +(shortcut_link (link_text) @nospell) + +[ + (link_label) + (link_text) + (image_description) +] @text.reference + +[ + (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 "")) + +; Conceal inline links +(inline_link + [ + "[" + "]" + "(" + (link_destination) + ")" + ] @conceal + (#set! conceal "")) + +; Conceal image links +(image + [ + "!" + "[" + "]" + "(" + (link_destination) + ")" + ] @conceal + (#set! conceal "")) + +; Conceal full reference links +(full_reference_link + [ + "[" + "]" + (link_label) + ] @conceal + (#set! conceal "")) + +; Conceal collapsed reference links +(collapsed_reference_link + [ + "[" + "]" + ] @conceal + (#set! conceal "")) + +; Conceal shortcut links +(shortcut_link + [ + "[" + "]" + ] @conceal + (#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 " ")) diff --git a/runtime/queries/markdown_inline/injections.scm b/runtime/queries/markdown_inline/injections.scm new file mode 100644 index 0000000000..f7aa19caff --- /dev/null +++ b/runtime/queries/markdown_inline/injections.scm @@ -0,0 +1,8 @@ +((html_tag) @injection.content + (#set! injection.language "html") + (#set! injection.combined) + (#set! injection.include-children)) + +((latex_block) @injection.content + (#set! injection.language "latex") + (#set! injection.include-children)) diff --git a/runtime/queries/python/folds.scm b/runtime/queries/python/folds.scm new file mode 100644 index 0000000000..78e1e2c00d --- /dev/null +++ b/runtime/queries/python/folds.scm @@ -0,0 +1,28 @@ +[ + (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 new file mode 100644 index 0000000000..04398668e9 --- /dev/null +++ b/runtime/queries/python/highlights.scm @@ -0,0 +1,351 @@ +;; 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) @type + (#lua-match? @type "^[A-Z].*[a-z]")) +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +((identifier) @constant.builtin + (#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")) + +"_" @constant.builtin ; match wildcard + +((attribute + attribute: (identifier) @field) + (#lua-match? @field "^[%l_].*$")) + +((assignment + left: (identifier) @type.definition + (type (identifier) @_annotation)) + (#eq? @_annotation "TypeAlias")) + +((assignment + left: (identifier) @type.definition + right: (call + function: (identifier) @_func)) + (#any-of? @_func "TypeVar" "NewType")) + +; Function calls + +(call + function: (identifier) @function.call) + +(call + function: (attribute + attribute: (identifier) @method.call)) + +((call + function: (identifier) @constructor) + (#lua-match? @constructor "^%u")) + +((call + function: (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +;; Decorators + +((decorator "@" @attribute) + (#set! "priority" 101)) + +(decorator + (identifier) @attribute) +(decorator + (attribute + attribute: (identifier) @attribute)) +(decorator + (call (identifier) @attribute)) +(decorator + (call (attribute + attribute: (identifier) @attribute))) + +((decorator + (identifier) @attribute.builtin) + (#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 + +(function_definition + name: (identifier) @function) + +(type (identifier) @type) +(type + (subscript + (identifier) @type)) ; type subscript: Tuple[int] + +((call + function: (identifier) @_isinstance + arguments: (argument_list + (_) + (identifier) @type)) + (#eq? @_isinstance "isinstance")) + +;; Normal parameters +(parameters + (identifier) @parameter) +;; Lambda parameters +(lambda_parameters + (identifier) @parameter) +(lambda_parameters + (tuple_pattern + (identifier) @parameter)) +; Default parameters +(keyword_argument + name: (identifier) @parameter) +; Naming parameters on call-site +(default_parameter + name: (identifier) @parameter) +(typed_parameter + (identifier) @parameter) +(typed_default_parameter + (identifier) @parameter) +; Variadic parameters *args, **kwargs +(parameters + (list_splat_pattern ; *args + (identifier) @parameter)) +(parameters + (dictionary_splat_pattern ; **kwargs + (identifier) @parameter)) + + +;; Literals + +(none) @constant.builtin +[(true) (false)] @boolean +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) +((identifier) @variable.builtin + (#eq? @variable.builtin "cls")) + +(integer) @number +(float) @float + +(comment) @comment @spell + +((module . (comment) @preproc) + (#lua-match? @preproc "^#!/")) + +(string) @string +[ + (escape_sequence) + (escape_interpolation) +] @string.escape + +; doc-strings + +(module . (expression_statement (string) @string.documentation @spell)) + +(class_definition + body: + (block + . (expression_statement (string) @string.documentation @spell))) + +(function_definition + body: + (block + . (expression_statement (string) @string.documentation @spell))) + +; Tokens + +[ + "-" + "-=" + ":=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "+=" + "<" + "<<" + "<<=" + "<=" + "<>" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "@" + "@=" + "|" + "|=" + "~" + "->" +] @operator + +; Keywords +[ + "and" + "in" + "is" + "not" + "or" + "is not" + "not in" + + "del" +] @keyword.operator + +[ + "def" + "lambda" +] @keyword.function + +[ + "assert" + "class" + "exec" + "global" + "nonlocal" + "pass" + "print" + "with" + "as" + "type" +] @keyword + +[ + "async" + "await" +] @keyword.coroutine + +[ + "return" + "yield" +] @keyword.return +(yield "from" @keyword.return) + +(future_import_statement + "from" @include + "__future__" @constant.builtin) +(import_from_statement "from" @include) +"import" @include + +(aliased_import "as" @include) + +["if" "elif" "else" "match" "case"] @conditional + +["for" "while" "break" "continue"] @repeat + +[ + "try" + "except" + "except*" + "raise" + "finally" +] @exception + +(raise_statement "from" @exception) + +(try_statement + (else_clause + "else" @exception)) + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) + +(type_conversion) @function.macro + +["," "." ":" ";" (ellipsis)] @punctuation.delimiter + +;; Class definitions + +(class_definition name: (identifier) @type) + +(class_definition + body: (block + (function_definition + name: (identifier) @method))) + +(class_definition + superclasses: (argument_list + (identifier) @type)) + +((class_definition + body: (block + (expression_statement + (assignment + left: (identifier) @field)))) + (#lua-match? @field "^%l.*$")) +((class_definition + body: (block + (expression_statement + (assignment + left: (_ + (identifier) @field))))) + (#lua-match? @field "^%l.*$")) + +((class_definition + (block + (function_definition + name: (identifier) @constructor))) + (#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 diff --git a/runtime/queries/query/folds.scm b/runtime/queries/query/folds.scm new file mode 100644 index 0000000000..47dd965126 --- /dev/null +++ b/runtime/queries/query/folds.scm @@ -0,0 +1,6 @@ +[ + (named_node) + (predicate) + (grouping) + (list) +] @fold diff --git a/runtime/queries/query/highlights.scm b/runtime/queries/query/highlights.scm new file mode 100644 index 0000000000..f2d2ef6c7f --- /dev/null +++ b/runtime/queries/query/highlights.scm @@ -0,0 +1,34 @@ +(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) +(comment) @comment @spell + +(quantifier) @operator +(predicate_type) @punctuation.special + +"." @operator + +[ + "[" + "]" + "(" + ")" +] @punctuation.bracket + +":" @punctuation.delimiter +["@" "#"] @punctuation.special +"_" @constant + +((parameters (identifier) @number) + (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) + +((program . (comment)* . (comment) @include) + (#lua-match? @include "^;+ *inherits *:")) + +((program . (comment)* . (comment) @preproc) + (#lua-match? @preproc "^;+ *extends")) diff --git a/runtime/queries/vim/folds.scm b/runtime/queries/vim/folds.scm new file mode 100644 index 0000000000..4c99735836 --- /dev/null +++ b/runtime/queries/vim/folds.scm @@ -0,0 +1,4 @@ +[ + (if_statement) + (function_definition) +] @fold diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm index 239b0a0b37..09188ddb68 100644 --- a/runtime/queries/vim/highlights.scm +++ b/runtime/queries/vim/highlights.scm @@ -271,11 +271,11 @@ ":" ] @punctuation.delimiter -(ternary_expression ["?" ":"] @conditional) +(ternary_expression ["?" ":"] @conditional.ternary) ; Options ((set_value) @number - (#match? @number "^[0-9]+(\.[0-9]+)?$")) + (#lua-match? @number "^[%d]+(%.[%d]+)?$")) (inv_option "!" @operator) (set_item "?" @operator) diff --git a/runtime/queries/vim/injections.scm b/runtime/queries/vim/injections.scm index fdd025bfd9..50f0190112 100644 --- a/runtime/queries/vim/injections.scm +++ b/runtime/queries/vim/injections.scm @@ -1,18 +1,33 @@ -(lua_statement (script (body) @lua)) -(lua_statement (chunk) @lua) -(ruby_statement (script (body) @ruby)) -(ruby_statement (chunk) @ruby) -(python_statement (script (body) @python)) -(python_statement (chunk) @python) +((lua_statement (script (body) @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 (chunk) @injection.content) + (#set! injection.language "ruby")) + +((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) @perl)) -;; (perl_statement (chunk) @perl) +;; ((perl_statement (script (body) @injection.content)) +;; (#set! injection.language "perl")) +;; ((perl_statement (chunk) @injection.content) +;; (#set! injection.language "perl")) -(autocmd_statement (pattern) @regex) +((autocmd_statement (pattern) @injection.content) + (#set! injection.language "regex")) ((set_item option: (option_name) @_option - value: (set_value) @vim) + value: (set_value) @injection.content) (#any-of? @_option "includeexpr" "inex" "printexpr" "pexpr" @@ -22,7 +37,12 @@ "foldexpr" "fde" "diffexpr" "dex" "patchexpr" "pex" - "charconvert" "ccv")) + "charconvert" "ccv") + (#set! injection.language "vim")) + + +; ((comment) @injection.content +; (#set! injection.language "comment")) -(comment) @comment -(line_continuation_comment) @comment +; ((line_continuation_comment) @injection.content +; (#set! injection.language "comment")) diff --git a/runtime/queries/help/highlights.scm b/runtime/queries/vimdoc/highlights.scm index c0d88301bc..e0dce49b2a 100644 --- a/runtime/queries/help/highlights.scm +++ b/runtime/queries/vimdoc/highlights.scm @@ -1,7 +1,7 @@ -(h1) @text.title -(h2) @text.title -(h3) @text.title -(column_heading) @text.title +(h1) @text.title.1 +(h2) @text.title.2 +(h3) @text.title.3 +(column_heading) @text.title.4 (column_heading "~" @conceal (#set! conceal "")) (tag diff --git a/runtime/queries/vimdoc/injections.scm b/runtime/queries/vimdoc/injections.scm new file mode 100644 index 0000000000..260a05d863 --- /dev/null +++ b/runtime/queries/vimdoc/injections.scm @@ -0,0 +1,4 @@ +((codeblock + (language) @injection.language + (code) @injection.content) + (#set! injection.include-children)) |