From ab09d67b49cd0298fb5ea94ba21fb7af430cf4b6 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 14 May 2020 12:22:17 -0700 Subject: [PATCH] =?UTF-8?q?Make=20FormatContext.host=20optional=20since=20?= =?UTF-8?q?it=E2=80=99s=20not=20necessary=20if=20format=20options=20are=20?= =?UTF-8?q?all=20applied?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/formatting/formatting.ts | 2 +- src/services/types.ts | 4 +++- src/services/utilities.ts | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 951ad5e5bba..d9553ea3465 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -3,7 +3,7 @@ namespace ts.formatting { export interface FormatContext { readonly options: FormatCodeSettings; readonly getRules: RulesMap; - readonly host: FormattingHost; + readonly host?: FormattingHost; } export interface TextRangeWithKind extends TextRange { diff --git a/src/services/types.ts b/src/services/types.ts index d40b94ae065..fd8ade8f8e6 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -203,6 +203,7 @@ namespace ts { has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean; } + /** @internal */ export interface FormattingHost { getNewLine?(): string; } @@ -210,8 +211,9 @@ namespace ts { // // Public interface of the host of a language service instance. // - export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, FormattingHost { + export interface LanguageServiceHost extends GetEffectiveTypeRootsHost { getCompilationSettings(): CompilerOptions; + getNewLine?(): string; getProjectVersion?(): string; getScriptFileNames(): string[]; getScriptKind?(fileName: string): ScriptKind; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index a5d733dd24f..2c551fe9d7c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2085,9 +2085,9 @@ namespace ts { /** * The default is CRLF. */ - export function getNewLineOrDefaultFromHost(host: FormattingHost, formatSettings?: FormatCodeSettings) { - return (formatSettings && formatSettings.newLineCharacter) || - (host.getNewLine && host.getNewLine()) || + export function getNewLineOrDefaultFromHost(host: FormattingHost | undefined, formatSettings?: FormatCodeSettings) { + return formatSettings?.newLineCharacter || + host?.getNewLine?.() || carriageReturnLineFeed; }