Skip to content

Commit ab09d67

Browse files
committed
Make FormatContext.host optional since it’s not necessary if format options are all applied
1 parent 0a696c9 commit ab09d67

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/services/formatting/formatting.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace ts.formatting {
33
export interface FormatContext {
44
readonly options: FormatCodeSettings;
55
readonly getRules: RulesMap;
6-
readonly host: FormattingHost;
6+
readonly host?: FormattingHost;
77
}
88

99
export interface TextRangeWithKind<T extends SyntaxKind = SyntaxKind> extends TextRange {

src/services/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,17 @@ namespace ts {
203203
has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean;
204204
}
205205

206+
/** @internal */
206207
export interface FormattingHost {
207208
getNewLine?(): string;
208209
}
209210

210211
//
211212
// Public interface of the host of a language service instance.
212213
//
213-
export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, FormattingHost {
214+
export interface LanguageServiceHost extends GetEffectiveTypeRootsHost {
214215
getCompilationSettings(): CompilerOptions;
216+
getNewLine?(): string;
215217
getProjectVersion?(): string;
216218
getScriptFileNames(): string[];
217219
getScriptKind?(fileName: string): ScriptKind;

src/services/utilities.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2085,9 +2085,9 @@ namespace ts {
20852085
/**
20862086
* The default is CRLF.
20872087
*/
2088-
export function getNewLineOrDefaultFromHost(host: FormattingHost, formatSettings?: FormatCodeSettings) {
2089-
return (formatSettings && formatSettings.newLineCharacter) ||
2090-
(host.getNewLine && host.getNewLine()) ||
2088+
export function getNewLineOrDefaultFromHost(host: FormattingHost | undefined, formatSettings?: FormatCodeSettings) {
2089+
return formatSettings?.newLineCharacter ||
2090+
host?.getNewLine?.() ||
20912091
carriageReturnLineFeed;
20922092
}
20932093

0 commit comments

Comments
 (0)