Merge pull request #16621 from aozgaa/formattingAfterParseError
Formatting after parse error
This commit is contained in:
commit
0d94d497df
|
@ -398,7 +398,6 @@ namespace ts.formatting {
|
||||||
|
|
||||||
// formatting context is used by rules provider
|
// formatting context is used by rules provider
|
||||||
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
|
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
|
||||||
let previousRangeHasError: boolean;
|
|
||||||
let previousRange: TextRangeWithKind;
|
let previousRange: TextRangeWithKind;
|
||||||
let previousParent: Node;
|
let previousParent: Node;
|
||||||
let previousRangeStartLine: number;
|
let previousRangeStartLine: number;
|
||||||
|
@ -883,7 +882,7 @@ namespace ts.formatting {
|
||||||
|
|
||||||
const rangeHasError = rangeContainsError(range);
|
const rangeHasError = rangeContainsError(range);
|
||||||
let lineAdded: boolean;
|
let lineAdded: boolean;
|
||||||
if (!rangeHasError && !previousRangeHasError) {
|
if (!rangeHasError) {
|
||||||
if (!previousRange) {
|
if (!previousRange) {
|
||||||
// trim whitespaces starting from the beginning of the span up to the current line
|
// trim whitespaces starting from the beginning of the span up to the current line
|
||||||
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
|
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
|
||||||
|
@ -898,7 +897,6 @@ namespace ts.formatting {
|
||||||
previousRange = range;
|
previousRange = range;
|
||||||
previousParent = parent;
|
previousParent = parent;
|
||||||
previousRangeStartLine = rangeStart.line;
|
previousRangeStartLine = rangeStart.line;
|
||||||
previousRangeHasError = rangeHasError;
|
|
||||||
|
|
||||||
return lineAdded;
|
return lineAdded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
////function f( f: function){/*1*/
|
////function f( f: function){/*1*/
|
||||||
goTo.marker("1");
|
goTo.marker("1");
|
||||||
edit.insert("}");
|
edit.insert("}");
|
||||||
verify.currentLineContentIs("function f(f: function) { }")
|
verify.currentLineContentIs("function f(f: function) { }");
|
11
tests/cases/fourslash/formatIfWithEmptyCondition.ts
Normal file
11
tests/cases/fourslash/formatIfWithEmptyCondition.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/// <reference path="fourslash.ts"/>
|
||||||
|
|
||||||
|
//// if () {
|
||||||
|
//// }
|
||||||
|
|
||||||
|
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
|
||||||
|
format.document();
|
||||||
|
verify.currentFileContentIs(
|
||||||
|
`if ()
|
||||||
|
{
|
||||||
|
}`);
|
|
@ -4,6 +4,6 @@
|
||||||
/////*2*/type Stylet = { new () {} }
|
/////*2*/type Stylet = { new () {} }
|
||||||
format.document();
|
format.document();
|
||||||
goTo.marker("1");
|
goTo.marker("1");
|
||||||
verify.currentLineContentIs("interface Gourai { new() {} }");
|
verify.currentLineContentIs("interface Gourai { new() { } }");
|
||||||
goTo.marker("2");
|
goTo.marker("2");
|
||||||
verify.currentLineContentIs("type Stylet = { new() {} }");
|
verify.currentLineContentIs("type Stylet = { new() { } }");
|
|
@ -14,7 +14,7 @@ verify.currentLineContentIs('foo(): Bar { }');
|
||||||
goTo.marker('2');
|
goTo.marker('2');
|
||||||
verify.currentLineContentIs('function Foo() # { }');
|
verify.currentLineContentIs('function Foo() # { }');
|
||||||
goTo.marker('3');
|
goTo.marker('3');
|
||||||
verify.currentLineContentIs('4 +:5');
|
verify.currentLineContentIs('4 +: 5');
|
||||||
goTo.marker('4');
|
goTo.marker('4');
|
||||||
verify.currentLineContentIs(' : T) { }');
|
verify.currentLineContentIs(' : T) { }');
|
||||||
goTo.marker('5');
|
goTo.marker('5');
|
||||||
|
|
|
@ -336,7 +336,7 @@ declare namespace FourSlashInterface {
|
||||||
setFormatOptions(options: FormatCodeOptions): any;
|
setFormatOptions(options: FormatCodeOptions): any;
|
||||||
selection(startMarker: string, endMarker: string): void;
|
selection(startMarker: string, endMarker: string): void;
|
||||||
onType(posMarker: string, key: string): void;
|
onType(posMarker: string, key: string): void;
|
||||||
setOption(name: string, value: number | string | boolean): void;
|
setOption(name: keyof FormatCodeOptions, value: number | string | boolean): void;
|
||||||
}
|
}
|
||||||
class cancellation {
|
class cancellation {
|
||||||
resetCancelled(): void;
|
resetCancelled(): void;
|
||||||
|
|
Loading…
Reference in a new issue