Closed notpeelz closed 2 years ago
They only work when the parent language has a textobject of that kind. The keybindings will only be set for the parent language because language injection is dynamic which mean any language could be injected at any moment. Users requested that the keybindings should not be set when a parent language doesn't have a certain textobject but probably it should always be set which configurable fallback functions that will be executed when no textobject is found.
You could set the keybindings manually. Eg TSTexobjectSelect @paramater.outer
should work.
Or in other words: the parent language defines which mappings will be defined: so you could just add textobjects for viml. Then, it will also work for injected languages.
You could set the keybindings manually. Eg
TSTexobjectSelect @paramater.outer
should work.
That only works in normal mode. I'd prefer to keep using operator-pending mappings.
This works but it's not super pretty:
onoremap aa <Cmd>lua require'nvim-treesitter.textobjects.select'.select_textobject('@parameter.outer', 'o')<CR>
onoremap ia <Cmd>lua require'nvim-treesitter.textobjects.select'.select_textobject('@parameter.inner', 'o')<CR>
Users requested that the keybindings should not be set when a parent language doesn't have
Would it be possible to add a setting to control that behavior? What's the use case for enabling mappings on a per-language basis?
Would it be possible to add a setting to control that behavior? What's the use case for enabling mappings on a per-language basis?
They had their own regex-based mappings for languages that had no tree-sitter support. This is why I said that we could solve this by having fall-back actions when no tree-sitter textobject is found.
Probably the quickest fix for this concrete issue is to just add Viml textobject. A solution for the general problem can be done later.
Sounds good.
For anybody else who might have the same issue as me; this is what I ended up doing:
fun! s:TextobjectMapping(lhs, rhs)
execute("onoremap " . a:lhs . " <Cmd>lua require'nvim-treesitter.textobjects.select'.select_textobject('" . a:rhs . "', 'o')<CR>")
endfun
call s:TextobjectMapping('aa', '@parameter.outer')
call s:TextobjectMapping('ia', '@parameter.inner')
" ...
I'm closing this issue because nvim-treesitter-textobjects works within injected languages. There is however a problem that the mappings are only set for the parent language. Feel free to open a new issue for that one. This can however maybe not avoided since every language can be injected in any other language and we don't want to set unsupported mappings.
@theHamsta Would you be opposed to a PR that possibly also checks for injected languages in the injections.scm
queries and then adds those potential text objects as mappings?
Describe the bug
Text objects don't work inside of injected languages.
Pressing
daa
here doesn't do anything.Related to #27
To Reproduce Steps to reproduce the behavior using the following textobjects config:
:set ft=vim
daa
(nothing happens)Output of
:checkhealth nvim_treesitter
Output of
nvim --version