nvim-treesitter-textobjects
nvim-treesitter-textobjects copied to clipboard
[main] recommended setup for swap doesn't work
Describe the bug The recommended setup for swapping text objects on main is:
-- keymaps
local swap = require("nvim-treesitter-textobjects.swap")
vim.keymap.set("n", "<leader>a", swap.swap_next("@parameter.inner"))
vim.keymap.set("n", "<leader>A", swap.swap_next("@parameter.outer"))
But these keymaps don't work: nothing is swapped, and no error is thrown. Based on the setup for default branch, I think there's a typo and it should be
vim.keymap.set("n", "<leader>a", swap.swap_next("@parameter.inner"))
vim.keymap.set("n", "<leader>A", swap.swap_previous("@parameter.inner"))
However, these keymaps also don't work.
To Reproduce Steps to reproduce the behavior:
- Install the plugin and enable the recommended for swap
<leader>aon an argument
Expected behavior Arguments should be swapped
Output of :checkhealth nvim-treesitter
==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()
Installation ~
- WARNING
tree-sitter executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK
node found v20.13.1 (only needed for :TSInstallFromGrammar)
- OK
git executable found.
- OK
cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (GCC) 14.1.1 20240522
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{
machine = "x86_64",
release = "6.9.1-arch1-2",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Wed, 22 May 2024 13:47:07 +0000"
} ~
Parser/Features H L F I J
- bash ✓ ✓ ✓ . ✓
- bibtex ✓ . ✓ ✓ .
- c ✓ ✓ ✓ ✓ ✓
- comment ✓ . . . .
- cpp ✓ ✓ ✓ ✓ ✓
- css ✓ . ✓ ✓ ✓
- diff ✓ . . . .
- gdscript ✓ ✓ ✓ ✓ ✓
- gitcommit ✓ . . . ✓
- gitignore ✓ . . . .
- html ✓ ✓ ✓ ✓ ✓
- hyprlang ✓ . ✓ ✓ ✓
- java ✓ ✓ ✓ ✓ ✓
- javascript ✓ ✓ ✓ ✓ ✓
- jsdoc ✓ . . . .
- json ✓ ✓ ✓ ✓ .
- jsonc ✓ ✓ ✓ ✓ ✓
- lua ✓ ✓ ✓ ✓ ✓
- make ✓ . ✓ . ✓
- markdown ✓ . ✓ ✓ ✓
- markdown_inline ✓ . . . ✓
- python ✓ ✓ ✓ ✓ ✓
- query ✓ ✓ ✓ ✓ ✓
- regex ✓ . . . .
- requirements ✓ . . . ✓
- rust ✓ ✓ ✓ ✓ ✓
- scss ✓ . ✓ ✓ .
- sql ✓ . . ✓ ✓
- svelte ✓ ✓ ✓ ✓ ✓
- toml ✓ ✓ ✓ ✓ ✓
- tsx ✓ ✓ ✓ ✓ ✓
- typescript ✓ ✓ ✓ ✓ ✓
- typst ✓ . ✓ ✓ ✓
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
- yaml ✓ ✓ ✓ ✓ ✓
- zathurarc ✓ . . . ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang} ~
Output of nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
EDIT: this might be an issue with lazy loading, since I was defining the keys via lazy.nvim's keys property 🤔
I see the same issue.
return {
'nvim-treesitter/nvim-treesitter-textobjects',
branch = 'main',
opts = {
select = {
lookahead = true,
},
lsp_interop = {
floating_preview_opts = {},
},
move = {
set_jumps = true,
},
},
keys = {
--...
{
']A',
function()
require('nvim-treesitter-textobjects.swap').swap_next(
'@parameter.inner'
)
end,
desc = 'Swap argument',
},
-- ...
},
}
Mine works with this:
return {
{
"nvim-treesitter/nvim-treesitter",
dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
},
branch = "master",
lazy = false,
build = ":TSUpdate",
config = function()
require("nvim-treesitter.configs").setup {
ensure_installed = {
...
},
auto_install = true,
highlight = {
enable = true,
},
textobjects = {
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
},
}
end,
},
}
Mine works with this:
return { { "nvim-treesitter/nvim-treesitter", dependencies = { "nvim-treesitter/nvim-treesitter-textobjects", }, branch = "master", lazy = false, build = ":TSUpdate", config = function() require("nvim-treesitter.configs").setup { ensure_installed = { ... }, auto_install = true, highlight = { enable = true, }, textobjects = { swap = { enable = true, swap_next = { ["<leader>a"] = "@parameter.inner", }, swap_previous = { ["<leader>A"] = "@parameter.inner", }, }, }, } end, }, }
we're discussing the main branch (not master) here, which addresses #503.
Trying to be helpful wasn't helpful 🤦♂️ 😁 sorry I didn't fully read the [main] part.
Just noticed this issue, I should fixed it while refactoring. Could you please try it again?
Hey! With the latest commit from main, the swapping is working as intended. Do notice the README still contains the typo and where it reads
https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/35ef33c4690008687303483ce1d0567d238898f3/README.md?plain=1#L96
It should be
require("nvim-treesitter-textobjects.swap").swap_previous "@parameter.inner"
Thanks, feel free to report issues on main, there are a lot of reactors that have been done, so there may be some regressions.
We may fully switch to main recently, more testers are needed.
The typo on README will be fixed in https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/676/commits/eb24d0cd98c2e44cae203dcb4dac09698b92a1f7
Just noticed this issue, I should fixed it while refactoring. Could you please try it again?
Your changes have resolved this issue for me. Thank you.