Merge pull request #16621 from aozgaa/formattingAfterParseError

Formatting after parse error
This commit is contained in:
Arthur Ozga 2017-08-16 20:49:29 -07:00 committed by GitHub
commit 0d94d497df
6 changed files with 17 additions and 8 deletions

View file

@ -398,7 +398,6 @@ namespace ts.formatting {
// formatting context is used by rules provider
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
let previousRangeHasError: boolean;
let previousRange: TextRangeWithKind;
let previousParent: Node;
let previousRangeStartLine: number;
@ -883,7 +882,7 @@ namespace ts.formatting {
const rangeHasError = rangeContainsError(range);
let lineAdded: boolean;
if (!rangeHasError && !previousRangeHasError) {
if (!rangeHasError) {
if (!previousRange) {
// trim whitespaces starting from the beginning of the span up to the current line
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
@ -898,7 +897,6 @@ namespace ts.formatting {
previousRange = range;
previousParent = parent;
previousRangeStartLine = rangeStart.line;
previousRangeHasError = rangeHasError;
return lineAdded;
}

View file

@ -2,4 +2,4 @@
////function f( f: function){/*1*/
goTo.marker("1");
edit.insert("}");
verify.currentLineContentIs("function f(f: function) { }")
verify.currentLineContentIs("function f(f: function) { }");

View file

@ -0,0 +1,11 @@
/// <reference path="fourslash.ts"/>
//// if () {
//// }
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
format.document();
verify.currentFileContentIs(
`if ()
{
}`);

View file

@ -4,6 +4,6 @@
/////*2*/type Stylet = { new () {} }
format.document();
goTo.marker("1");
verify.currentLineContentIs("interface Gourai { new() {} }");
verify.currentLineContentIs("interface Gourai { new() { } }");
goTo.marker("2");
verify.currentLineContentIs("type Stylet = { new() {} }");
verify.currentLineContentIs("type Stylet = { new() { } }");

View file

@ -14,7 +14,7 @@ verify.currentLineContentIs('foo(): Bar { }');
goTo.marker('2');
verify.currentLineContentIs('function Foo() # { }');
goTo.marker('3');
verify.currentLineContentIs('4 +:5');
verify.currentLineContentIs('4 +: 5');
goTo.marker('4');
verify.currentLineContentIs(' : T) { }');
goTo.marker('5');

View file

@ -336,7 +336,7 @@ declare namespace FourSlashInterface {
setFormatOptions(options: FormatCodeOptions): any;
selection(startMarker: string, endMarker: 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 {
resetCancelled(): void;