Skip to content

fix(41736): tsserver should not crash if external file does not exist #41737

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 1 commit into from
Dec 1, 2020
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
4 changes: 2 additions & 2 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,8 @@ namespace ts.server {
// by the host for files in the program when the program is retrieved above but
// the program doesn't contain external files so this must be done explicitly.
inserted => {
const scriptInfo = this.projectService.getOrCreateScriptInfoNotOpenedByClient(inserted, this.currentDirectory, this.directoryStructureHost)!;
scriptInfo.attachToProject(this);
const scriptInfo = this.projectService.getOrCreateScriptInfoNotOpenedByClient(inserted, this.currentDirectory, this.directoryStructureHost);
scriptInfo?.attachToProject(this);
},
removed => this.detachScriptInfoFromProject(removed)
);
Expand Down
39 changes: 39 additions & 0 deletions src/testRunner/unittests/tsserver/externalProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,5 +898,44 @@ namespace ts.projectSystem {
const jsConfigProject = service.configuredProjects.get(jsConfig.path.toLowerCase())!;
checkProjectActualFiles(jsConfigProject, [jsConfig.path, jsFilePath, libFile.path]);
});

it("does not crash if external file does not exist", () => {
const f1 = {
path: "/a/file1.ts",
content: "let x = [1, 2];",
};
const p1 = {
projectFileName: "/a/proj1.csproj",
rootFiles: [toExternalFile(f1.path)],
options: {},
};

const host = createServerHost([f1]);
host.require = (_initialPath, moduleName) => {
assert.equal(moduleName, "myplugin");
return {
module: () => ({
create(info: server.PluginCreateInfo) {
return Harness.LanguageService.makeDefaultProxy(info);
},
getExternalFiles() {
return ["/does/not/exist"];
},
}),
error: undefined,
};
};
const session = createSession(host, {
globalPlugins: ["myplugin"],
});
const projectService = session.getProjectService();
// When the external project is opened, the graph will be updated,
// and in the process getExternalFiles() above will be called.
// Since the external file does not exist, there will not be a script
// info for it. If tsserver does not handle this case, the following
// method call will crash.
projectService.openExternalProject(p1);
checkNumberOfProjects(projectService, { externalProjects: 1 });
});
});
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy