From 40729ec1a9314fc474ccc8808fea469c728d0f43 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 17 Jan 2017 18:23:05 +0100 Subject: [PATCH 1/3] AtaProgressReporter using proposed progress api --- extensions/typescript/package.json | 3 +- extensions/typescript/src/typescriptMain.ts | 3 +- .../typescript/src/utils/typingsStatus.ts | 46 ++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) 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 97c8e8b3140..2e414f7da9f 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..97f837af3f5 100644 --- a/extensions/typescript/src/utils/typingsStatus.ts +++ b/extensions/typescript/src/utils/typingsStatus.ts @@ -3,6 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +/// + 'use strict'; import * as vscode from 'vscode'; @@ -54,4 +56,46 @@ 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, e.packages)), + client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)) + ); + } + + dispose(): void { + this._disposable.dispose(); + this._promises.forEach(value => value()); + } + + private _onBegin(eventId: number, packages: ReadonlyArray): void { + + const handle = setTimeout(() => this._onEndOrTimeout(eventId), typingsInstallTimeout); + const promise = new Promise(resolve => { + this._promises.set(eventId, () => { + clearTimeout(handle); + resolve(); + }); + }); + + vscode.window.withWindowProgress(progress => { + progress.report('Installing packages...'); + return promise; + }); + } + + private _onEndOrTimeout(eventId: number): void { + const resolve = this._promises.get(eventId); + if (resolve) { + this._promises.delete(eventId); + resolve(); + } + } +} From fca283d7d6246d99cf908544bf4051206f947681 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 19 Jan 2017 12:24:59 +0100 Subject: [PATCH 2/3] different api, nicer message --- extensions/typescript/src/utils/typingsStatus.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/typescript/src/utils/typingsStatus.ts b/extensions/typescript/src/utils/typingsStatus.ts index 97f837af3f5..6d1f23439da 100644 --- a/extensions/typescript/src/utils/typingsStatus.ts +++ b/extensions/typescript/src/utils/typingsStatus.ts @@ -9,6 +9,8 @@ import * as vscode from 'vscode'; import { ITypescriptServiceClient } from '../typescriptService'; +import { loadMessageBundle } from 'vscode-nls'; +const localize = loadMessageBundle(); const typingsInstallTimeout = 30 * 1000; @@ -85,10 +87,7 @@ export class AtaProgressReporter { }); }); - vscode.window.withWindowProgress(progress => { - progress.report('Installing packages...'); - return promise; - }); + vscode.window.withWindowProgress(localize('installingPackages', "Fetching data for better TypeScript IntelliSense"), () => promise); } private _onEndOrTimeout(eventId: number): void { From 5262c787bc33d7eaace8813087e8c63fe5ff8296 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 19 Jan 2017 12:34:01 +0100 Subject: [PATCH 3/3] drop packages which are only send on end --- extensions/typescript/src/utils/typingsStatus.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/extensions/typescript/src/utils/typingsStatus.ts b/extensions/typescript/src/utils/typingsStatus.ts index 6d1f23439da..de5cd9d291e 100644 --- a/extensions/typescript/src/utils/typingsStatus.ts +++ b/extensions/typescript/src/utils/typingsStatus.ts @@ -67,7 +67,7 @@ export class AtaProgressReporter { constructor(client: ITypescriptServiceClient) { this._disposable = vscode.Disposable.from( - client.onDidBeginInstallTypings(e => this._onBegin(e.eventId, e.packages)), + client.onDidBeginInstallTypings(e => this._onBegin(e.eventId)), client.onDidEndInstallTypings(e => this._onEndOrTimeout(e.eventId)) ); } @@ -77,8 +77,7 @@ export class AtaProgressReporter { this._promises.forEach(value => value()); } - private _onBegin(eventId: number, packages: ReadonlyArray): void { - + private _onBegin(eventId: number): void { const handle = setTimeout(() => this._onEndOrTimeout(eventId), typingsInstallTimeout); const promise = new Promise(resolve => { this._promises.set(eventId, () => {