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", () => { 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() {