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

improve match bracket matching #10613

Merged
merged 2 commits into from
May 7, 2024

Conversation

pascalkuthe
Copy link
Member

This PR fixes a couple of edgecases that were noticed in the match bracket implementation after the recent changes to match_bracket.

This should cover both the markdown cases discovered by @David-Else (although I think there are still some cases involving injections that may not be covered but all the examples discussed work now) and the python cases discoreved by @ thomasaarholt. I also included fixes for some issues for cases where in cases where multiple nested pairs are siblings. I think this probably shouldn't happen usually, but it can happen in case there are syntax error so it's nice to be a bit more robust

@pascalkuthe pascalkuthe added C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much A-core Area: Helix core improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Apr 27, 2024
Copy link
Contributor

@woojiq woojiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rebase my changes on top of yours to see if they work together.
Unfortunately I can't review your PR properly because I don't really know how to work with the tree-sitter API, I used only helix's wrappers around TS in my commits)

helix-core/src/match_brackets.rs Outdated Show resolved Hide resolved
helix-core/src/match_brackets.rs Show resolved Hide resolved
@David-Else
Copy link
Contributor

Brilliant! In Markdown words surrounded in backticks now work everywhere, and also all the individual matching pair elements ([] () "") inside a link work, for example:

My favorite search engine is [Duck Duck Go](https://duckduckgo.com "The best search engine for privacy").

For reasons unknown to me you can mim inside the " in the link above, but not in general text:

Try `mim in this backticked text`, no problem, but it doesn't work in "this quoted text"

Not that big a deal, but I thought I would mention it in case it was a bug.

@woojiq
Copy link
Contributor

woojiq commented Apr 27, 2024

For reasons unknown to me you can mim inside the " in the link above, but not in general text:

Type :tree-sitter-subtree and you will notice that there are no nodes for default text, but there is a node for "link_title" that contains quotes.

@pascalkuthe pascalkuthe force-pushed the match_bracket_fixes branch from 68d6677 to 3049692 Compare April 27, 2024 15:23
@pascalkuthe
Copy link
Member Author

Markdown seems to be just a weird case its grammar the quotes there are not actually part of the sytnax tree (they are really just plaintext). The inline grammar that markdown uses is pretty hacky and the way it seems to produce nodes... Frankly doesn't make much sense. I think it works this way because of TS limitations/because markdown really isn't all that suited to a proper syntax tree but its mostly a coincidence that is works sometimes at all that is down to implementation details of the language.

mim/mam/mm for quotes (and even brackets where they aren't part of links) just won't work with markdown. The fact that they sometimes do is pure coincidence.

Copy link
Contributor

@thomasaarholt thomasaarholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this with #10611 on top, only with Python. Everything works as expected. Nice work, and thanks for fixing!

@archseer
Copy link
Member

Can we add some unit/integration tests for the bugs being fixed?

@pascalkuthe pascalkuthe force-pushed the match_bracket_fixes branch from 3049692 to d9bf297 Compare May 4, 2024 19:27
@pascalkuthe
Copy link
Member Author

pascalkuthe commented May 4, 2024

@archseer good point I added a couple integration tests both for past edge-cases and the new cases I fixed

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
@archseer archseer requested a review from the-mikedavis May 7, 2024 14:10
@the-mikedavis the-mikedavis merged commit 5b8b2f4 into helix-editor:master May 7, 2024
6 checks passed
Vulpesx pushed a commit to Vulpesx/helix that referenced this pull request Jun 7, 2024
Chirikumbrah pushed a commit to Chirikumbrah/helix that referenced this pull request Jun 15, 2024
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Helix core improvements C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants