feat(treesitter): provide select()

Problem: No public method for treesitter incremental selection.

Solution: Add `vim.treesitter.select()`.
This commit is contained in:
Nathan Zeng
2026-05-06 03:16:58 -07:00
committed by Justin M. Keyes
parent cac643f0f5
commit a0dcdcd8a0
2 changed files with 18 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ local M = vim._defer_require('vim.treesitter', {
language = ..., --- @module 'vim.treesitter.language'
languagetree = ..., --- @module 'vim.treesitter.languagetree'
query = ..., --- @module 'vim.treesitter.query'
_select = ..., --- @module 'vim.treesitter._select'
})
local LanguageTree = M.languagetree

View File

@@ -23,14 +23,26 @@ local function set_filetype(ft)
api.nvim_set_option_value('filetype', ft, { buf = 0 })
end
local function treeselect(cmd_, ...)
local function treeselect(cmd_, count_)
if cmd_ == 'select_node' then
cmd_ = 'select_child'
cmd_ = 'child'
elseif cmd_ == 'select_child' then
cmd_ = 'child'
elseif cmd_ == 'select_parent' then
cmd_ = 'parent'
elseif cmd_ == 'select_next' then
cmd_ = 'next'
elseif cmd_ == 'select_prev' then
cmd_ = 'prev'
elseif cmd_ == 'select_grow_next' then
cmd_ = 'extend_next'
elseif cmd_ == 'select_grow_prev' then
cmd_ = 'extend_prev'
end
exec_lua(function(cmd, ...)
require 'vim.treesitter._select'[cmd](...)
end, cmd_, ...)
exec_lua(function(cmd, count)
vim.treesitter.select(cmd, { count = count })
end, cmd_, count_)
end
describe('treesitter incremental-selection', function()