diff options
-rw-r--r-- | runtime/doc/treesitter.txt | 4 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 4 | ||||
-rw-r--r-- | runtime/plugin/nvim.lua | 15 |
3 files changed, 16 insertions, 7 deletions
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index ddca307e74..46f414d905 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -623,8 +623,8 @@ inspect_tree({opts}) *vim.treesitter.inspect_tree()* • winid (integer|nil): Window id to display the tree buffer in. If omitted, a new window is created with {command}. • command (string|nil): Vimscript command to create the - window. Default value is "topleft 60vnew". Only used when - {winid} is nil. + window. Default value is "60vnew". Only used when {winid} is + nil. • title (string|fun(bufnr:integer):string|nil): Title of the window. If a function, it accepts the buffer number of the source buffer as its only argument and should return a diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 56000f99a8..43b8c11b80 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -439,7 +439,7 @@ end --- - winid (integer|nil): Window id to display the tree buffer in. If omitted, --- a new window is created with {command}. --- - command (string|nil): Vimscript command to create the window. Default ---- value is "topleft 60vnew". Only used when {winid} is nil. +--- value is "60vnew". Only used when {winid} is nil. --- - title (string|fun(bufnr:integer):string|nil): Title of the window. If a --- function, it accepts the buffer number of the source buffer as its only --- argument and should return a string. @@ -465,7 +465,7 @@ function M.inspect_tree(opts) local w = opts.winid if not w then - vim.cmd(opts.command or 'topleft 60vnew') + vim.cmd(opts.command or '60vnew') w = a.nvim_get_current_win() end diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index e4b099f7ad..0a33826b82 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -6,6 +6,15 @@ vim.api.nvim_create_user_command('Inspect', function(cmd) end end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true }) -vim.api.nvim_create_user_command('InspectTree', function() - vim.treesitter.inspect_tree() -end, { desc = 'Inspect treesitter language tree for buffer' }) +vim.api.nvim_create_user_command('InspectTree', function(cmd) + if cmd.mods ~= '' or cmd.count ~= 0 then + local count = cmd.count ~= 0 and cmd.count or '' + local new = cmd.mods ~= '' and 'new' or 'vnew' + + vim.treesitter.inspect_tree({ + command = ('%s %s%s'):format(cmd.mods, count, new), + }) + else + vim.treesitter.inspect_tree() + end +end, { desc = 'Inspect treesitter language tree for buffer', count = true }) |