Skip to content

Handle conflicting multi-char auto closing pairs#110094

Merged
alexdima merged 3 commits intomicrosoft:masterfrom
olivercoad:conflicting-autoclose-pairs
Nov 13, 2020
Merged

Handle conflicting multi-char auto closing pairs#110094
alexdima merged 3 commits intomicrosoft:masterfrom
olivercoad:conflicting-autoclose-pairs

Conversation

@olivercoad
Copy link
Contributor

This PR fixes #72177

When autoclosing multi-character pairs, rather than just adding all of pair.close, it now only adds the part that hasn't already been autoclosed.
It does this by finding the longest pair that is contained in the current pair. It then checks if subAutoClosingPair.close is already present (it may not necessarily have just been autoclosed) for all selections, and if so only adds a substring of pair.close excluding subAutoClosingPair.close.

In order to get auto close working when the sub-pair is multiple characters, _isBeforeClosingBrace had to be updated to work with multi-character pairs.

And example of where this is the case is the F# pairs

"autoClosingPairs": [
...
["<@", "@>"],
["<@@", "@@>"],
...
]

In the process of updating _isBeforeClosingBrace, I changed it from excluding symmetric pairs to explicitely returning false for all potential starting braces.
I believe the intended purpose of the symmetric pair check was to allow autoclosing before close braces but to not get mixed up when the close brace might actually be an open brace (see #20801).
However, the previous implementation also allowed autoclosing before starting braces if the autoclose brace was also symmetric. This seems contrary to the method name so I'm assuming it was unintentional (or otherwise it should probably be more explicit);
this change required a couple of minor changes to some unit tests.

@ghost
Copy link

ghost commented Nov 6, 2020

CLA assistant check
All CLA requirements met.

@rebornix rebornix assigned alexdima and unassigned rebornix Nov 8, 2020
@alexdima alexdima force-pushed the conflicting-autoclose-pairs branch from 47d4001 to ea9be95 Compare November 13, 2020 10:50
@alexdima alexdima force-pushed the conflicting-autoclose-pairs branch from ea9be95 to d310cba Compare November 13, 2020 10:53
@alexdima alexdima added this to the November 2020 milestone Nov 13, 2020
@alexdima
Copy link
Member

Thank you!

@alexdima alexdima merged commit 7dde162 into microsoft:master Nov 13, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auto closing pairs with conflicting patterns problems

4 participants