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

Align the way rust and typescript are defining field paramaters

Open dmtrKovalenko opened this issue 6 months ago • 3 comments

Is your feature request related to a problem? Please describe. Seeing the PR https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/751 made me think that it would be possible to resolve the problem I am struggling with for quite some time.

In rust

let value = MyStruct {
   my_param: 13
};

If I want to work with my_param I need to use @parameter text object, but in typescript with the exact same code

let value = MyStruct {
  my_param: 13
}

I have to use @variable for whatever reason

Describe the solution you'd like Have similar code in different languages to be handled in the similar way either @parameter or @attribute in both cases

Describe alternatives you've considered to suffer

dmtrKovalenko avatar May 29 '25 08:05 dmtrKovalenko

So in Typescript, an object is often used for function parameters. But I think in Rust it's not the case because of efficiency.

Currently, for the sake of simplicity the @parameter should select an entire parameter and there's no distinction between the @parameter.name and @parameter.value (some languages don't even support named arguments).

@variable is not part of this plugin and I believe it's a highlighting definition from nvim-treesitter. The purpose of highlighting queries is not for textobjects so we can't guarantee the alignment of it across languages.

TL;DR

  1. @parameter.name is not supported in the plugin yet. So what you want to do can't be done without custom queries or queries from another plugin.
  2. If we want to align @parameter.inner and @parameter.outer, then the Rust behaviour has to change to match Typescript. Typescript one is correct.

kiyoon avatar May 30 '25 03:05 kiyoon

You mean the parse itself?

dmtrKovalenko avatar May 30 '25 04:05 dmtrKovalenko

parsing is done by treesitter which and the grammar supports it. But we don't have a query to select just parameter names

kiyoon avatar May 30 '25 07:05 kiyoon