Skip to content
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 });
});
});
}