diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 4a7033c6f3e..651105e9d5c 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -695,8 +695,8 @@ namespace ts.formatting { let tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos); if (isTokenInRange) { let rangeHasError = rangeContainsError(currentTokenInfo.token); - // save prevStartLine since processRange will overwrite this value with current ones - let prevStartLine = previousRangeStartLine; + // save previousRange since processRange will overwrite this value with current one + let savePreviousRange = previousRange; lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation); if (rangeHasError) { // do not indent comments\token if token range overlaps with some error @@ -707,7 +707,9 @@ namespace ts.formatting { indentToken = lineAdded; } else { - indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine; + // indent token only if end line of previous range does not match start line of the token + const prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line; + indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine; } } } diff --git a/tests/cases/fourslash/formatAfterMultilineComment.ts b/tests/cases/fourslash/formatAfterMultilineComment.ts new file mode 100644 index 00000000000..b795ab5c8c9 --- /dev/null +++ b/tests/cases/fourslash/formatAfterMultilineComment.ts @@ -0,0 +1,7 @@ +/// +/////*foo +////*/"123123"; + +format.document(); +verify.currentFileContentIs(`/*foo +*/"123123";`)