Skip to content

Reload the text from file if there is pending reload of the script info before determining to use SVC #22151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<protocol.OpenRequest>({
command: protocol.CommandTypes.Open,
arguments: { file: file2.path, fileContent: file2.content }
});
session.executeCommandSeq<protocol.OpenRequest>({
command: protocol.CommandTypes.Open,
arguments: { file: file1.path }
});
session.executeCommandSeq<protocol.CloseRequest>({
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<protocol.GetApplicableRefactorsRequest>({
command: protocol.CommandTypes.GetApplicableRefactors,
arguments: { file: file2.path, startLine: 1, startOffset, endLine: 1, endOffset: startOffset + 1 }
});

});
});

describe("tsserverProjectSystem Proper errors", () => {
Expand Down
9 changes: 7 additions & 2 deletions src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

@aozgaa aozgaa Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this.pendingReloadFromDisk be set to false here or in a callee after the reload completes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does get set whenever the text is reloaded into the script info. (https://github.com/Microsoft/TypeScript/pull/22151/files#diff-f56eebffea5b0d2286bb5998c67920e9L78)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that. Thanks!

this.reloadWithFileText();
}

// At this point if svc is present its valid
return this.svc;
}

private getOrLoadText() {
Expand Down