do not indent leading comments that attached to tokens with errors
This commit is contained in:
parent
49eb487920
commit
10d08b816e
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
tests/cases/fourslash/formattingCommentsBeforeErrors.ts
Normal file
20
tests/cases/fourslash/formattingCommentsBeforeErrors.ts
Normal 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 ");
|
Loading…
Reference in a new issue