diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index aa169baa33230..d3d2a41e5d59d 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -534,7 +534,7 @@ namespace ts.server { } } - updateTypingsForProject(response: SetTypings | InvalidateCachedTypings): void { + updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse): void { const project = this.findProject(response.projectName); if (!project) { return; diff --git a/src/server/project.ts b/src/server/project.ts index 71be32744811b..75c1afc87c8ed 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -251,7 +251,7 @@ namespace ts.server { return this.typingsCache.isKnownTypesPackageName(name); } installPackage(options: InstallPackageOptions): Promise { - return this.typingsCache.installPackage({ ...options, projectRootPath: this.toPath(this.currentDirectory) }); + return this.typingsCache.installPackage({ ...options, projectName: this.projectName, projectRootPath: this.toPath(this.currentDirectory) }); } private get typingsCache(): TypingsCache { return this.projectService.typingsCache; diff --git a/src/server/server.ts b/src/server/server.ts index 3a1244c4b44dc..5a2d314241552 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -297,7 +297,7 @@ namespace ts.server { return false; } - installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise { + installPackage(options: InstallPackageOptionsWithProject): Promise { const rq: InstallPackageRequest = { kind: "installPackage", ...options }; this.send(rq); Debug.assert(this.packageInstalledPromise === undefined); @@ -416,7 +416,7 @@ namespace ts.server { case EventTypesRegistry: this.typesRegistryCache = ts.createMapFromTemplate(response.typesRegistry); break; - case EventPackageInstalled: { + case ActionPackageInstalled: { const { success, message } = response; if (success) { this.packageInstalledPromise.resolve({ successMessage: message }); @@ -425,6 +425,14 @@ namespace ts.server { this.packageInstalledPromise.reject(message); } this.packageInstalledPromise = undefined; + + this.projectService.updateTypingsForProject(response); + + // The behavior is the same as for setTypings, so send the same event. + if (this.socket) { + this.sendEvent(0, "setTypings", response); + } + break; } case EventInitializationFailed: diff --git a/src/server/shared.ts b/src/server/shared.ts index a8a122c3327ee..27bd0b650a30e 100644 --- a/src/server/shared.ts +++ b/src/server/shared.ts @@ -3,8 +3,8 @@ namespace ts.server { export const ActionSet: ActionSet = "action::set"; export const ActionInvalidate: ActionInvalidate = "action::invalidate"; + export const ActionPackageInstalled: ActionPackageInstalled = "action::packageInstalled"; export const EventTypesRegistry: EventTypesRegistry = "event::typesRegistry"; - export const EventPackageInstalled: EventPackageInstalled = "event::packageInstalled"; export const EventBeginInstallTypes: EventBeginInstallTypes = "event::beginInstallTypes"; export const EventEndInstallTypes: EventEndInstallTypes = "event::endInstallTypes"; export const EventInitializationFailed: EventInitializationFailed = "event::initializationFailed"; diff --git a/src/server/types.ts b/src/server/types.ts index af5e121278eff..32132ed278b22 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -53,7 +53,7 @@ declare namespace ts.server { readonly kind: "typesRegistry"; } - export interface InstallPackageRequest { + export interface InstallPackageRequest extends TypingInstallerRequestWithProjectName { readonly kind: "installPackage"; readonly fileName: Path; readonly packageName: string; @@ -62,14 +62,14 @@ declare namespace ts.server { export type ActionSet = "action::set"; export type ActionInvalidate = "action::invalidate"; + export type ActionPackageInstalled = "action::packageInstalled"; export type EventTypesRegistry = "event::typesRegistry"; - export type EventPackageInstalled = "event::packageInstalled"; export type EventBeginInstallTypes = "event::beginInstallTypes"; export type EventEndInstallTypes = "event::endInstallTypes"; export type EventInitializationFailed = "event::initializationFailed"; export interface TypingInstallerResponse { - readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | EventPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed; + readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed; } /* @internal */ export type TypingInstallerResponseUnion = SetTypings | InvalidateCachedTypings | TypesRegistryResponse | PackageInstalledResponse | InstallTypes | InitializationFailedResponse; @@ -80,9 +80,8 @@ declare namespace ts.server { readonly typesRegistry: MapLike; } - /* @internal */ - export interface PackageInstalledResponse extends TypingInstallerResponse { - readonly kind: EventPackageInstalled; + export interface PackageInstalledResponse extends ProjectResponse { + readonly kind: ActionPackageInstalled; readonly success: boolean; readonly message: string; } diff --git a/src/server/typingsCache.ts b/src/server/typingsCache.ts index d6eeaa2cbcf2b..2db9be96747e5 100644 --- a/src/server/typingsCache.ts +++ b/src/server/typingsCache.ts @@ -1,13 +1,14 @@ /// namespace ts.server { - export interface InstallPackageOptionsWithProjectRootPath extends InstallPackageOptions { + export interface InstallPackageOptionsWithProject extends InstallPackageOptions { + projectName: string; projectRootPath: Path; } export interface ITypingsInstaller { isKnownTypesPackageName(name: string): boolean; - installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise; + installPackage(options: InstallPackageOptionsWithProject): Promise; enqueueInstallTypingsRequest(p: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray): void; attach(projectService: ProjectService): void; onProjectClosed(p: Project): void; @@ -90,7 +91,7 @@ namespace ts.server { return this.installer.isKnownTypesPackageName(name); } - installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise { + installPackage(options: InstallPackageOptionsWithProject): Promise { return this.installer.installPackage(options); } diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 2a1036010a733..4e3c52f8592ad 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -150,17 +150,17 @@ namespace ts.server.typingsInstaller { break; } case "installPackage": { - const { fileName, packageName, projectRootPath } = req; + const { fileName, packageName, projectName, projectRootPath } = req; const cwd = getDirectoryOfPackageJson(fileName, this.installTypingHost) || projectRootPath; if (cwd) { this.installWorker(-1, [packageName], cwd, success => { const message = success ? `Package ${packageName} installed.` : `There was an error installing ${packageName}.`; - const response: PackageInstalledResponse = { kind: EventPackageInstalled, success, message }; + const response: PackageInstalledResponse = { kind: ActionPackageInstalled, projectName, success, message }; this.sendResponse(response); }); } else { - const response: PackageInstalledResponse = { kind: EventPackageInstalled, success: false, message: "Could not determine a project root path." }; + const response: PackageInstalledResponse = { kind: ActionPackageInstalled, projectName, success: false, message: "Could not determine a project root path." }; this.sendResponse(response); } break; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 522cfc906c03f..c4266d82b1589 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4699,7 +4699,7 @@ declare namespace ts.server { interface TypesRegistryRequest { readonly kind: "typesRegistry"; } - interface InstallPackageRequest { + interface InstallPackageRequest extends TypingInstallerRequestWithProjectName { readonly kind: "installPackage"; readonly fileName: Path; readonly packageName: string; @@ -4707,13 +4707,18 @@ declare namespace ts.server { } type ActionSet = "action::set"; type ActionInvalidate = "action::invalidate"; + type ActionPackageInstalled = "action::packageInstalled"; type EventTypesRegistry = "event::typesRegistry"; - type EventPackageInstalled = "event::packageInstalled"; type EventBeginInstallTypes = "event::beginInstallTypes"; type EventEndInstallTypes = "event::endInstallTypes"; type EventInitializationFailed = "event::initializationFailed"; interface TypingInstallerResponse { - readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | EventPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed; + readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed; + } + interface PackageInstalledResponse extends ProjectResponse { + readonly kind: ActionPackageInstalled; + readonly success: boolean; + readonly message: string; } interface InitializationFailedResponse extends TypingInstallerResponse { readonly kind: EventInitializationFailed; @@ -4749,8 +4754,8 @@ declare namespace ts.server { declare namespace ts.server { const ActionSet: ActionSet; const ActionInvalidate: ActionInvalidate; + const ActionPackageInstalled: ActionPackageInstalled; const EventTypesRegistry: EventTypesRegistry; - const EventPackageInstalled: EventPackageInstalled; const EventBeginInstallTypes: EventBeginInstallTypes; const EventEndInstallTypes: EventEndInstallTypes; const EventInitializationFailed: EventInitializationFailed; @@ -7092,12 +7097,13 @@ declare namespace ts.server { } } declare namespace ts.server { - interface InstallPackageOptionsWithProjectRootPath extends InstallPackageOptions { + interface InstallPackageOptionsWithProject extends InstallPackageOptions { + projectName: string; projectRootPath: Path; } interface ITypingsInstaller { isKnownTypesPackageName(name: string): boolean; - installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise; + installPackage(options: InstallPackageOptionsWithProject): Promise; enqueueInstallTypingsRequest(p: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray): void; attach(projectService: ProjectService): void; onProjectClosed(p: Project): void; @@ -7109,7 +7115,7 @@ declare namespace ts.server { private readonly perProjectCache; constructor(installer: ITypingsInstaller); isKnownTypesPackageName(name: string): boolean; - installPackage(options: InstallPackageOptionsWithProjectRootPath): Promise; + installPackage(options: InstallPackageOptionsWithProject): Promise; getTypingsForProject(project: Project, unresolvedImports: SortedReadonlyArray, forceRefresh: boolean): SortedReadonlyArray; updateTypingsForProject(projectName: string, compilerOptions: CompilerOptions, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray, newTypings: string[]): void; deleteTypingsForProject(projectName: string): void; @@ -7537,7 +7543,7 @@ declare namespace ts.server { private createWatcherLog(watchType, project); toPath(fileName: string): Path; private loadTypesMap(); - updateTypingsForProject(response: SetTypings | InvalidateCachedTypings): void; + updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse): void; private delayInferredProjectsRefresh(); private delayUpdateProjectGraph(project); private sendProjectsUpdatedInBackgroundEvent();