nvim-treesitter-textobjects icon indicating copy to clipboard operation
nvim-treesitter-textobjects copied to clipboard

Do not include parentheses in @call.inner

Open mawkler opened this issue 3 years ago • 7 comments

Is your feature request related to a problem? Please describe. With the following keymaps:

['af'] = '@call.outer'
['if'] = '@call.inner'

With the following example code:

my_function(argument1, argument2)

When pressing dif that would delete the arguments and the parentheses like so:

my_function

But I personally think it would make more sense if the parentheses were not deleted:

my_function()

I often want to delete/replace the arguments to a function but I've never found myself wanting to delete the parentheses as well.

Describe the solution you'd like

@call.inner does not include the parentheses.

Describe alternatives you've considered

I could use i( instead but this is a more generic command which works in many cases, but not all cases. For instance in Lua the parentheses can be omitted if there's only one argument to the function, for instance require 'telescope'.

mawkler avatar Apr 04 '22 12:04 mawkler

I think this sound reasonable. Which language are you using? Could you create a PR that is fixing the queries to do this?

theHamsta avatar Apr 04 '22 13:04 theHamsta

I primarily use Lua and TypeScript at the moment. I've never used Schema before so I'm not sure how or where to start, but if you could point me to some resources on how Scheme and Treesitter work I could give it a try :)

Btw, I realize now that this is nvim-treesitter/nvim-treesitter, but I meant to post this issue in nvim-treesitter-textobjects. Should I move it to there instead or does it belong here?

mawkler avatar Apr 04 '22 13:04 mawkler

I could imagine the query for inner calls would look similar to https://github.com/theHamsta/nvim-treesitter-textobjects/blob/4e730ebe45f96e73f810567dc876fc934476f3d3/queries/fennel/textobjects.scm#L27-L31 with "(" . (_) @_start (_) @_end ")" in the middle.

theHamsta avatar Apr 05 '22 09:04 theHamsta

@melkster Maybe take a look at the queries in my recent pull request. I bet something similar would work, but with ( and ) instead of { and }.

telemachus avatar Apr 08 '22 22:04 telemachus

meain/evil-textobj-tree-sitter/pull/47 seems to fix this issue for many languages. Is it possible to apply the commit directly or does it require any modifications to work for nvim-treesitter-textobjects?

mawkler avatar Apr 25 '22 13:04 mawkler

@melkster Unless I'm confused, that commit fixes an issue with braces being included in function.inner, not the issue with parentheses being included in call.inner.

telemachus avatar Apr 25 '22 15:04 telemachus

@telemachus Oh yeah you're right! It applies better to nvim-treesitter/nvim-treesitter-textobjects/issues/112, which I see you recently added a similar PR for already!

mawkler avatar Apr 25 '22 19:04 mawkler