Skip to content

Commit eb5797f

Browse files
authored
Merge pull request #20211 from amcasey/GH20084
Update project on PackageInstalledResponse
2 parents 8e6642e + 82aa518 commit eb5797f

File tree

8 files changed

+36
-25
lines changed

8 files changed

+36
-25
lines changed

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ namespace ts.server {
540540
}
541541
}
542542

543-
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings): void {
543+
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse): void {
544544
const project = this.findProject(response.projectName);
545545
if (!project) {
546546
return;

src/server/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ namespace ts.server {
249249
return this.typingsCache.isKnownTypesPackageName(name);
250250
}
251251
installPackage(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult> {
252-
return this.typingsCache.installPackage({ ...options, projectRootPath: this.toPath(this.currentDirectory) });
252+
return this.typingsCache.installPackage({ ...options, projectName: this.projectName, projectRootPath: this.toPath(this.currentDirectory) });
253253
}
254254
private get typingsCache(): TypingsCache {
255255
return this.projectService.typingsCache;

src/server/server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ namespace ts.server {
290290
return false;
291291
}
292292

293-
installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise<ApplyCodeActionCommandResult> {
293+
installPackage(options: InstallPackageOptionsWithProject): Promise<ApplyCodeActionCommandResult> {
294294
const rq: InstallPackageRequest = { kind: "installPackage", ...options };
295295
this.send(rq);
296296
Debug.assert(this.packageInstalledPromise === undefined);
@@ -392,7 +392,7 @@ namespace ts.server {
392392
case EventTypesRegistry:
393393
this.typesRegistryCache = ts.createMapFromTemplate(response.typesRegistry);
394394
break;
395-
case EventPackageInstalled: {
395+
case ActionPackageInstalled: {
396396
const { success, message } = response;
397397
if (success) {
398398
this.packageInstalledPromise.resolve({ successMessage: message });
@@ -401,6 +401,11 @@ namespace ts.server {
401401
this.packageInstalledPromise.reject(message);
402402
}
403403
this.packageInstalledPromise = undefined;
404+
405+
this.projectService.updateTypingsForProject(response);
406+
407+
// The behavior is the same as for setTypings, so send the same event.
408+
this.event(response, "setTypings");
404409
break;
405410
}
406411
case EventInitializationFailed:

src/server/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace ts.server {
44
// tslint:disable variable-name
55
export const ActionSet: ActionSet = "action::set";
66
export const ActionInvalidate: ActionInvalidate = "action::invalidate";
7+
export const ActionPackageInstalled: ActionPackageInstalled = "action::packageInstalled";
78
export const EventTypesRegistry: EventTypesRegistry = "event::typesRegistry";
8-
export const EventPackageInstalled: EventPackageInstalled = "event::packageInstalled";
99
export const EventBeginInstallTypes: EventBeginInstallTypes = "event::beginInstallTypes";
1010
export const EventEndInstallTypes: EventEndInstallTypes = "event::endInstallTypes";
1111
export const EventInitializationFailed: EventInitializationFailed = "event::initializationFailed";

src/server/types.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare namespace ts.server {
5353
readonly kind: "typesRegistry";
5454
}
5555

56-
export interface InstallPackageRequest {
56+
export interface InstallPackageRequest extends TypingInstallerRequestWithProjectName {
5757
readonly kind: "installPackage";
5858
readonly fileName: Path;
5959
readonly packageName: string;
@@ -62,14 +62,14 @@ declare namespace ts.server {
6262

6363
export type ActionSet = "action::set";
6464
export type ActionInvalidate = "action::invalidate";
65+
export type ActionPackageInstalled = "action::packageInstalled";
6566
export type EventTypesRegistry = "event::typesRegistry";
66-
export type EventPackageInstalled = "event::packageInstalled";
6767
export type EventBeginInstallTypes = "event::beginInstallTypes";
6868
export type EventEndInstallTypes = "event::endInstallTypes";
6969
export type EventInitializationFailed = "event::initializationFailed";
7070

7171
export interface TypingInstallerResponse {
72-
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | EventPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
72+
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
7373
}
7474
/* @internal */
7575
export type TypingInstallerResponseUnion = SetTypings | InvalidateCachedTypings | TypesRegistryResponse | PackageInstalledResponse | InstallTypes | InitializationFailedResponse;
@@ -80,9 +80,8 @@ declare namespace ts.server {
8080
readonly typesRegistry: MapLike<void>;
8181
}
8282

83-
/* @internal */
84-
export interface PackageInstalledResponse extends TypingInstallerResponse {
85-
readonly kind: EventPackageInstalled;
83+
export interface PackageInstalledResponse extends ProjectResponse {
84+
readonly kind: ActionPackageInstalled;
8685
readonly success: boolean;
8786
readonly message: string;
8887
}

src/server/typingsCache.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/// <reference path="project.ts"/>
22

33
namespace ts.server {
4-
export interface InstallPackageOptionsWithProjectRootPath extends InstallPackageOptions {
4+
export interface InstallPackageOptionsWithProject extends InstallPackageOptions {
5+
projectName: string;
56
projectRootPath: Path;
67
}
78

89
// tslint:disable-next-line interface-name (for backwards-compatibility)
910
export interface ITypingsInstaller {
1011
isKnownTypesPackageName(name: string): boolean;
11-
installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise<ApplyCodeActionCommandResult>;
12+
installPackage(options: InstallPackageOptionsWithProject): Promise<ApplyCodeActionCommandResult>;
1213
enqueueInstallTypingsRequest(p: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray<string>): void;
1314
attach(projectService: ProjectService): void;
1415
onProjectClosed(p: Project): void;
@@ -91,7 +92,7 @@ namespace ts.server {
9192
return this.installer.isKnownTypesPackageName(name);
9293
}
9394

94-
installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise<ApplyCodeActionCommandResult> {
95+
installPackage(options: InstallPackageOptionsWithProject): Promise<ApplyCodeActionCommandResult> {
9596
return this.installer.installPackage(options);
9697
}
9798

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ namespace ts.server.typingsInstaller {
150150
break;
151151
}
152152
case "installPackage": {
153-
const { fileName, packageName, projectRootPath } = req;
153+
const { fileName, packageName, projectName, projectRootPath } = req;
154154
const cwd = getDirectoryOfPackageJson(fileName, this.installTypingHost) || projectRootPath;
155155
if (cwd) {
156156
this.installWorker(-1, [packageName], cwd, success => {
157157
const message = success ? `Package ${packageName} installed.` : `There was an error installing ${packageName}.`;
158-
const response: PackageInstalledResponse = { kind: EventPackageInstalled, success, message };
158+
const response: PackageInstalledResponse = { kind: ActionPackageInstalled, projectName, success, message };
159159
this.sendResponse(response);
160160
});
161161
}
162162
else {
163-
const response: PackageInstalledResponse = { kind: EventPackageInstalled, success: false, message: "Could not determine a project root path." };
163+
const response: PackageInstalledResponse = { kind: ActionPackageInstalled, projectName, success: false, message: "Could not determine a project root path." };
164164
this.sendResponse(response);
165165
}
166166
break;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4716,21 +4716,26 @@ declare namespace ts.server {
47164716
interface TypesRegistryRequest {
47174717
readonly kind: "typesRegistry";
47184718
}
4719-
interface InstallPackageRequest {
4719+
interface InstallPackageRequest extends TypingInstallerRequestWithProjectName {
47204720
readonly kind: "installPackage";
47214721
readonly fileName: Path;
47224722
readonly packageName: string;
47234723
readonly projectRootPath: Path;
47244724
}
47254725
type ActionSet = "action::set";
47264726
type ActionInvalidate = "action::invalidate";
4727+
type ActionPackageInstalled = "action::packageInstalled";
47274728
type EventTypesRegistry = "event::typesRegistry";
4728-
type EventPackageInstalled = "event::packageInstalled";
47294729
type EventBeginInstallTypes = "event::beginInstallTypes";
47304730
type EventEndInstallTypes = "event::endInstallTypes";
47314731
type EventInitializationFailed = "event::initializationFailed";
47324732
interface TypingInstallerResponse {
4733-
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | EventPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
4733+
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
4734+
}
4735+
interface PackageInstalledResponse extends ProjectResponse {
4736+
readonly kind: ActionPackageInstalled;
4737+
readonly success: boolean;
4738+
readonly message: string;
47344739
}
47354740
interface InitializationFailedResponse extends TypingInstallerResponse {
47364741
readonly kind: EventInitializationFailed;
@@ -4766,8 +4771,8 @@ declare namespace ts.server {
47664771
declare namespace ts.server {
47674772
const ActionSet: ActionSet;
47684773
const ActionInvalidate: ActionInvalidate;
4774+
const ActionPackageInstalled: ActionPackageInstalled;
47694775
const EventTypesRegistry: EventTypesRegistry;
4770-
const EventPackageInstalled: EventPackageInstalled;
47714776
const EventBeginInstallTypes: EventBeginInstallTypes;
47724777
const EventEndInstallTypes: EventEndInstallTypes;
47734778
const EventInitializationFailed: EventInitializationFailed;
@@ -7125,12 +7130,13 @@ declare namespace ts.server {
71257130
}
71267131
}
71277132
declare namespace ts.server {
7128-
interface InstallPackageOptionsWithProjectRootPath extends InstallPackageOptions {
7133+
interface InstallPackageOptionsWithProject extends InstallPackageOptions {
7134+
projectName: string;
71297135
projectRootPath: Path;
71307136
}
71317137
interface ITypingsInstaller {
71327138
isKnownTypesPackageName(name: string): boolean;
7133-
installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise<ApplyCodeActionCommandResult>;
7139+
installPackage(options: InstallPackageOptionsWithProject): Promise<ApplyCodeActionCommandResult>;
71347140
enqueueInstallTypingsRequest(p: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray<string>): void;
71357141
attach(projectService: ProjectService): void;
71367142
onProjectClosed(p: Project): void;
@@ -7142,7 +7148,7 @@ declare namespace ts.server {
71427148
private readonly perProjectCache;
71437149
constructor(installer: ITypingsInstaller);
71447150
isKnownTypesPackageName(name: string): boolean;
7145-
installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise<ApplyCodeActionCommandResult>;
7151+
installPackage(options: InstallPackageOptionsWithProject): Promise<ApplyCodeActionCommandResult>;
71467152
getTypingsForProject(project: Project, unresolvedImports: SortedReadonlyArray<string>, forceRefresh: boolean): SortedReadonlyArray<string>;
71477153
updateTypingsForProject(projectName: string, compilerOptions: CompilerOptions, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray<string>, newTypings: string[]): void;
71487154
deleteTypingsForProject(projectName: string): void;
@@ -7566,7 +7572,7 @@ declare namespace ts.server {
75667572
private createWatcherLog(watchType, project);
75677573
toPath(fileName: string): Path;
75687574
private loadTypesMap();
7569-
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings): void;
7575+
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse): void;
75707576
private delayInferredProjectsRefresh();
75717577
private delayUpdateProjectGraph(project);
75727578
private sendProjectsUpdatedInBackgroundEvent();

0 commit comments

Comments
 (0)