surround for TSX generic tags #2079
-
Contributing guidelines
Module(s)mini.surround Questionmini.surround supports 'tags', which works great also for JSX (including the <></> empty tag which is a thing in JSX). However it seems TSX generic components are not recognized as 'tags'. For instance, see: If I just modify a little that example... function Form() {
// ...
return (
<Select<string>
options={targets}
value={target}
onChange={setTarget}
>
<Item key="1" />
<Item key="2" />
</Select>
);
} Now if I put the cursor before the I do realize it's a bizarre syntax and really a torture test... But it's a real use-case so I thought I'd ask. I imagine this could be sorted out using custom surroundings, and maybe using treesitter, or a regex. I tried a little, but didn't make it quickly. If noone answers and I manage to make it work, i'll paste my solution here, but i'll be grateful if someone beats me to it :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
I am afraid, this is a too complicated use case for built-in As always the case with tag surrounding and textobject, the suggestion is to use tree-sitter to define them. This might or might not require writing custom tree-sitter queries, which is not trivial.
I am pretty sure that As both "delete" and first step of "replace" share the logic of finding the target region, it is not possible to achieve this with a single surrounding. There has to be separate
Here is my attempt on enabling this kind of behavior for tsx files using tree-sitter (make sure to use 'nvim-treesitter' on
Now The Let's hope there will be an improvement in this area with time. |
Beta Was this translation helpful? Give feedback.
-
A query for
I also played with queries for a self closing tag
and
But, in both cases, for |
Beta Was this translation helpful? Give feedback.
I am afraid, this is a too complicated use case for built-in
t
because it uses Lua patterns. Account for aSelect<string>
as a tag name is very not trivial with the Lua pattern surrounding specification (because it needs to "know" that>
afterstring
does not close the tag).As always the case with tag surrounding and textobject, the suggestion is to use tree-sitter to define them. This might or might not require writing custom tree-sitter queries, which is not trivial.