From a0dcdcd8a0e919ccddb5ecece72bd539272efdc5 Mon Sep 17 00:00:00 2001 From: Nathan Zeng <121571396+nathanzeng@users.noreply.github.com> Date: Wed, 6 May 2026 03:16:58 -0700 Subject: [PATCH] feat(treesitter): provide select() Problem: No public method for treesitter incremental selection. Solution: Add `vim.treesitter.select()`. --- runtime/lua/vim/treesitter.lua | 1 + test/functional/treesitter/select_spec.lua | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index a16e291510..f5334fe449 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -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 diff --git a/test/functional/treesitter/select_spec.lua b/test/functional/treesitter/select_spec.lua index 9df172efc3..ae8a3eedaf 100644 --- a/test/functional/treesitter/select_spec.lua +++ b/test/functional/treesitter/select_spec.lua @@ -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()