diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index a74697b8026..a9295fe54a1 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -34,6 +34,7 @@ "onCommand:javascript.reloadProjects" ], "main": "./out/typescriptMain", + "enableProposedApi": true, "contributes": { "languages": [ { @@ -299,4 +300,4 @@ } ] } -} \ No newline at end of file +} diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index a9e95cd39f5..c8f0af9ee04 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -40,7 +40,7 @@ import ReferenceCodeLensProvider from './features/referencesCodeLensProvider'; import * as BuildStatus from './utils/buildStatus'; import * as ProjectStatus from './utils/projectStatus'; -import TypingsStatus from './utils/typingsStatus'; +import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus'; import * as VersionStatus from './utils/versionStatus'; interface LanguageDescription { @@ -128,6 +128,7 @@ class LanguageProvider { this.currentDiagnostics = languages.createDiagnosticCollection(description.id); this.typingsStatus = new TypingsStatus(client); + new AtaProgressReporter(client); workspace.onDidChangeConfiguration(this.configurationChanged, this); this.configurationChanged(); diff --git a/extensions/typescript/src/utils/typingsStatus.ts b/extensions/typescript/src/utils/typingsStatus.ts index cd1d7e8e91a..de5cd9d291e 100644 --- a/extensions/typescript/src/utils/typingsStatus.ts +++ b/extensions/typescript/src/utils/typingsStatus.ts @@ -3,10 +3,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +/// + 'use strict'; import * as vscode from 'vscode'; import { ITypescriptServiceClient } from '../typescriptService'; +import { loadMessageBundle } from 'vscode-nls'; +const localize = loadMessageBundle(); const typingsInstallTimeout = 30 * 1000; @@ -54,4 +58,42 @@ export default class TypingsStatus extends vscode.Disposable { } delete this._acquiringTypings[eventId]; } -} \ No newline at end of file +} + +export class AtaProgressReporter { + + private _promises = new Map(); + private _disposable: vscode.Disposable; + + constructor(client: ITypescriptServiceClient) { + this._disposable = vscode.Disposable.from( + client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)), + client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)) + ); + } + + dispose(): void { + this._disposable.dispose(); + this._promises.forEach(value => value()); + } + + private _onBegin(eventId: number): void { + const handle = setTimeout(() => this._onEndOrTimeout(eventId), typingsInstallTimeout); + const promise = new Promise(resolve => { + this._promises.set(eventId, () => { + clearTimeout(handle); + resolve(); + }); + }); + + vscode.window.withWindowProgress(localize('installingPackages', "Fetching data for better TypeScript IntelliSense"), () => promise); + } + + private _onEndOrTimeout(eventId: number): void { + const resolve = this._promises.get(eventId); + if (resolve) { + this._promises.delete(eventId); + resolve(); + } + } +}