Skip to content

Commit 0d94d49

Browse files
authored
Merge pull request #16621 from aozgaa/formattingAfterParseError
Formatting after parse error
2 parents d4fecd4 + bc0c9a4 commit 0d94d49

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

src/services/formatting/formatting.ts

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

399399
// formatting context is used by rules provider
400400
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
401-
let previousRangeHasError: boolean;
402401
let previousRange: TextRangeWithKind;
403402
let previousParent: Node;
404403
let previousRangeStartLine: number;
@@ -883,7 +882,7 @@ namespace ts.formatting {
883882

884883
const rangeHasError = rangeContainsError(range);
885884
let lineAdded: boolean;
886-
if (!rangeHasError && !previousRangeHasError) {
885+
if (!rangeHasError) {
887886
if (!previousRange) {
888887
// trim whitespaces starting from the beginning of the span up to the current line
889888
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
@@ -898,7 +897,6 @@ namespace ts.formatting {
898897
previousRange = range;
899898
previousParent = parent;
900899
previousRangeStartLine = rangeStart.line;
901-
previousRangeHasError = rangeHasError;
902900

903901
return lineAdded;
904902
}

tests/cases/fourslash/formatEmptyParamList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
////function f( f: function){/*1*/
33
goTo.marker("1");
44
edit.insert("}");
5-
verify.currentLineContentIs("function f(f: function) { }")
5+
verify.currentLineContentIs("function f(f: function) { }");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// if () {
4+
//// }
5+
6+
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
7+
format.document();
8+
verify.currentFileContentIs(
9+
`if ()
10+
{
11+
}`);

tests/cases/fourslash/formattingOnConstructorSignature.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
/////*2*/type Stylet = { new () {} }
55
format.document();
66
goTo.marker("1");
7-
verify.currentLineContentIs("interface Gourai { new() {} }");
7+
verify.currentLineContentIs("interface Gourai { new() { } }");
88
goTo.marker("2");
9-
verify.currentLineContentIs("type Stylet = { new() {} }");
9+
verify.currentLineContentIs("type Stylet = { new() { } }");

tests/cases/fourslash/formattingSkippedTokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ verify.currentLineContentIs('foo(): Bar { }');
1414
goTo.marker('2');
1515
verify.currentLineContentIs('function Foo() # { }');
1616
goTo.marker('3');
17-
verify.currentLineContentIs('4 +:5');
17+
verify.currentLineContentIs('4 +: 5');
1818
goTo.marker('4');
1919
verify.currentLineContentIs(' : T) { }');
2020
goTo.marker('5');

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ declare namespace FourSlashInterface {
336336
setFormatOptions(options: FormatCodeOptions): any;
337337
selection(startMarker: string, endMarker: string): void;
338338
onType(posMarker: string, key: string): void;
339-
setOption(name: string, value: number | string | boolean): void;
339+
setOption(name: keyof FormatCodeOptions, value: number | string | boolean): void;
340340
}
341341
class cancellation {
342342
resetCancelled(): void;

0 commit comments

Comments
 (0)