From 8290f8bf422d520af18f242c7965487b70c5aa6b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 14 Dec 2016 14:40:04 -0800 Subject: [PATCH 1/3] Normalize line endings for lib files while building them --- Jakefile.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 17346e8bc1f..275303dda13 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -353,19 +353,16 @@ function prependFile(prefixFile, destinationFile) { // concatenate a list of sourceFiles to a destinationFile function concatenateFiles(destinationFile, sourceFiles) { var temp = "temptemp"; - // Copy the first file to temp - if (!fs.existsSync(sourceFiles[0])) { - fail(sourceFiles[0] + " does not exist!"); - } - jake.cpR(sourceFiles[0], temp, { silent: true }); // append all files in sequence - for (var i = 1; i < sourceFiles.length; i++) { + var text = ""; + for (var i = 0; i < sourceFiles.length; i++) { if (!fs.existsSync(sourceFiles[i])) { fail(sourceFiles[i] + " does not exist!"); } - fs.appendFileSync(temp, "\n\n"); - fs.appendFileSync(temp, fs.readFileSync(sourceFiles[i])); + if (i > 0) { text += "\n\n"; } + text += fs.readFileSync(sourceFiles[i]).toString().replace(/\r?\n/g, "\n"); } + fs.writeFileSync(temp, text); // Move the file to the final destination fs.renameSync(temp, destinationFile); } From dda24f6d70d971b36535844d15ec69a9ac49fe5b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 14 Dec 2016 14:43:45 -0800 Subject: [PATCH 2/3] allow to compute change ranges only for snapshots from the same script version cache --- .../unittests/tsserverProjectSystem.ts | 27 ++++++++++++++++++- src/server/scriptVersionCache.ts | 4 +-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 783a6016f7a..c1c7828fd3b 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1799,7 +1799,6 @@ namespace ts.projectSystem { }); it("language service disabled state is updated in external projects", () => { - debugger const f1 = { path: "/a/app.js", content: "var x = 1" @@ -1940,6 +1939,32 @@ namespace ts.projectSystem { const edits = project.getLanguageService().getFormattingEditsForDocument(f1.path, options); assert.deepEqual(edits, [{ span: createTextSpan(/*start*/ 7, /*length*/ 3), newText: " " }]); }); + + it("snapshot from different caches are incompatible", () => { + const f1 = { + path: "/a/b/app.ts", + content: "let x = 1;" + }; + debugger + const host = createServerHost([f1]); + const projectFileName = "/a/b/proj.csproj"; + const projectService = createProjectService(host); + projectService.openExternalProject({ + projectFileName, + rootFiles: [toExternalFile(f1.path)], + options: {} + }) + projectService.openClientFile(f1.path, "let x = 1;\nlet y = 2;"); + + projectService.checkNumberOfProjects({ externalProjects: 1 }); + projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path); + projectService.closeClientFile(f1.path); + + projectService.openClientFile(f1.path); + projectService.checkNumberOfProjects({ externalProjects: 1 }); + const navbar = projectService.externalProjects[0].getLanguageService(/*ensureSynchronized*/false).getNavigationBarItems(f1.path); + assert.equal(navbar[0].spans[0].length, f1.content.length); + }); }); describe("Proper errors", () => { diff --git a/src/server/scriptVersionCache.ts b/src/server/scriptVersionCache.ts index aaf04d39a1f..e087c3b6dde 100644 --- a/src/server/scriptVersionCache.ts +++ b/src/server/scriptVersionCache.ts @@ -398,7 +398,7 @@ namespace ts.server { index: LineIndex; changesSincePreviousVersion: TextChange[] = []; - constructor(public version: number, public cache: ScriptVersionCache) { + constructor(readonly version: number, readonly cache: ScriptVersionCache) { } getText(rangeStart: number, rangeEnd: number) { @@ -438,7 +438,7 @@ namespace ts.server { } } getChangeRange(oldSnapshot: ts.IScriptSnapshot): ts.TextChangeRange { - if (oldSnapshot instanceof LineIndexSnapshot) { + if (oldSnapshot instanceof LineIndexSnapshot && this.cache === oldSnapshot.cache) { return this.getTextChangeRangeSinceVersion(oldSnapshot.version); } } From 321b23525acca61a06fdef42c509d9d9fdc6efa2 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 14 Dec 2016 15:01:46 -0800 Subject: [PATCH 3/3] remove debugger statement --- src/harness/unittests/tsserverProjectSystem.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index c1c7828fd3b..13d8a6bf824 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1945,7 +1945,6 @@ namespace ts.projectSystem { path: "/a/b/app.ts", content: "let x = 1;" }; - debugger const host = createServerHost([f1]); const projectFileName = "/a/b/proj.csproj"; const projectService = createProjectService(host);