From 1df3f5ec6aca24cbe7b78ead5c37ad06a65c84e8 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 23 Feb 2023 17:05:20 +0000 Subject: feat(treesitter): upstream foldexpr from nvim-treesitter --- runtime/queries/c/folds.scm | 19 +++++++++++++++++++ runtime/queries/lua/folds.scm | 10 ++++++++++ runtime/queries/vim/folds.scm | 4 ++++ 3 files changed, 33 insertions(+) create mode 100644 runtime/queries/c/folds.scm create mode 100644 runtime/queries/lua/folds.scm create mode 100644 runtime/queries/vim/folds.scm (limited to 'runtime/queries') diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm new file mode 100644 index 0000000000..80c3039b6b --- /dev/null +++ b/runtime/queries/c/folds.scm @@ -0,0 +1,19 @@ +[ + (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) +] @fold + + (compound_statement + (compound_statement) @fold) 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/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 -- cgit From 98e051783c26239a47c5cd643e9aea7146b097bd Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 3 Mar 2023 14:27:30 +0100 Subject: feat(treesitter): bundle query parser and queries (#22483) skip injections for now --- runtime/queries/lua/injections.scm | 8 ++++---- runtime/queries/query/folds.scm | 6 ++++++ runtime/queries/query/highlights.scm | 34 ++++++++++++++++++++++++++++++++++ runtime/queries/vim/injections.scm | 4 ++-- 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 runtime/queries/query/folds.scm create mode 100644 runtime/queries/query/highlights.scm (limited to 'runtime/queries') diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 0e67329139..69acbbbe9f 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -11,10 +11,10 @@ arguments: (arguments (string content: _ @vim))) (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd")) -; ((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: _ @query) .)) + (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) ; ;; highlight string as query if starts with `;; query` ; ((string ("string_content") @query) (#lua-match? @query "^%s*;+%s?query")) 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..ee31a7e7ef --- /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) @include) + (#match? @include "^;\ +inherits\ *:")) + +((program . (comment) @preproc) + (#match? @preproc "^; +extends")) diff --git a/runtime/queries/vim/injections.scm b/runtime/queries/vim/injections.scm index fdd025bfd9..b53643dc1a 100644 --- a/runtime/queries/vim/injections.scm +++ b/runtime/queries/vim/injections.scm @@ -24,5 +24,5 @@ "patchexpr" "pex" "charconvert" "ccv")) -(comment) @comment -(line_continuation_comment) @comment +; (comment) @comment +; (line_continuation_comment) @comment -- cgit From ddd257f75301a50c177fc24a693d39a45b47a689 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 8 Mar 2023 11:03:11 +0000 Subject: feat(treesitter): use upstream format for injection queries --- runtime/queries/c/injections.scm | 6 +++-- runtime/queries/help/injections.scm | 7 +++--- runtime/queries/lua/injections.scm | 16 +++++++++---- runtime/queries/vim/injections.scm | 46 ++++++++++++++++++++++++++----------- 4 files changed, 52 insertions(+), 23 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 7e9e73449d..84ae33683e 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,3 +1,5 @@ -(preproc_arg) @c +((preproc_arg) @injection.content + (#set! injection.language "c")) -; (comment) @comment +; ((comment) @injection.content +; (#set! injection.language "comment")) diff --git a/runtime/queries/help/injections.scm b/runtime/queries/help/injections.scm index 09bbe44e84..260a05d863 100644 --- a/runtime/queries/help/injections.scm +++ b/runtime/queries/help/injections.scm @@ -1,3 +1,4 @@ -(codeblock - (language) @language - (code) @content) +((codeblock + (language) @injection.language + (code) @injection.content) + (#set! injection.include-children)) diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 69acbbbe9f..10eb4c4054 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -3,20 +3,26 @@ (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))) + arguments: (arguments (string content: _ @injection.content))) + (#set! injection.language "vim") (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd")) ((function_call name: (_) @_vimcmd_identifier - arguments: (arguments (string content: _ @query) .)) + arguments: (arguments (string content: _ @injection.content) .)) + (#set! injection.language "query") (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) ; ;; highlight string as query if starts with `;; query` -; ((string ("string_content") @query) (#lua-match? @query "^%s*;+%s?query")) +; ((string ("string_content") @injection.content) +; (#set! injection.language "query") +; (#lua-match? @injection.content "^%s*;+%s?query")) -; (comment) @comment +; ((comment) @injection.content +; (#set! injection.language "comment")) diff --git a/runtime/queries/vim/injections.scm b/runtime/queries/vim/injections.scm index b53643dc1a..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")) -- cgit From 2a298f2e48eb081f2e3b58068af589b82fe76a18 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 31 Mar 2023 16:11:17 +0200 Subject: fix(treesitter): update queries from nvim-treesitter remove self-injection for C preprocessor macros (can be very slow) --- runtime/queries/c/highlights.scm | 115 ++++++++++++++++++++++++------------- runtime/queries/c/injections.scm | 4 +- runtime/queries/lua/highlights.scm | 43 +++++++++----- runtime/queries/lua/injections.scm | 12 ++-- runtime/queries/vim/highlights.scm | 2 +- 5 files changed, 112 insertions(+), 64 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 33e6df74ab..dee70f9cc7 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,22 +1,19 @@ -(identifier) @variable +; Lower priority to prefer @parameter when identifier appears in parameter_declaration. +((identifier) @variable (#set! "priority" 95)) [ - "const" "default" "enum" - "extern" - "inline" - "return" - "sizeof" - "static" "struct" "typedef" "union" - "volatile" "goto" - "register" ] @keyword +"sizeof" @keyword.operator + +"return" @keyword.return + [ "while" "for" @@ -32,7 +29,6 @@ "switch" ] @conditional -"#define" @constant.macro [ "#if" "#ifdef" @@ -41,10 +37,18 @@ "#elif" "#endif" (preproc_directive) -] @keyword +] @preproc + +"#define" @define "#include" @include +[ ";" ":" "," ] @punctuation.delimiter + +"..." @punctuation.special + +[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket + [ "=" @@ -62,6 +66,7 @@ ">>" "->" + "." "<" "<=" @@ -88,35 +93,25 @@ "++" ] @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 -[ "." ";" ":" "," ] @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) @@ -126,18 +121,32 @@ (statement_identifier) @label [ -(type_identifier) -(primitive_type) -(sized_type_specifier) -(type_descriptor) - ] @type + (type_identifier) + (sized_type_specifier) + (type_descriptor) +] @type + +(storage_class_specifier) @storageclass + +(type_qualifier) @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 ((identifier) @constant - (#match? @constant "^[A-Z][A-Z0-9_]+$")) + (#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")) ;; Preproc def / undef (preproc_def @@ -147,9 +156,20 @@ 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) +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment @spell -(comment) @comment -(comment) @spell +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) ;; Parameters (parameter_declaration @@ -158,7 +178,20 @@ (parameter_declaration declarator: (pointer_declarator) @parameter) -(preproc_params - (identifier)) @parameter +(preproc_params (identifier) @parameter) + +[ + "__attribute__" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + "_unaligned" + "__unaligned" + "__declspec" + (attribute_declaration) +] @attribute (ERROR) @error diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 84ae33683e..3b99c7a444 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,5 +1,5 @@ -((preproc_arg) @injection.content - (#set! injection.language "c")) +; ((preproc_arg) @injection.content +; (#set! injection.language "c")) ; ((comment) @injection.content ; (#set! injection.language "comment")) diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 2c0dc5447a..5fbf8a1833 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 @@ -129,12 +128,21 @@ (identifier) @variable ((identifier) @variable.builtin - (#eq? @variable.builtin "self")) + (#any-of? @variable.builtin "_G" "_VERSION" "debug" "io" "jit" "math" "os" "package" "self" "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 @@ -172,7 +180,7 @@ (function_call name: (dot_index_expression field: (identifier) @function.call)) (function_declaration name: (dot_index_expression field: (identifier) @function)) -(method_index_expression method: (identifier) @method) +(method_index_expression method: (identifier) @method.call) (function_call (identifier) @function.builtin @@ -180,20 +188,27 @@ ;; 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 + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^[-][-][-]")) + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^[-][-](%s?)@")) -(hash_bang_line) @comment +(hash_bang_line) @preproc (number) @number -(string) @string -(string) @spell +(string) @string @spell ;; Error (ERROR) @error diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 10eb4c4054..1c7bdaf951 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -11,18 +11,18 @@ name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content))) (#set! injection.language "vim") - (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd")) + (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2" "vim.api.nvim_cmd")) ((function_call name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content) .)) (#set! injection.language "query") - (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) + (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse")) -; ;; highlight string as query if starts with `;; query` -; ((string ("string_content") @injection.content) -; (#set! injection.language "query") -; (#lua-match? @injection.content "^%s*;+%s?query")) +;; highlight string as query if starts with `;; query` +((string ("string_content") @injection.content) + (#set! injection.language "query") + (#lua-match? @injection.content "^%s*;+%s?query")) ; ((comment) @injection.content ; (#set! injection.language "comment")) diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm index 239b0a0b37..ce25b13b9f 100644 --- a/runtime/queries/vim/highlights.scm +++ b/runtime/queries/vim/highlights.scm @@ -271,7 +271,7 @@ ":" ] @punctuation.delimiter -(ternary_expression ["?" ":"] @conditional) +(ternary_expression ["?" ":"] @conditional.ternary) ; Options ((set_value) @number -- cgit From d7f7450017b9b05303698a6cda54303ef22c63b3 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 31 Mar 2023 17:09:00 +0200 Subject: refactor(treesitter)!: rename help parser to vimdoc --- runtime/queries/help/highlights.scm | 25 ------------------------- runtime/queries/help/injections.scm | 4 ---- runtime/queries/vimdoc/highlights.scm | 25 +++++++++++++++++++++++++ runtime/queries/vimdoc/injections.scm | 4 ++++ 4 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 runtime/queries/help/highlights.scm delete mode 100644 runtime/queries/help/injections.scm create mode 100644 runtime/queries/vimdoc/highlights.scm create mode 100644 runtime/queries/vimdoc/injections.scm (limited to 'runtime/queries') diff --git a/runtime/queries/help/highlights.scm b/runtime/queries/help/highlights.scm deleted file mode 100644 index c0d88301bc..0000000000 --- a/runtime/queries/help/highlights.scm +++ /dev/null @@ -1,25 +0,0 @@ -(h1) @text.title -(h2) @text.title -(h3) @text.title -(column_heading) @text.title -(column_heading - "~" @conceal (#set! conceal "")) -(tag - "*" @conceal (#set! conceal "") - text: (_) @label) -(taglink - "|" @conceal (#set! conceal "") - text: (_) @text.reference) -(optionlink - text: (_) @text.reference) -(codespan - "`" @conceal (#set! conceal "") - text: (_) @text.literal) -(codeblock) @text.literal -(codeblock - [">" (language)] @conceal (#set! conceal "")) -(block - "<" @conceal (#set! conceal "")) -(argument) @parameter -(keycode) @string.special -(url) @text.uri diff --git a/runtime/queries/help/injections.scm b/runtime/queries/help/injections.scm deleted file mode 100644 index 260a05d863..0000000000 --- a/runtime/queries/help/injections.scm +++ /dev/null @@ -1,4 +0,0 @@ -((codeblock - (language) @injection.language - (code) @injection.content) - (#set! injection.include-children)) diff --git a/runtime/queries/vimdoc/highlights.scm b/runtime/queries/vimdoc/highlights.scm new file mode 100644 index 0000000000..c0d88301bc --- /dev/null +++ b/runtime/queries/vimdoc/highlights.scm @@ -0,0 +1,25 @@ +(h1) @text.title +(h2) @text.title +(h3) @text.title +(column_heading) @text.title +(column_heading + "~" @conceal (#set! conceal "")) +(tag + "*" @conceal (#set! conceal "") + text: (_) @label) +(taglink + "|" @conceal (#set! conceal "") + text: (_) @text.reference) +(optionlink + text: (_) @text.reference) +(codespan + "`" @conceal (#set! conceal "") + text: (_) @text.literal) +(codeblock) @text.literal +(codeblock + [">" (language)] @conceal (#set! conceal "")) +(block + "<" @conceal (#set! conceal "")) +(argument) @parameter +(keycode) @string.special +(url) @text.uri 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)) -- cgit From 0dbed7132b559b3e8419c0e59ca553e5921d6a90 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 13 May 2023 12:37:22 +0200 Subject: build(deps): update lua parser and queries --- runtime/queries/lua/highlights.scm | 10 +++++++++- runtime/queries/lua/injections.scm | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 5fbf8a1833..537a171441 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -127,8 +127,14 @@ (identifier) @variable +((identifier) @constant.builtin + (#eq? @constant.builtin "_VERSION")) + ((identifier) @variable.builtin - (#any-of? @variable.builtin "_G" "_VERSION" "debug" "io" "jit" "math" "os" "package" "self" "string" "table" "utf8")) + (#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")) @@ -210,5 +216,7 @@ (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 1c7bdaf951..3fcebe83f3 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -13,6 +13,14 @@ (#set! injection.language "vim") (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2" "vim.api.nvim_cmd")) +; vim.rcprequest(123, "nvim_exec_lua", "return vim.api.nvim_buf_get_lines(0, 0, -1, false)", false) +((function_call + name: (_) @_vimcmd_identifier + arguments: (arguments . (_) . (string content: _ @_method) . (string content: _ @injection.content))) + (#set! injection.language "lua") + (#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify") + (#eq? @_method "nvim_exec_lua")) + ((function_call name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content) .)) @@ -20,7 +28,7 @@ (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse")) ;; highlight string as query if starts with `;; query` -((string ("string_content") @injection.content) +(string content: _ @injection.content (#set! injection.language "query") (#lua-match? @injection.content "^%s*;+%s?query")) -- cgit From c97de026e357dec0bed034af3b54abf10966200b Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 13 May 2023 12:50:40 +0200 Subject: fix(treesitter): update vimdoc and vimscript queries --- runtime/queries/vim/highlights.scm | 2 +- runtime/queries/vimdoc/highlights.scm | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm index ce25b13b9f..09188ddb68 100644 --- a/runtime/queries/vim/highlights.scm +++ b/runtime/queries/vim/highlights.scm @@ -275,7 +275,7 @@ ; 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/vimdoc/highlights.scm b/runtime/queries/vimdoc/highlights.scm index c0d88301bc..e0dce49b2a 100644 --- a/runtime/queries/vimdoc/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 -- cgit From 9ff59517cbf309d31f979a49b7dc82b237ecfcc4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 13 May 2023 12:56:21 +0200 Subject: fix(treesitter): update c queries --- runtime/queries/c/highlights.scm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index dee70f9cc7..523a792403 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -117,12 +117,19 @@ (preproc_defined) ] @function.macro -(field_identifier) @property +(((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)) + (statement_identifier) @label [ (type_identifier) - (sized_type_specifier) (type_descriptor) ] @type @@ -138,6 +145,8 @@ (primitive_type) @type.builtin +(sized_type_specifier _ @type.builtin type: _?) + ((identifier) @constant (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) (enumerator @@ -163,6 +172,10 @@ 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) -- cgit From edf9a897f089191f2b43985f7ebc11a0b540bb44 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 21 May 2023 19:22:28 +0200 Subject: fix(treesitter): update highlights for query (#23699) captures for `; extends` and `; inherits` --- runtime/queries/query/highlights.scm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/query/highlights.scm b/runtime/queries/query/highlights.scm index ee31a7e7ef..f2d2ef6c7f 100644 --- a/runtime/queries/query/highlights.scm +++ b/runtime/queries/query/highlights.scm @@ -27,8 +27,8 @@ ((parameters (identifier) @number) (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) -((program . (comment) @include) - (#match? @include "^;\ +inherits\ *:")) +((program . (comment)* . (comment) @include) + (#lua-match? @include "^;+ *inherits *:")) -((program . (comment) @preproc) - (#match? @preproc "^; +extends")) +((program . (comment)* . (comment) @preproc) + (#lua-match? @preproc "^;+ *extends")) -- cgit From b697c0cd4fb2ebe3f021599cb77122374db7fd59 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 26 Jun 2023 09:25:46 +0200 Subject: fix(treesitter): update lua parser and queries (#24148) --- runtime/queries/lua/highlights.scm | 37 ++++++++++++++++++++++++++++++++----- runtime/queries/lua/injections.scm | 27 +++++++++++++-------------- 2 files changed, 45 insertions(+), 19 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 537a171441..96ffeae793 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -180,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))) -(method_index_expression method: (identifier) @method.call) +(table_constructor + (field + name: (identifier) @function + value: (function_definition))) + +(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 diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm index 3fcebe83f3..dbfe75ae31 100644 --- a/runtime/queries/lua/injections.scm +++ b/runtime/queries/lua/injections.scm @@ -3,7 +3,9 @@ (identifier) @_cdef_identifier (_ _ (identifier) @_cdef_identifier) ] - arguments: (arguments (string content: _ @injection.content))) + arguments: + (arguments + (string content: _ @injection.content))) (#set! injection.language "c") (#eq? @_cdef_identifier "cdef")) @@ -11,15 +13,7 @@ name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content))) (#set! injection.language "vim") - (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2" "vim.api.nvim_cmd")) - -; vim.rcprequest(123, "nvim_exec_lua", "return vim.api.nvim_buf_get_lines(0, 0, -1, false)", false) -((function_call - name: (_) @_vimcmd_identifier - arguments: (arguments . (_) . (string content: _ @_method) . (string content: _ @injection.content))) - (#set! injection.language "lua") - (#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify") - (#eq? @_method "nvim_exec_lua")) + (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_command" "vim.api.nvim_exec2")) ((function_call name: (_) @_vimcmd_identifier @@ -27,10 +21,15 @@ (#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 content: _ @injection.content - (#set! injection.language "query") - (#lua-match? @injection.content "^%s*;+%s?query")) + (#lua-match? @injection.content "^%s*;+%s?query") + (#set! injection.language "query")) -; ((comment) @injection.content -; (#set! injection.language "comment")) -- cgit From 11844dde81c41bded54f2383b57f8eef406f2736 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 1 Jul 2023 11:08:06 +0200 Subject: feat(treesitter): bundle markdown parser and queries (#22481) * bundle split Markdown parser from https://github.com/MDeiml/tree-sitter-markdown * add queries from https://github.com/nvim-treesitter/nvim-treesitter/tree/main * upstream `#trim!` and `#inject-language!` directives Co-authored-by: dundargoc --- runtime/queries/markdown/folds.scm | 9 +++ runtime/queries/markdown/highlights.scm | 63 ++++++++++++++++++ runtime/queries/markdown/injections.scm | 26 ++++++++ runtime/queries/markdown_inline/highlights.scm | 92 ++++++++++++++++++++++++++ runtime/queries/markdown_inline/injections.scm | 8 +++ 5 files changed, 198 insertions(+) create mode 100644 runtime/queries/markdown/folds.scm create mode 100644 runtime/queries/markdown/highlights.scm create mode 100644 runtime/queries/markdown/injections.scm create mode 100644 runtime/queries/markdown_inline/highlights.scm create mode 100644 runtime/queries/markdown_inline/injections.scm (limited to 'runtime/queries') 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..e78d233cc6 --- /dev/null +++ b/runtime/queries/markdown/highlights.scm @@ -0,0 +1,63 @@ +;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 diff --git a/runtime/queries/markdown/injections.scm b/runtime/queries/markdown/injections.scm new file mode 100644 index 0000000000..0bead6f4ac --- /dev/null +++ b/runtime/queries/markdown/injections.scm @@ -0,0 +1,26 @@ +(fenced_code_block + (info_string + (language) @_lang) + (code_fence_content) @injection.content + (#inject-language! @_lang)) + +((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..a70e34bb87 --- /dev/null +++ b/runtime/queries/markdown_inline/highlights.scm @@ -0,0 +1,92 @@ +;; 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 + +[ + (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 "")) 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)) -- cgit From 88c8803aa167806f32272e5f344af00b98a91f01 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 1 Jul 2023 11:19:31 +0200 Subject: feat(treesitter): add python parser and queries --- runtime/queries/python/folds.scm | 28 +++ runtime/queries/python/highlights.scm | 345 ++++++++++++++++++++++++++++++++++ 2 files changed, 373 insertions(+) create mode 100644 runtime/queries/python/folds.scm create mode 100644 runtime/queries/python/highlights.scm (limited to 'runtime/queries') 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..c18b748674 --- /dev/null +++ b/runtime/queries/python/highlights.scm @@ -0,0 +1,345 @@ +;; 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")) + +((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) @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" +] @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 -- cgit From cb0a1a10b22463664b4aecd3aa25e262692c0cab Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 1 Jul 2023 11:22:19 +0200 Subject: feat(treesitter): add bash parser and queries --- runtime/queries/bash/folds.scm | 8 ++ runtime/queries/bash/highlights.scm | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 runtime/queries/bash/folds.scm create mode 100644 runtime/queries/bash/highlights.scm (limited to 'runtime/queries') 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 "^#!/")) -- cgit From ad95b369856969ccb05b3f92b24d7262b4de3d71 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 22 Jul 2023 19:57:58 +0200 Subject: fix(treesitter): update markdown parser and queries (#24429) --- runtime/queries/markdown_inline/highlights.scm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'runtime/queries') diff --git a/runtime/queries/markdown_inline/highlights.scm b/runtime/queries/markdown_inline/highlights.scm index a70e34bb87..cd5da530d7 100644 --- a/runtime/queries/markdown_inline/highlights.scm +++ b/runtime/queries/markdown_inline/highlights.scm @@ -20,6 +20,8 @@ (uri_autolink) ] @text.uri @nospell +(shortcut_link (link_text) @nospell) + [ (link_label) (link_text) -- cgit From 41cefe513054edd1c12f235125220dbc6b4d9451 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 27 Jul 2023 12:45:08 +0200 Subject: build(deps): bump tree-sitter-c to v0.20.4 (#24495) --- runtime/queries/c/folds.scm | 3 ++- runtime/queries/c/highlights.scm | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm index 80c3039b6b..5a35334a24 100644 --- a/runtime/queries/c/folds.scm +++ b/runtime/queries/c/folds.scm @@ -13,7 +13,8 @@ (preproc_else) (preproc_ifdef) (initializer_list) + (gnu_asm_expression) ] @fold - (compound_statement +(compound_statement (compound_statement) @fold) diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 523a792403..ef70a7103c 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -8,9 +8,14 @@ "typedef" "union" "goto" + "asm" + "__asm__" ] @keyword -"sizeof" @keyword.operator +[ + "sizeof" + "offsetof" +] @keyword.operator "return" @keyword.return @@ -36,6 +41,8 @@ "#else" "#elif" "#endif" + "#elifdef" + "#elifndef" (preproc_directive) ] @preproc @@ -43,7 +50,7 @@ "#include" @include -[ ";" ":" "," ] @punctuation.delimiter +[ ";" ":" "," "::" ] @punctuation.delimiter "..." @punctuation.special @@ -98,8 +105,8 @@ (comma_expression [ "," ] @operator) [ - (true) - (false) + (true) + (false) ] @boolean (conditional_expression [ "?" ":" ] @conditional.ternary) @@ -112,10 +119,8 @@ (number_literal) @number (char_literal) @character -[ - (preproc_arg) - (preproc_defined) -] @function.macro +((preproc_arg) @function.macro (#set! "priority" 90)) +(preproc_defined) @function.macro (((field_expression (field_identifier) @property)) @_parent @@ -135,7 +140,10 @@ (storage_class_specifier) @storageclass -(type_qualifier) @type.qualifier +[ + (type_qualifier) + (gnu_asm_qualifier) +] @type.qualifier (linkage_specification "extern" @storageclass) @@ -195,15 +203,15 @@ [ "__attribute__" + "__declspec" + "__based" "__cdecl" "__clrcall" "__stdcall" "__fastcall" "__thiscall" "__vectorcall" - "_unaligned" - "__unaligned" - "__declspec" + (ms_pointer_modifier) (attribute_declaration) ] @attribute -- cgit From 31c4ed26bc278282898123ad21bb6fead401fd6f Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 11 Aug 2023 17:05:17 +0200 Subject: feat(treesitter): add injection language fallback (#24659) * feat(treesitter): add injection language fallback Problem: injection languages are often specified via aliases (e.g., filetype or in upper case), requiring custom directives. Solution: include lookup logic (try as parser name, then filetype, then lowercase) in LanguageTree itself and remove `#inject-language` directive. Co-authored-by: Lewis Russell --- runtime/queries/markdown/injections.scm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/markdown/injections.scm b/runtime/queries/markdown/injections.scm index 0bead6f4ac..fda7036830 100644 --- a/runtime/queries/markdown/injections.scm +++ b/runtime/queries/markdown/injections.scm @@ -1,8 +1,7 @@ (fenced_code_block (info_string - (language) @_lang) - (code_fence_content) @injection.content - (#inject-language! @_lang)) + (language) @injection.language) + (code_fence_content) @injection.content) ((html_block) @injection.content (#set! injection.language "html") -- cgit From 3836eeb90182cc610ea15bf6bd83cbc720bb7c64 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 12 Aug 2023 18:12:49 +0200 Subject: feat(treesitter): update C queries from upstream --- runtime/queries/c/highlights.scm | 49 ++++++++++++++++++++++++++++++++++++++-- runtime/queries/c/injections.scm | 20 ++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) (limited to 'runtime/queries') diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index ef70a7103c..29fb5747ca 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,5 +1,6 @@ ; Lower priority to prefer @parameter when identifier appears in parameter_declaration. ((identifier) @variable (#set! "priority" 95)) +(preproc_def (preproc_arg) @variable) [ "default" @@ -16,6 +17,7 @@ "sizeof" "offsetof" ] @keyword.operator +(alignof_expression . _ @keyword.operator) "return" @keyword.return @@ -141,8 +143,9 @@ (storage_class_specifier) @storageclass [ - (type_qualifier) + (type_qualifier) (gnu_asm_qualifier) + "__extension__" ] @type.qualifier (linkage_specification @@ -157,13 +160,52 @@ ((identifier) @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 - (#any-of? @constant.builtin "stderr" "stdin" "stdout")) + (#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 @@ -196,6 +238,9 @@ (parameter_declaration declarator: (identifier) @parameter) +(parameter_declaration + declarator: (array_declarator) @parameter) + (parameter_declaration declarator: (pointer_declarator) @parameter) diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 3b99c7a444..5a49e20df5 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,5 +1,21 @@ -; ((preproc_arg) @injection.content -; (#set! injection.language "c")) +((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")) -- cgit From 874b8172a69a0a5b0973f32410036823edc0dba7 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 24 Aug 2023 10:45:20 +0530 Subject: build(deps): bump tree-sitter-python to v0.20.4 --- runtime/queries/python/highlights.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'runtime/queries') diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index c18b748674..04398668e9 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -27,6 +27,8 @@ "credits" "license")) +"_" @constant.builtin ; match wildcard + ((attribute attribute: (identifier) @field) (#lua-match? @field "^[%l_].*$")) @@ -155,7 +157,10 @@ (#lua-match? @preproc "^#!/")) (string) @string -(escape_sequence) @string.escape +[ + (escape_sequence) + (escape_interpolation) +] @string.escape ; doc-strings @@ -241,6 +246,7 @@ "print" "with" "as" + "type" ] @keyword [ -- cgit From cfd4a9dfaf5fd900264a946ca33c4a4f26f66a49 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Tue, 12 Sep 2023 20:51:21 -0700 Subject: feat(lsp): use treesitter for stylize markdown --- runtime/queries/markdown/highlights.scm | 8 ++++++++ runtime/queries/markdown_inline/highlights.scm | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'runtime/queries') diff --git a/runtime/queries/markdown/highlights.scm b/runtime/queries/markdown/highlights.scm index e78d233cc6..2cc5546bac 100644 --- a/runtime/queries/markdown/highlights.scm +++ b/runtime/queries/markdown/highlights.scm @@ -61,3 +61,11 @@ ] @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_inline/highlights.scm b/runtime/queries/markdown_inline/highlights.scm index cd5da530d7..c75da478af 100644 --- a/runtime/queries/markdown_inline/highlights.scm +++ b/runtime/queries/markdown_inline/highlights.scm @@ -92,3 +92,11 @@ "]" ] @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 " ")) -- cgit