From 912e49b66852e9dd598790446026de9b7e3efe8f Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 21 Oct 2015 12:49:14 -0700 Subject: [PATCH] do not indent token if its start line matches end line of previous token\trivia --- src/services/formatting/formatting.ts | 8 +++++--- tests/cases/fourslash/formatAfterMultilineComment.ts | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/formatAfterMultilineComment.ts 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";`)