Ensure formatter can always get a newline character (#38579)

* Ensure formatter can always get a newline character

* Make FormatContext.host optional since it’s not necessary if format options are all applied

* Make FormattingHost required again
This commit is contained in:
Andrew Branch
2020-05-19 13:14:32 -07:00
committed by GitHub
parent 611dd22b9a
commit 707e977056
12 changed files with 61 additions and 21 deletions

View File

@@ -515,6 +515,12 @@ namespace FourSlash {
}
}
public verifyOrganizeImports(newContent: string) {
const changes = this.languageService.organizeImports({ fileName: this.activeFile.fileName, type: "file" }, this.formatCodeSettings, ts.emptyOptions);
this.applyChanges(changes);
this.verifyFileContent(this.activeFile.fileName, newContent);
}
private raiseError(message: string): never {
throw new Error(this.messageAtLastKnownMarker(message));
}

View File

@@ -560,6 +560,10 @@ namespace FourSlashInterface {
public noMoveToNewFile(): void {
this.state.noMoveToNewFile();
}
public organizeImports(newContent: string) {
this.state.verifyOrganizeImports(newContent);
}
}
export class Edit {