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

Does it make sense to treat elements in a tuple/array literal as part of the @parameter object?

Open IndianBoy42 opened this issue 3 years ago • 6 comments

They are syntactically similar, and semantically not that different. I think there should be a text object for entries in lists/tuples/dictionaries, but the question is whether it should be in the parameter text object or another (@entry? @element)

IndianBoy42 avatar Jul 16 '21 14:07 IndianBoy42

@IndianBoy42 do you have a file we can use to test what you mean?

stsewd avatar Jul 18 '21 00:07 stsewd

This can be a problem for dynamically typed programming languages such as Python and Lua where dicts/arrays/... can be passed directly as arguments.

function_call(1, [8, 38, 2, 5])
function_call({
  value1 = true,
  some_number = 35,
  child_table = {
    something = "something"
  }
}, true)

I find it very convincing to be able to select such objects. This way, I can quickly swap arguments, move some to their own local variables, etc.

But I also frequently find it lacking that there's no selector for dict entries / table members out of the box. Maybe there should be a query that does exactly what you propose, but named different. To be able to select all the delimited objects, including function arguments.

snezhniylis avatar Jul 18 '21 08:07 snezhniylis

This was already done in https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/87/. But I agree that it makes sense to have those as a separate capture.

stsewd avatar Dec 21 '21 17:12 stsewd

I think arguments could be made either way.

Either you just want a 'smarter' select inside comma separated list, or you really want to be specific about the semantic element

One of the troubles is the sheer number of different text objects you could define semantically

IndianBoy42 avatar Dec 21 '21 17:12 IndianBoy42

I would also love to have a text object for comma separated items inside an array/list/table/dictionary. To me it makes sense to have a different capture group than @parameter, perhaps it could be called @field or @listItem?

mawkler avatar Nov 03 '22 09:11 mawkler

I would go with @item or @element I think.

yochem avatar Mar 06 '23 16:03 yochem