apply formatting after parse error

This commit is contained in:
Arthur Ozga
2017-06-19 10:57:47 -07:00
parent a2776648cd
commit 2a2595fc5f
3 changed files with 18 additions and 4 deletions

View File

@@ -363,7 +363,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;
@@ -848,7 +847,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);
@@ -863,7 +862,6 @@ namespace ts.formatting {
previousRange = range;
previousParent = parent;
previousRangeStartLine = rangeStart.line;
previousRangeHasError = rangeHasError;
return lineAdded;
}

View File

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

View File

@@ -329,7 +329,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;