Skip to content

Commit 3820875

Browse files
liukunbasarat
authored andcommitted
respect compiler option newLine (#905)
Since `ntypescript` still using `ts.getNewLineOrDefaultFromHost()` to get new line character, we need provide `getNewLine` function in `LanguageServiceHost`.
1 parent 083f5cd commit 3820875

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

dist/main/lang/core/languageServiceHost2.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
var path = require('path');
33
var fs = require('fs');
4+
var os = require('os');
45
var textBuffer = require('basarat-text-buffer');
56
function createScriptInfo(fileName, text, isOpen) {
67
if (isOpen === void 0) { isOpen = false; }
@@ -206,6 +207,18 @@ var LanguageServiceHost = (function () {
206207
return { preview: preview, position: position };
207208
};
208209
this.getCompilationSettings = function () { return _this.config.project.compilerOptions; };
210+
this.getNewLine = function () {
211+
var eol = os.EOL;
212+
switch (_this.config.project.compilerOptions.newLine) {
213+
case ts.NewLineKind.CarriageReturnLineFeed:
214+
eol = "\r\n";
215+
break;
216+
case ts.NewLineKind.LineFeed:
217+
eol = "\n";
218+
break;
219+
}
220+
return eol;
221+
};
209222
this.getScriptFileNames = function () { return Object.keys(_this.fileNameToScript); };
210223
this.getScriptVersion = function (fileName) {
211224
var script = _this.fileNameToScript[fileName];

dist/main/tsconfig/tsconfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ function rawToTsCompilerOptions(jsonOptions, projectDir) {
141141
var compilerOptions = mixin({}, exports.defaults);
142142
for (var key in jsonOptions) {
143143
if (typescriptEnumMap[key]) {
144-
compilerOptions[key] = typescriptEnumMap[key][jsonOptions[key].toLowerCase()];
144+
var name_1 = jsonOptions[key];
145+
var map = typescriptEnumMap[key];
146+
compilerOptions[key] = map[name_1.toLowerCase()] || map[name_1.toUpperCase()];
145147
}
146148
else {
147149
compilerOptions[key] = jsonOptions[key];

lib/main/lang/core/languageServiceHost2.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path = require('path');
22
import utils = require('../utils');
33
import fs = require('fs');
4+
import os = require('os')
45
import textBuffer = require('basarat-text-buffer');
56

67
import tsconfig = require('../../tsconfig/tsconfig');
@@ -328,6 +329,18 @@ export class LanguageServiceHost implements ts.LanguageServiceHost {
328329
////////////////////////////////////////
329330

330331
getCompilationSettings = () => this.config.project.compilerOptions;
332+
getNewLine = () => {
333+
let eol = os.EOL;
334+
switch (this.config.project.compilerOptions.newLine) {
335+
case ts.NewLineKind.CarriageReturnLineFeed:
336+
eol = "\r\n";
337+
break;
338+
case ts.NewLineKind.LineFeed:
339+
eol = "\n";
340+
break;
341+
}
342+
return eol;
343+
}
331344
getScriptFileNames = (): string[]=> Object.keys(this.fileNameToScript);
332345
getScriptVersion = (fileName: string): string => {
333346
var script = this.fileNameToScript[fileName];

lib/main/tsconfig/tsconfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ function rawToTsCompilerOptions(jsonOptions: CompilerOptions, projectDir: string
299299
var compilerOptions = <ts.CompilerOptions>mixin({}, defaults);
300300
for (var key in jsonOptions) {
301301
if (typescriptEnumMap[key]) {
302-
compilerOptions[key] = typescriptEnumMap[key][jsonOptions[key].toLowerCase()];
302+
let name = jsonOptions[key];
303+
let map = typescriptEnumMap[key];
304+
compilerOptions[key] = map[name.toLowerCase()] || map[name.toUpperCase()];
303305
}
304306
else {
305307
compilerOptions[key] = jsonOptions[key];

0 commit comments

Comments
 (0)