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

Make m textobject look for pairs enclosing selections #3344

Conversation

EpocSquadron
Copy link
Contributor

Right now, this textobject only looks for pairs that surround the cursor. This ensures that the pair found encloses each selection, which is likely to be intuitively what is expected of this textobject.

I'm marking this as a draft because I haven't adjusted the tests to expect the new behavior, and I'm not 100% sure all the edge cases are covered. I wanted to maybe get eyes on it to help me find them.

@the-mikedavis
Copy link
Member

This behavior feels intuitive to me as you say 👍

I think the tests don't need any adjustment because there aren't cases yet that cover this behavior. It would probably be good to add one or two that have different behavior between this and master

@EpocSquadron
Copy link
Contributor Author

I implemented a test and identified that it was missing some cases. In particular, if the start of the selection was before the opening pair it would reduce the selection down. I tried modifying the logic, but now in that case it simply fails to find a matching pair at all.. I've been banging my head against the desk for an hour, so I have to step away from this. Any help would be appreciated.

@A-Walrus
Copy link
Contributor

A-Walrus commented Aug 8, 2022

The function you modified is find_nth_closest_pairs_pos. I believe it is not actually used by any of the tests. They use find_nth_pairs_pos. You can replace the code for find_nth_closest_pairs_pos with a panic!() and the test will still fail for the same reason, the assertions are different, and not because the function panicked (it was never called):

thread 'surround::test::test_find_nth_pairs_range' panicked at 'assertion failed: `(left == right)`
  left: `Ok((10, 15))`,
 right: `Ok((4, 21))`: Beginning range (9, 13), character '(', skip 1', helix-core/src/surround.rs:275:13

@EpocSquadron
Copy link
Contributor Author

Thanks so much! My next hacking session on this might not be for a little while but I should be a lot more productive on it now

@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch from 3aaacfa to 41b484d Compare August 13, 2022 19:31
@EpocSquadron EpocSquadron marked this pull request as ready for review August 13, 2022 19:32
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Can we split these tests out into helix-term/tests/test/movement.rs or at least add a few cases there? mam/mim could really use some overall tests and the tests should end up being easier to read because of the selection DSL

helix-term/src/commands.rs Outdated Show resolved Hide resolved
@EpocSquadron
Copy link
Contributor Author

Can we split these tests out into helix-term/tests/test/movement.rs or at least add a few cases there? mam/mim could really use some overall tests and the tests should end up being easier to read because of the selection DSL

I could take a stab at that.

@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch 2 times, most recently from fca2dc4 to ca4fe1b Compare August 28, 2022 18:38
@EpocSquadron
Copy link
Contributor Author

Tests have been translated over to the new integration system, but they're still not passing. Ran out of time to work through correctness issues with test cases. Will come back later.

@EpocSquadron
Copy link
Contributor Author

There's an issue with the PR and counts that I need to address, and staring at the code some more I think there's some more simplification to do.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 13, 2022
@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch from ca4fe1b to 9cfdf4c Compare September 18, 2022 19:26
@EpocSquadron
Copy link
Contributor Author

Tests all pass now, the trouble was with the skip logic.

There remains the pathological case of when a single character cursor is on the opening of a pair, but that was an issue prior to this refactor and should be left for a separate fix. The new tests should help a lot with such an endeavour.

@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 18, 2022
@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch from f285550 to 2c070cb Compare September 19, 2022 03:53
Copy link
Member

@dead10ck dead10ck left a comment

Choose a reason for hiding this comment

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

The code looks good to me, thanks for the improvement! I'm assuming this code affects the "around" motions too. Would you be able to add ma tests that complement the mi tests?

@EpocSquadron
Copy link
Contributor Author

I can do another pass on tests yeah.

@archseer
Copy link
Member

archseer commented Oct 3, 2022

Looks like the code fails some lints, can you run cargo fmt?

@EpocSquadron
Copy link
Contributor Author

Looks like the code fails some lints, can you run cargo fmt?

Yes I can, also intended to write the ma tests I've just had a lot going on personally. Might be another week or two before I get time. I'm not opposed to a maintainer pushing to my branch however.

@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch from 2c070cb to 812dffd Compare October 10, 2022 12:47
@EpocSquadron
Copy link
Contributor Author

@archseer Added the mam equivalent tests, added multi-cursor tests, and added range direction preservation to the logic (with more tests). I can't think of much else to do here aside from that annoying bug where being on the opening brace skips out to the next pair. I've tried everything with regards to that and at this point I think it's better to address in a separate PR.

@EpocSquadron EpocSquadron removed the request for review from the-mikedavis October 10, 2022 12:54
@EpocSquadron
Copy link
Contributor Author

Looks like this partly resolves #4568

Reading through that it doesn't actually appear this PR addresses any of the several issues identified. Can you enlighten me?

, but it still fails with the cursor on an opening bracket. I think it'd be a good idea to add if is_opening_pair(text.char(pos)) before the loop in find_nth_closest_pairs_pos (removed error checking for conciseness).

At this point this PR has been sitting for a while. I'd rather see that issue with the opening bracket fixed in a follow-up. Feel free to work on that on your end.

Also I think it's a good idea to try and use the tree-sitter when available for getting pairs — that'd also allow mim and mam to work with strings and other language specific pairs. However, having a simpler algorithm to fall back to is still a good idea.

100%. When I started work on this the conceit was I would quickly resolve the non-tree-sitter version and then move on to working on the tree-sitter version. Didn't end up getting that far.

Do you want to work on all this yourself or should I do this myself?

I won't be able to spend a lot of time on helix contributions for a while, go for it!

@EpocSquadron
Copy link
Contributor Author

@archseer any chance this makes it into the release?

@archseer
Copy link
Member

archseer commented Dec 3, 2022

Oh, sorry but I completely missed this PR. I'm only merging small changes or bugfixes this close to release, but it'll definitely make it into the next cycle!

@the-mikedavis the-mikedavis added this to the next milestone Jan 13, 2023
@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch from 21f14a9 to 085e3aa Compare January 22, 2023 01:21
@EpocSquadron
Copy link
Contributor Author

Lint issue is unrelated to changes in this PR.

@gabydd
Copy link
Member

gabydd commented Jan 22, 2023

Seems like a2ad2e6 deleted some indents rustfmt wants

@EpocSquadron EpocSquadron force-pushed the epocsquadron/make-m-textobject-enclose-selections branch from 085e3aa to eb953c3 Compare January 28, 2023 20:02
helix-term/tests/test/movement.rs Outdated Show resolved Hide resolved
helix-term/tests/test/movement.rs Outdated Show resolved Hide resolved
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, let's get this merged! I'm liking the new integration tests and the main change in find_nth_closest_pairs_pos looks good 👍

@the-mikedavis the-mikedavis merged commit 6929a12 into helix-editor:master Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants