aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake.deps/CMakeLists.txt3
-rw-r--r--cmake.deps/cmake/BuildTreesitterParsers.cmake1
-rw-r--r--runtime/lua/vim/treesitter.lua18
-rw-r--r--runtime/lua/vim/treesitter/playground.lua7
-rw-r--r--runtime/queries/lua/injections.scm8
-rw-r--r--runtime/queries/query/folds.scm6
-rw-r--r--runtime/queries/query/highlights.scm34
-rw-r--r--runtime/queries/vim/injections.scm4
8 files changed, 72 insertions, 9 deletions
diff --git a/cmake.deps/CMakeLists.txt b/cmake.deps/CMakeLists.txt
index a9a3f45319..12fa94c1c9 100644
--- a/cmake.deps/CMakeLists.txt
+++ b/cmake.deps/CMakeLists.txt
@@ -190,6 +190,9 @@ set(TREESITTER_VIM_SHA256 1b1cd39e33c8fb02fa7fe3977e844883c2a8508a7edd621f2d21e3
set(TREESITTER_HELP_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v1.3.0.tar.gz)
set(TREESITTER_HELP_SHA256 f33f6d49c7d71feb2fd68ef2b2684da150f9f8e486ad9726213631d673942331)
+set(TREESITTER_QUERY_URL https://github.com/nvim-treesitter/tree-sitter-query/archive/0717de07078a20a8608c98ad5f26c208949d0e15.tar.gz)
+set(TREESITTER_QUERY_SHA256 2f2c79a59e3ff550aef849925e589d69b8a146b3af935504366cc973399d26e1)
+
set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/c51896d32dcc11a38e41f36e3deb1a6a9c4f4b14.tar.gz)
set(TREESITTER_SHA256 243e07541a9dd71681984b65bffed2d4a259bef0a4ad28cff55cc1c6878b8d18)
diff --git a/cmake.deps/cmake/BuildTreesitterParsers.cmake b/cmake.deps/cmake/BuildTreesitterParsers.cmake
index fcfcb71036..774fc8a8c3 100644
--- a/cmake.deps/cmake/BuildTreesitterParsers.cmake
+++ b/cmake.deps/cmake/BuildTreesitterParsers.cmake
@@ -20,3 +20,4 @@ BuildTSParser(c ${TREESITTER_C_URL} ${TREESITTER_C_SHA256} TreesitterParserCMake
BuildTSParser(lua ${TREESITTER_LUA_URL} ${TREESITTER_LUA_SHA256} TreesitterParserCMakeLists.txt)
BuildTSParser(vim ${TREESITTER_VIM_URL} ${TREESITTER_VIM_SHA256} TreesitterParserCMakeLists.txt)
BuildTSParser(help ${TREESITTER_HELP_URL} ${TREESITTER_HELP_SHA256} TreesitterParserCMakeLists.txt)
+BuildTSParser(query ${TREESITTER_QUERY_URL} ${TREESITTER_QUERY_SHA256} TreesitterParserCMakeLists.txt)
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index f80da433b1..b63247aa2c 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -507,8 +507,26 @@ function M.inspect_tree(opts)
a.nvim_buf_set_keymap(b, 'n', 'a', '', {
desc = 'Toggle anonymous nodes',
callback = function()
+ local row, col = unpack(a.nvim_win_get_cursor(w))
+ local curnode = pg:get(row)
+ while curnode and not curnode.named do
+ row = row - 1
+ curnode = pg:get(row)
+ end
+
pg.opts.anon = not pg.opts.anon
pg:draw(b)
+
+ if not curnode then
+ return
+ end
+
+ local id = curnode.id
+ for i, node in pg:iter() do
+ if node.id == id then
+ a.nvim_win_set_cursor(w, { i, col })
+ end
+ end
end,
})
a.nvim_buf_set_keymap(b, 'n', 'I', '', {
diff --git a/runtime/lua/vim/treesitter/playground.lua b/runtime/lua/vim/treesitter/playground.lua
index fd5b687195..992433961f 100644
--- a/runtime/lua/vim/treesitter/playground.lua
+++ b/runtime/lua/vim/treesitter/playground.lua
@@ -146,9 +146,9 @@ local decor_ns = api.nvim_create_namespace('ts.playground')
---@return string
local function get_range_str(lnum, col, end_col, end_lnum)
if lnum == end_lnum then
- return string.format('[%d:%d-%d]', lnum + 1, col + 1, end_col)
+ return string.format('[%d:%d - %d]', lnum + 1, col + 1, end_col)
end
- return string.format('[%d:%d-%d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
+ return string.format('[%d:%d - %d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
end
--- Write the contents of this Playground into {bufnr}.
@@ -163,7 +163,8 @@ function TSPlayground:draw(bufnr)
for _, item in self:iter() do
local range_str = get_range_str(item.lnum, item.col, item.end_lnum, item.end_col)
local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
- local line = string.rep(' ', item.depth) .. item.text .. '; ' .. range_str .. lang_str
+ local line =
+ string.format('%s%s ; %s%s', string.rep(' ', item.depth), item.text, range_str, lang_str)
if self.opts.lang then
lang_hl_marks[#lang_hl_marks + 1] = {
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