diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 793e17d52e7..948a2982a5f 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -32,7 +32,7 @@ namespace ts.server { children: ScriptInfo[] = []; // files referenced by this file defaultProject: Project; // project to use by default for file fileWatcher: FileWatcher; - formatCodeOptions = ts.clone(CompilerService.defaultFormatCodeOptions); + formatCodeOptions = ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)); path: Path; scriptKind: ScriptKind; @@ -542,7 +542,7 @@ namespace ts.server { addDefaultHostConfiguration() { this.hostConfiguration = { - formatCodeOptions: ts.clone(CompilerService.defaultFormatCodeOptions), + formatCodeOptions: ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)), hostInfo: "Unknown host" }; } @@ -1377,23 +1377,25 @@ namespace ts.server { return ts.isExternalModule(sourceFile); } - static defaultFormatCodeOptions: ts.FormatCodeOptions = { - IndentSize: 4, - TabSize: 4, - NewLineCharacter: ts.sys ? ts.sys.newLine : "\n", - ConvertTabsToSpaces: true, - IndentStyle: ts.IndentStyle.Smart, - InsertSpaceAfterCommaDelimiter: true, - InsertSpaceAfterSemicolonInForStatements: true, - InsertSpaceBeforeAndAfterBinaryOperators: true, - InsertSpaceAfterKeywordsInControlFlowStatements: true, - InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, - InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, - PlaceOpenBraceOnNewLineForFunctions: false, - PlaceOpenBraceOnNewLineForControlBlocks: false, - }; + static getDefaultFormatCodeOptions(host: ServerHost): ts.FormatCodeOptions { + return ts.clone({ + IndentSize: 4, + TabSize: 4, + NewLineCharacter: host.newLine || "\n", + ConvertTabsToSpaces: true, + IndentStyle: ts.IndentStyle.Smart, + InsertSpaceAfterCommaDelimiter: true, + InsertSpaceAfterSemicolonInForStatements: true, + InsertSpaceBeforeAndAfterBinaryOperators: true, + InsertSpaceAfterKeywordsInControlFlowStatements: true, + InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, + InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, + PlaceOpenBraceOnNewLineForFunctions: false, + PlaceOpenBraceOnNewLineForControlBlocks: false, + }); + } } export interface LineCollection {