From 4d6b53bae5979394614342f0ef2ed1ce95746a38 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 23 Feb 2018 12:03:13 -0800 Subject: [PATCH 1/2] Add test for scenario when script info being operated is pending on reload but has svc for the previous version Test for #20806 --- .../unittests/tsserverProjectSystem.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index e09dff2a6d5dd..b8232fda1c135 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2978,6 +2978,47 @@ namespace ts.projectSystem { checkProjectActualFiles(configuredProject, [file.path, filesFile1.path, libFile.path, config.path]); } }); + + it("requests are done on file on pendingReload but has svc for previous version", () => { + const projectLocation = "/user/username/projects/project"; + const file1: FileOrFolder = { + path: `${projectLocation}/src/file1.ts`, + content: `import { y } from "./file1"; let x = 10;` + }; + const file2: FileOrFolder = { + path: `${projectLocation}/src/file2.ts`, + content: "export let y = 10;" + }; + const config: FileOrFolder = { + path: `${projectLocation}/tsconfig.json`, + content: "{}" + }; + const files = [file1, file2, libFile, config]; + const host = createServerHost(files); + const session = createSession(host); + session.executeCommandSeq({ + command: protocol.CommandTypes.Open, + arguments: { file: file2.path, fileContent: file2.content } + }); + session.executeCommandSeq({ + command: protocol.CommandTypes.Open, + arguments: { file: file1.path } + }); + session.executeCommandSeq({ + command: protocol.CommandTypes.Close, + arguments: { file: file2.path } + }); + + file2.content += "export let z = 10;"; + host.reloadFS(files); + // Do not let the timeout runs, before executing command + const startOffset = file2.content.indexOf("y") + 1; + session.executeCommandSeq({ + command: protocol.CommandTypes.GetApplicableRefactors, + arguments: { file: file2.path, startLine: 1, startOffset, endLine: 1, endOffset: startOffset + 1 } + }); + + }); }); describe("tsserverProjectSystem Proper errors", () => { From 08ab6eb42dddee1f501998445046653de5aa4eab Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 23 Feb 2018 12:10:24 -0800 Subject: [PATCH 2/2] Reload the text from file if there is pending reload of the script info before determining to use SVC Fixes #20806 --- src/server/scriptInfo.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 6fc4f241f6511..d368acd5ce3e4 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -176,8 +176,13 @@ namespace ts.server { return this.switchToScriptVersionCache(); } - // Else if the svc is uptodate with the text, we are good - return !this.pendingReloadFromDisk && this.svc; + // If there is pending reload from the disk then, reload the text + if (this.pendingReloadFromDisk) { + this.reloadWithFileText(); + } + + // At this point if svc is present its valid + return this.svc; } private getOrLoadText() {