do not indent leading comments that attached to tokens with errors

This commit is contained in:
Vladimir Matveev 2014-12-10 15:08:26 -08:00
parent 49eb487920
commit 10d08b816e
2 changed files with 30 additions and 3 deletions

View file

@ -622,14 +622,21 @@ module ts.formatting {
var tokenStart = sourceFile.getLineAndCharacterFromPosition(currentTokenInfo.token.pos);
if (isTokenInRange) {
var rangeHasError = rangeContainsError(currentTokenInfo.token);
// save prevStartLine since processRange will overwrite this value with current ones
var prevStartLine = previousRangeStartLine;
lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation);
if (lineAdded !== undefined) {
indentToken = lineAdded;
if (rangeHasError) {
// do not indent comments\token if token range overlaps with some error
indentToken = false;
}
else {
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine;
if (lineAdded !== undefined) {
indentToken = lineAdded;
}
else {
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine;
}
}
}

View file

@ -0,0 +1,20 @@
/// <reference path='fourslash.ts' />
////module A {
//// interface B {
//// // a
//// // b
//// baz();
/////*0*/ // d /*1*/asd a
//// // e
//// foo();
//// // f asd
//// // g as
//// bar();
//// }
////}
goTo.marker("1");
edit.insert("\n");
goTo.marker("0");
verify.currentLineContentIs(" // d ");