@@ -161,16 +161,6 @@ module ts.formatting {
161
161
162
162
if ( precedingListItemStartLineAndChar . line !== listStart . line ) {
163
163
return findColumnForFirstNonWhitespaceCharacterInLine ( precedingListItemStartLineAndChar , sourceFile , options ) ;
164
- // previous list item starts on the different line with list, find first non-whitespace character in this line and use its position as indentation
165
- var lineStartPosition = sourceFile . getPositionFromLineAndCharacter ( precedingListItemStartLineAndChar . line , 1 ) ;
166
- for ( var i = 0 ; i < precedingListItemStartLineAndChar . character ; ++ i ) {
167
- if ( ! isWhiteSpace ( sourceFile . text . charCodeAt ( lineStartPosition + i ) ) ) {
168
- return i ;
169
- }
170
- }
171
-
172
- // seems that this is the first non-whitespace character on the line - return it
173
- return precedingListItemStartLineAndChar . character ;
174
164
}
175
165
176
166
return - 1 ;
@@ -290,6 +280,8 @@ module ts.formatting {
290
280
function getActualIndentationFromList ( list : Node [ ] ) : number {
291
281
var index = indexOf ( list , node ) ;
292
282
if ( index !== - 1 ) {
283
+ // walk toward the start of the list starting from current node and check if if line is the same for all items.
284
+ // if line for item [i - 1] differs from the line for item [i] - find column of the first non-whitespace character on the line of item [i]
293
285
var lineAndCharacter = getStartLineAndCharacterForNode ( node , sourceFile ) ; ;
294
286
for ( var i = index - 1 ; i >= 0 ; -- i ) {
295
287
var prevLineAndCharacter = getStartLineAndCharacterForNode ( list [ i ] , sourceFile ) ;
@@ -312,7 +304,7 @@ module ts.formatting {
312
304
return column ;
313
305
}
314
306
315
- if ( charCode === CharacterCodes . tab ) {
307
+ if ( charCode === CharacterCodes . tab && ! options . useTabs ) {
316
308
column += options . spacesPerTab ;
317
309
}
318
310
else {
@@ -479,6 +471,7 @@ module ts.formatting {
479
471
return false ;
480
472
}
481
473
474
+ // this function is alwasy called when position of the cursor is located after the node
482
475
function isCompletedNode ( n : Node , sourceFile : SourceFile ) : boolean {
483
476
switch ( n . kind ) {
484
477
case SyntaxKind . ClassDeclaration :
@@ -518,17 +511,15 @@ module ts.formatting {
518
511
case SyntaxKind . DefaultClause :
519
512
// there is no such thing as terminator token for CaseClause\DefaultClause so for simplicitly always consider them non-completed
520
513
return false ;
521
- case SyntaxKind . VariableStatement :
522
- // variable statement is considered completed if it either doesn'not have variable declarations or last variable declaration is completed
523
- var variableDeclarations = ( < VariableStatement > n ) . declarations ;
524
- return variableDeclarations . length === 0 || isCompletedNode ( variableDeclarations [ variableDeclarations . length - 1 ] , sourceFile ) ;
525
- case SyntaxKind . VariableDeclaration :
526
- // variable declaration is completed if it either doesn't have initializer or initializer is completed
527
- return ! ( < VariableDeclaration > n ) . initializer || isCompletedNode ( ( < VariableDeclaration > n ) . initializer , sourceFile ) ;
528
514
case SyntaxKind . WhileStatement :
529
515
return isCompletedNode ( ( < WhileStatement > n ) . statement , sourceFile ) ;
530
516
case SyntaxKind . DoStatement :
531
- return isCompletedNode ( ( < DoStatement > n ) . statement , sourceFile ) ;
517
+ // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
518
+ var hasWhileKeyword = forEach ( n . getChildren ( ) , c => c . kind === SyntaxKind . WhileKeyword && c ) ;
519
+ if ( hasWhileKeyword ) {
520
+ return isNodeEndWith ( n , SyntaxKind . CloseParenToken , sourceFile ) ;
521
+ }
522
+ return isCompletedNode ( ( < DoStatement > n ) . statement , sourceFile ) ;
532
523
default :
533
524
return true ;
534
525
}
0 commit comments