aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-05-15 19:46:47 +0200
committerGitHub <noreply@github.com>2023-05-15 19:46:47 +0200
commit8e3124493ce176843b9a66773d76a4422647dea9 (patch)
tree8d69ea596c19353f6584f9362b495ba5b79cee48
parent88a202a01097de029beb01f60ad98aa0b5b44b50 (diff)
parent9ff59517cbf309d31f979a49b7dc82b237ecfcc4 (diff)
downloadrneovim-8e3124493ce176843b9a66773d76a4422647dea9.tar.gz
rneovim-8e3124493ce176843b9a66773d76a4422647dea9.tar.bz2
rneovim-8e3124493ce176843b9a66773d76a4422647dea9.zip
Merge pull request #23606 from clason/bump-tree-sitter-lua
fix(treesitter): update parser and queries
-rw-r--r--cmake.deps/deps.txt4
-rw-r--r--runtime/doc/treesitter.txt16
-rw-r--r--runtime/lua/vim/treesitter/query.lua33
-rw-r--r--runtime/queries/c/highlights.scm17
-rw-r--r--runtime/queries/lua/highlights.scm10
-rw-r--r--runtime/queries/lua/injections.scm10
-rw-r--r--runtime/queries/vim/highlights.scm2
-rw-r--r--runtime/queries/vimdoc/highlights.scm8
-rw-r--r--test/functional/treesitter/parser_spec.lua2
9 files changed, 88 insertions, 14 deletions
diff --git a/cmake.deps/deps.txt b/cmake.deps/deps.txt
index 5c9d29bea6..385ede0e42 100644
--- a/cmake.deps/deps.txt
+++ b/cmake.deps/deps.txt
@@ -52,8 +52,8 @@ LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178
TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz
TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2
-TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.14.tar.gz
-TREESITTER_LUA_SHA256 930d0370dc15b66389869355c8e14305b9ba7aafd36edbfdb468c8023395016d
+TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.17.tar.gz
+TREESITTER_LUA_SHA256 8963fd0a185d786c164dfca3824941c7eaec497ce49a3a0bc24bf753f5e0e59c
TREESITTER_VIM_URL https://github.com/neovim/tree-sitter-vim/archive/v0.3.0.tar.gz
TREESITTER_VIM_SHA256 403acec3efb7cdb18ff3d68640fc823502a4ffcdfbb71cec3f98aa786c21cbe2
TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v2.0.0.tar.gz
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index 483812b7c9..64b4730eee 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -221,8 +221,7 @@ The following predicates are built in:
similar to `match?`
`contains?` *treesitter-predicate-contains?*
- Match a string against parts of the text corresponding to a node:
- >query
+ Match a string against parts of the text corresponding to a node: >query
((identifier) @foo (#contains? @foo "foo"))
((identifier) @foo-bar (#contains? @foo-bar "foo" "bar"))
<
@@ -234,6 +233,19 @@ The following predicates are built in:
This is the recommended way to check if the node matches one of many
keywords, as it has been optimized for this.
+ `has-ancestor?` *treesitter-predicate-has-ancestor?*
+ Match any of the given node types against all ancestors of a node: >query
+ ((identifier) @variable.builtin
+ (#any-of? @variable.builtin "begin" "end")
+ (#has-ancestor? @variable.builtin range_expression))
+<
+ `has-parent?` *treesitter-predicate-has-parent?*
+ Match any of the given node types against the direct ancestor of a
+ node: >query
+ (((field_expression
+ (field_identifier) @method)) @_parent
+ (#has-parent? @_parent template_method function_declarator))
+<
*lua-treesitter-not-predicate*
Each predicate has a `not-` prefixed predicate that is just the negation of
the predicate.
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 75e5bf8870..73b561c777 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -382,6 +382,39 @@ local predicate_handlers = {
return string_set[node_text]
end,
+
+ ['has-ancestor?'] = function(match, _, _, predicate)
+ local node = match[predicate[2]]
+ if not node then
+ return true
+ end
+
+ local ancestor_types = {}
+ for _, type in ipairs({ unpack(predicate, 3) }) do
+ ancestor_types[type] = true
+ end
+
+ node = node:parent()
+ while node do
+ if ancestor_types[node:type()] then
+ return true
+ end
+ node = node:parent()
+ end
+ return false
+ end,
+
+ ['has-parent?'] = function(match, _, _, predicate)
+ local node = match[predicate[2]]
+ if not node then
+ return true
+ end
+
+ if vim.list_contains({ unpack(predicate, 3) }, node:parent():type()) then
+ return true
+ end
+ return false
+ end,
}
-- As we provide lua-match? also expose vim-match?
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)
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"))
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
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua
index 9afce0b3a0..60042ab2fd 100644
--- a/test/functional/treesitter/parser_spec.lua
+++ b/test/functional/treesitter/parser_spec.lua
@@ -483,7 +483,7 @@ end]]
return list
]]
- eq({ 'any-of?', 'contains?', 'eq?', 'is-main?', 'lua-match?', 'match?', 'vim-match?' }, res_list)
+ eq({ 'any-of?', 'contains?', 'eq?', 'has-ancestor?', 'has-parent?', 'is-main?', 'lua-match?', 'match?', 'vim-match?' }, res_list)
end)