Skip to content

Commit cbef5c2

Browse files
authored
Merge pull request #22151 from Microsoft/svcOfPendingReloadFile
Reload the text from file if there is pending reload of the script info before determining to use SVC
2 parents 6e756b5 + 08ab6eb commit cbef5c2

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,6 +2984,47 @@ namespace ts.projectSystem {
29842984
checkProjectActualFiles(configuredProject, [file.path, filesFile1.path, libFile.path, config.path]);
29852985
}
29862986
});
2987+
2988+
it("requests are done on file on pendingReload but has svc for previous version", () => {
2989+
const projectLocation = "/user/username/projects/project";
2990+
const file1: FileOrFolder = {
2991+
path: `${projectLocation}/src/file1.ts`,
2992+
content: `import { y } from "./file1"; let x = 10;`
2993+
};
2994+
const file2: FileOrFolder = {
2995+
path: `${projectLocation}/src/file2.ts`,
2996+
content: "export let y = 10;"
2997+
};
2998+
const config: FileOrFolder = {
2999+
path: `${projectLocation}/tsconfig.json`,
3000+
content: "{}"
3001+
};
3002+
const files = [file1, file2, libFile, config];
3003+
const host = createServerHost(files);
3004+
const session = createSession(host);
3005+
session.executeCommandSeq<protocol.OpenRequest>({
3006+
command: protocol.CommandTypes.Open,
3007+
arguments: { file: file2.path, fileContent: file2.content }
3008+
});
3009+
session.executeCommandSeq<protocol.OpenRequest>({
3010+
command: protocol.CommandTypes.Open,
3011+
arguments: { file: file1.path }
3012+
});
3013+
session.executeCommandSeq<protocol.CloseRequest>({
3014+
command: protocol.CommandTypes.Close,
3015+
arguments: { file: file2.path }
3016+
});
3017+
3018+
file2.content += "export let z = 10;";
3019+
host.reloadFS(files);
3020+
// Do not let the timeout runs, before executing command
3021+
const startOffset = file2.content.indexOf("y") + 1;
3022+
session.executeCommandSeq<protocol.GetApplicableRefactorsRequest>({
3023+
command: protocol.CommandTypes.GetApplicableRefactors,
3024+
arguments: { file: file2.path, startLine: 1, startOffset, endLine: 1, endOffset: startOffset + 1 }
3025+
});
3026+
3027+
});
29873028
});
29883029

29893030
describe("tsserverProjectSystem Proper errors", () => {

src/server/scriptInfo.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ namespace ts.server {
176176
return this.switchToScriptVersionCache();
177177
}
178178

179-
// Else if the svc is uptodate with the text, we are good
180-
return !this.pendingReloadFromDisk && this.svc;
179+
// If there is pending reload from the disk then, reload the text
180+
if (this.pendingReloadFromDisk) {
181+
this.reloadWithFileText();
182+
}
183+
184+
// At this point if svc is present its valid
185+
return this.svc;
181186
}
182187

183188
private getOrLoadText() {

0 commit comments

Comments
 (0)