Fix incorrect indentation after comment line in JS/TS#309259
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix incorrect indentation after comment line in JS/TS#309259yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…ft#299080) Add a negative lookahead (?!\s*\/\/) to increaseIndentPattern and indentNextLinePattern so that lines beginning with // are not treated as containing unmatched brackets or control-flow keywords.
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.
Summary
(?!\s*\/\/)toincreaseIndentPatternandindentNextLinePatternin the JavaScript and TypeScript language configuration files so that single-line comment lines (starting with//) are excluded from indentation pattern matchingProblem
Typing or pasting a commented-out line like
// const test = () => {and pressing Enter causes VS Code to incorrectly increase the indentation on the next line. This happens because theincreaseIndentPatternsees the unmatched{at the end of the line without recognizing that the entire line is a comment.The same issue applies to
indentNextLinePattern-- a commented line like// if (true)would incorrectly trigger next-line indentation.Fix
A negative lookahead
(?!\s*\/\/)is prepended to bothincreaseIndentPatternandindentNextLinePattern. This causes lines that begin with//(with optional leading whitespace) to be excluded from matching, while lines with trailing comments likeif (true) { // commentcontinue to work correctly.Test plan
// const test = () => {and press Enter -- cursor should stay at the same indentation level (no extra indent)// if (true)and press Enter -- cursor should stay at the same indentation levelconst test = () => {and press Enter -- cursor should be indented (existing behavior preserved)if (true) { // commentand press Enter -- cursor should be indented (existing behavior preserved)