Skip to content

Commit e2a0551

Browse files
committed
Update project on PackageInstalledResponse
As with `SetTypings`, new typings have been installed so the project should be updated and the client should be notified (via event). Changed PackageInstalledResponse from "event" to "action" for the sake of explicitness. Fixes microsoft#20084.
1 parent 761c739 commit e2a0551

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
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;

0 commit comments

Comments
 (0)