fix: respect embedded language auto-closing pairs when typing#309365
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: respect embedded language auto-closing pairs when typing#309365yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When the cursor is positioned inside an embedded language region (for example, LaTeX embedded inside a markdown `$...$` math block), the auto- closing pair lookup previously used only the outer language's configuration. This caused pairs that are defined only in the outer language (such as markdown's `<>`) to be auto-closed inside regions where they are not meaningful - e.g. typing `<` inside a math block would insert `<>` even though `<` is a math operator there. Consult the embedded language's auto-closing pair configuration in addition to the outer language's. If the pair found via the outer language's configuration does not also exist in the embedded language (matched by identical open and close), skip auto-closing. This aligns with the existing pattern already used for electric characters in CursorConfiguration#onElectricCharacter, which uses ScopedLineTokens#languageId to pick the embedded language's configuration. Fixes microsoft#272922 Refs microsoft#133397
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Fixes auto-closing of the outer language's pairs inside embedded language regions. The concrete symptom reported in #272922 is typing
<inside a markdown LaTeX math block ($...$or$$...$$) auto-closes to<>, even though<is a math operator there, not an HTML tag.Root cause
AutoClosingOpenCharTypeOperation.getAutoClosingPairCloselooks up candidate pairs fromconfig.autoClosingPairs, which is built solely from the outer document language's configuration. When the cursor is inside an embedded language region (such as LaTeX embedded inside markdown math), pairs that are only defined in the outer language (e.g. markdown's<>) leak into regions where they are not meaningful.This is the root cause @alexdima identified on the parent issue:
(#133397)
The fix
After a candidate pair is found and the standard token-type check passes, also check the scoped (embedded) language's auto-closing pair configuration. If the pair does not exist in the embedded language (matched by identical open and close), skip auto-closing.
This mirrors the existing pattern already used for electric characters in
CursorConfiguration#onElectricCharacter, which usesScopedLineTokens#languageIdto pick the embedded language's configuration.The change is conservative:
(),{},[]for most languages) continue to auto-close as before.markup.math.*.markdownscopes.Verification
Repro from #272922 in a
.mdfile:Before: typing
<afteraproduces<>.After: typing
<afteraproduces just<.Also verified:
<still auto-closes to<>(markdown HTML use case preserved)..htmlfiles,<auto-closing behavior unchanged.```pythoninside markdown) still respect the embedded language's pairs (Python defines(),[],{},"",''but not<>, so<is no longer auto-closed there either - matching behavior in a standalone.pyfile).Fixes #272922
Refs #133397