Skip to content

Do not create packagejson imports and auto import provider in partial semantic server mode #40890

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
Oct 2, 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
5 changes: 5 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@ namespace ts.server {

/*@internal*/
getPackageJsonsVisibleToFile(fileName: string, rootDir?: string): readonly PackageJsonInfo[] {
if (this.projectService.serverMode !== LanguageServiceMode.Semantic) return emptyArray;
Copy link
Member

Choose a reason for hiding this comment

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

Slightly afraid of all the places that are going to need to be patched up in the future to check like this, but I guess that's programming

return this.projectService.getPackageJsonsVisibleToFile(fileName, rootDir);
}

Expand Down Expand Up @@ -1669,6 +1670,10 @@ namespace ts.server {
if (this.autoImportProviderHost === false) {
return undefined;
}
if (this.projectService.serverMode !== LanguageServiceMode.Semantic) {
this.autoImportProviderHost = false;
return undefined;
}
if (this.autoImportProviderHost) {
updateProjectIfDirty(this.autoImportProviderHost);
if (this.autoImportProviderHost.isEmpty()) {
Expand Down
31 changes: 31 additions & 0 deletions src/testRunner/unittests/tsserver/partialSemanticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,36 @@ function fooB() { }`
openFilesForSession([file2], session);
checkProjectActualFiles(project, [libFile.path, file2.path, file3.path]);
});

it("should not create autoImportProvider or handle package jsons", () => {
const angularFormsDts: File = {
path: "/node_modules/@angular/forms/forms.d.ts",
content: "export declare class PatternValidator {}",
};
const angularFormsPackageJson: File = {
path: "/node_modules/@angular/forms/package.json",
content: `{ "name": "@angular/forms", "typings": "./forms.d.ts" }`,
};
const tsconfig: File = {
path: "/tsconfig.json",
content: `{ "compilerOptions": { "module": "commonjs" } }`,
};
const packageJson: File = {
path: "/package.json",
content: `{ "dependencies": { "@angular/forms": "*", "@angular/core": "*" } }`
};
const indexTs: File = {
path: "/index.ts",
content: ""
};
const host = createServerHost([angularFormsDts, angularFormsPackageJson, tsconfig, packageJson, indexTs, libFile]);
const session = createSession(host, { serverMode: LanguageServiceMode.PartialSemantic, useSingleInferredProject: true });
const service = session.getProjectService();
openFilesForSession([indexTs], session);
const project = service.inferredProjects[0];
assert.isFalse(project.autoImportProviderHost);
assert.isUndefined(project.getPackageJsonAutoImportProvider());
assert.deepEqual(project.getPackageJsonsForAutoImport(), emptyArray);
});
});
}