neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit bb15fa035610bb9765ca16900703804a88faa3bb
parent 85cb0b0ddc59cd1b3a911e5b4a358e5404c1d0d8
Author: 再生花 <hoangtun0810@gmail.com>
Date:   Fri, 23 Feb 2024 05:58:59 +0900

feat(treesitter): add folding for `InspectTree` (#27518)

As the InspectTree buffer is now a valid tree-sitter query tree, we can
use the bundled fold queries to have folding for the tree.
Diffstat:
Mruntime/doc/news.txt | 7++++---
Mruntime/doc/treesitter.txt | 2+-
Mruntime/lua/vim/treesitter.lua | 3++-
Mruntime/lua/vim/treesitter/dev.lua | 5++++-
4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt @@ -231,9 +231,10 @@ The following new APIs and features were added. • |vim.treesitter.query.edit()| allows live editing of treesitter queries. • Improved error messages for query parsing. - • `:InspectTree` (|vim.treesitter.inspect_tree()|) shows node ranges in - 0-based indexing instead of 1-based indexing. - • `:InspectTree` (|vim.treesitter.inspect_tree()|) shows root nodes + • |:InspectTree| shows node ranges in 0-based indexing instead of 1-based + indexing. + • |:InspectTree| shows root nodes + • |:InspectTree| now supports |folding| • |vim.ui.open()| opens URIs using the system default handler (macOS `open`, Windows `explorer`, Linux `xdg-open`, etc.) diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt @@ -821,7 +821,7 @@ inspect_tree({opts}) *vim.treesitter.inspect_tree()* While in the window, press "a" to toggle display of anonymous nodes, "I" to toggle the display of the source language of each node, "o" to toggle the query editor, and press <Enter> to jump to the node under the cursor - in the source buffer. + in the source buffer. Folding also works (try |zo|, |zc|, etc.). Can also be shown with `:InspectTree`. *:InspectTree* diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua @@ -461,7 +461,8 @@ end --- --- While in the window, press "a" to toggle display of anonymous nodes, "I" to toggle the --- display of the source language of each node, "o" to toggle the query editor, and press ---- <Enter> to jump to the node under the cursor in the source buffer. +--- <Enter> to jump to the node under the cursor in the source buffer. Folding also works +--- (try |zo|, |zc|, etc.). --- --- Can also be shown with `:InspectTree`. *:InspectTree* --- diff --git a/runtime/lua/vim/treesitter/dev.lua b/runtime/lua/vim/treesitter/dev.lua @@ -159,7 +159,10 @@ end local function set_dev_properties(w, b) vim.wo[w].scrolloff = 5 vim.wo[w].wrap = false - vim.wo[w].foldmethod = 'manual' -- disable folding + vim.wo[w].foldmethod = 'expr' + vim.wo[w].foldexpr = 'v:lua.vim.treesitter.foldexpr()' -- explicitly set foldexpr + vim.wo[w].foldenable = false -- Don't fold on first open InspectTree + vim.wo[w].foldlevel = 99 vim.bo[b].buflisted = false vim.bo[b].buftype = 'nofile' vim.bo[b].bufhidden = 'wipe'