Skip to content

Commit 2a2595f

Browse files
author
Arthur Ozga
committed
apply formatting after parse error
1 parent a277664 commit 2a2595f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/services/formatting/formatting.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ namespace ts.formatting {
363363

364364
// formatting context is used by rules provider
365365
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
366-
let previousRangeHasError: boolean;
367366
let previousRange: TextRangeWithKind;
368367
let previousParent: Node;
369368
let previousRangeStartLine: number;
@@ -848,7 +847,7 @@ namespace ts.formatting {
848847

849848
const rangeHasError = rangeContainsError(range);
850849
let lineAdded: boolean;
851-
if (!rangeHasError && !previousRangeHasError) {
850+
if (!rangeHasError) {
852851
if (!previousRange) {
853852
// trim whitespaces starting from the beginning of the span up to the current line
854853
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
@@ -863,7 +862,6 @@ namespace ts.formatting {
863862
previousRange = range;
864863
previousParent = parent;
865864
previousRangeStartLine = rangeStart.line;
866-
previousRangeHasError = rangeHasError;
867865

868866
return lineAdded;
869867
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// if (true) {
4+
//// }
5+
//// if () {
6+
//// }
7+
8+
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
9+
format.document();
10+
verify.currentFileContentIs(
11+
`if (true)
12+
{
13+
}
14+
if ()
15+
{
16+
}`);

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ declare namespace FourSlashInterface {
329329
setFormatOptions(options: FormatCodeOptions): any;
330330
selection(startMarker: string, endMarker: string): void;
331331
onType(posMarker: string, key: string): void;
332-
setOption(name: string, value: number | string | boolean): void;
332+
setOption(name: keyof FormatCodeOptions, value: number | string | boolean): void;
333333
}
334334
class cancellation {
335335
resetCancelled(): void;

0 commit comments

Comments
 (0)