Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matchit bug fixes #626

Merged
merged 4 commits into from Apr 26, 2023
Merged

Matchit bug fixes #626

merged 4 commits into from Apr 26, 2023

Conversation

myzeiri
Copy link
Contributor

@myzeiri myzeiri commented Apr 14, 2023

This fixes some Matchit edge cases.

Missed jumps on comments
Currently, hitting % on the whitespace before a commented pair will not jump. This is a logic bug. When deciding if comments should be included in the search, we need to check the PSI element at the first match offset, not the caret offset.

As a bonus, this fix makes the special isHtmlAttribute check unnecessary. If the caret is in an HTML attribute, the first match offset will point to the start of the tag.

Incorrect jumps on HTML tags sharing a prefix
The regex for HTML jumps needs a closing > else a tag like <Box> will match with e.g. <BoxHeading>.

VIM-2905: Matchit doesnt work with closing JSX tags

In files that mix HTML and JavaScript, like JSX or simple <script> tags, the brackets used for arrow functions and comparisons like x > y conflict with the brackets on tags.

To fix that, we can ignore the JS brackets using PSI checks like we currently do for some Ruby keywords.

I double checked that those PSI elements are the same anywhere JavaScript or TypeScript syntax highlighting is used e.g. JSX/TSX, Vue.js etc.

Clip showing the fixed jumps on the example in the ticket:

B8uS1Hgp7d

@myzeiri myzeiri marked this pull request as draft April 14, 2023 13:51
Since the cursor can come before the start of the matching pair, we need
to check the PSI element at the first match offset, not the caret offset,
when deciding if we need to skip comments.

This fix makes the special isHtmlAttribute check unnecessary. If the caret
is in an HTML attribute, the first match offset will point to the start
of the tag.
A final closing > is required on the search pair, otherwise tags with a
shared prefix in their names will conflict.
In files that mix HTML and JavaScript, arrow functions or forms like (x > y)
conflict with the brackets on HTML tags. We can ignore those JS elements
using PSI checks like we do for some Ruby keywords.
@myzeiri myzeiri marked this pull request as ready for review April 16, 2023 15:29
@AlexPl292
Copy link
Member

Hi, this seems good to me. Thank you for your updates! 🎉

@AlexPl292 AlexPl292 merged commit bcf10a0 into JetBrains:master Apr 26, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants