Skip to content

Commit

Permalink
Make FormatContext.host optional since it’s not necessary if format o…
Browse files Browse the repository at this point in the history
…ptions are all applied
  • Loading branch information
andrewbranch committed May 14, 2020
1 parent 0a696c9 commit ab09d67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/services/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends SyntaxKind = SyntaxKind> extends TextRange {
Expand Down
4 changes: 3 additions & 1 deletion src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ namespace ts {
has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean;
}

/** @internal */
export interface FormattingHost {
getNewLine?(): string;
}

//
// 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;
Expand Down
6 changes: 3 additions & 3 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ab09d67

Please sign in to comment.