tsserver should use newline provided by the host (#13185)

This commit is contained in:
Vladimir Matveev 2016-12-27 11:59:56 -08:00 committed by GitHub
parent bec32d4721
commit 77a3dfbcfc
3 changed files with 39 additions and 4 deletions

View File

@ -467,6 +467,36 @@ namespace ts.projectSystem {
});
describe("EmitFile test", () => {
it("should respect line endings", () => {
test("\n");
test("\r\n");
function test(newLine: string) {
const lines = ["var x = 1;", "var y = 2;"];
const path = "/a/app";
const f = {
path: path + ".ts",
content: lines.join(newLine)
};
const host = createServerHost([f], { newLine });
const session = createSession(host);
session.executeCommand(<server.protocol.OpenRequest>{
seq: 1,
type: "request",
command: "open",
arguments: { file: f.path }
});
session.executeCommand(<server.protocol.CompileOnSaveEmitFileRequest>{
seq: 2,
type: "request",
command: "compileOnSaveEmitFile",
arguments: { file: f.path }
});
const emitOutput = host.readFile(path + ".js");
assert.equal(emitOutput, f.content + newLine, "content of emit output should be identical with the input + newline");
}
})
it("should emit specified file", () => {
const file1 = {
path: "/a/b/f1.ts",
@ -480,7 +510,7 @@ namespace ts.projectSystem {
path: "/a/b/tsconfig.json",
content: `{}`
};
const host = createServerHost([file1, file2, configFile, libFile]);
const host = createServerHost([file1, file2, configFile, libFile], { newLine: "\r\n" });
const typingsInstaller = createTestTypingsInstaller(host);
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);

View File

@ -141,6 +141,7 @@ namespace ts.projectSystem {
useCaseSensitiveFileNames?: boolean;
executingFilePath?: string;
currentDirectory?: string;
newLine?: string;
}
export function createServerHost(fileOrFolderList: FileOrFolder[], params?: TestServerHostCreationParameters): TestServerHost {
@ -151,7 +152,8 @@ namespace ts.projectSystem {
params.useCaseSensitiveFileNames !== undefined ? params.useCaseSensitiveFileNames : false,
params.executingFilePath || getExecutingFilePathFromLibFile(),
params.currentDirectory || "/",
fileOrFolderList);
fileOrFolderList,
params.newLine);
return host;
}
@ -329,7 +331,6 @@ namespace ts.projectSystem {
export class TestServerHost implements server.ServerHost {
args: string[] = [];
newLine: "\n";
private fs: ts.FileMap<FSEntry>;
private getCanonicalFileName: (s: string) => string;
@ -342,7 +343,7 @@ namespace ts.projectSystem {
private filesOrFolders: FileOrFolder[];
constructor(public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: FileOrFolder[]) {
constructor(public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: FileOrFolder[], public readonly newLine = "\n") {
this.getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
this.toPath = s => toPath(s, currentDirectory, this.getCanonicalFileName);

View File

@ -135,6 +135,10 @@ namespace ts.server {
}
}
getNewLine() {
return this.host.newLine;
}
getProjectVersion() {
return this.project.getProjectVersion();
}