windwp / nvim-ts-autotag

Use treesitter to auto close and auto rename html tag
MIT License
1.63k stars 87 forks source link

fix: Don't auto tag fragment if not in jsx #210

Closed akozlev closed 1 month ago

akozlev commented 1 month ago

Use treesitter to determine whether node is a jsx_opening_element and use this info to bail out if the user may be writing a generic parameter.

Solves issue mentioned in https://github.com/windwp/nvim-ts-autotag/pull/202#issuecomment-2254467345 where useState<> becomes useState<></> when the user is typing out a generic type argument in typescriptreact files.

A thing to note is that there is still an ambiguity in the grammar while typing:

// If the user types:
const foo = <T>
// It could be a generic function:
const foo = <T>() => { ... };
// Alternatively it could be a JSX element:
const foo = <T></T>;

But generic inline functions are less common than generic types and argument so this PR fixes most cases.

PriceHiller commented 1 month ago

Thanks for the PR 🙂!

The test failure is from an older issue that still needs to be fixed, not relevant to this PR.