mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
finalize progress API, #18066
This commit is contained in:
@@ -344,11 +344,11 @@ export function createApiFactory(
|
||||
setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
|
||||
return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
|
||||
},
|
||||
withWindowProgress: proposedApiFunction(extension, <R>(title: string, task: (progress: vscode.Progress<string>, token: vscode.CancellationToken) => Thenable<R>): Thenable<R> => {
|
||||
return extHostProgress.withWindowProgress(extension, title, task);
|
||||
}),
|
||||
withScmProgress<R>(task: (progress: vscode.Progress<number>) => Thenable<R>) {
|
||||
return extHostProgress.withScmProgress(extension, task);
|
||||
return extHostProgress.withProgress(extension, { location: extHostTypes.ProgressLocation.Scm }, task);
|
||||
},
|
||||
withProgress<R>(options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string; percentage?: number }>) => Thenable<R>) {
|
||||
return extHostProgress.withProgress(extension, options, task);
|
||||
},
|
||||
createOutputChannel(name: string): vscode.OutputChannel {
|
||||
return extHostOutputService.createOutputChannel(name);
|
||||
@@ -526,6 +526,7 @@ export function createApiFactory(
|
||||
Uri: URI,
|
||||
ViewColumn: extHostTypes.ViewColumn,
|
||||
WorkspaceEdit: extHostTypes.WorkspaceEdit,
|
||||
ProgressLocation: extHostTypes.ProgressLocation,
|
||||
// functions
|
||||
FileLocationKind: extHostTypes.FileLocationKind,
|
||||
ApplyToKind: extHostTypes.ApplyToKind,
|
||||
|
||||
@@ -23,6 +23,7 @@ import { StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/platform/
|
||||
import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { IProgressOptions, IProgressStep } from 'vs/platform/progress/common/progress';
|
||||
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
@@ -202,9 +203,8 @@ export abstract class MainThreadOutputServiceShape {
|
||||
|
||||
export abstract class MainThreadProgressShape {
|
||||
|
||||
$startWindow(handle: number, title: string): void { throw ni(); };
|
||||
$startScm(handle: number): void { throw ni(); };
|
||||
$progressReport(handle: number, message: string): void { throw ni(); }
|
||||
$startProgress(handle: number, options: IProgressOptions): void { throw ni(); };
|
||||
$progressReport(handle: number, message: IProgressStep): void { throw ni(); }
|
||||
$progressEnd(handle: number): void { throw ni(); }
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Progress, CancellationToken } from 'vscode';
|
||||
import { Progress, ProgressOptions, CancellationToken } from 'vscode';
|
||||
import { MainThreadProgressShape } from './extHost.protocol';
|
||||
import { ProgressLocation } from './extHostTypeConverters';
|
||||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { IProgressStep } from "vs/platform/progress/common/progress";
|
||||
|
||||
export class ExtHostProgress {
|
||||
|
||||
@@ -17,23 +19,18 @@ export class ExtHostProgress {
|
||||
this._proxy = proxy;
|
||||
}
|
||||
|
||||
withWindowProgress<R>(extension: IExtensionDescription, title: string, task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
withProgress<R>(extension: IExtensionDescription, options: ProgressOptions, task: (progress: Progress<IProgressStep>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
const handle = this._handles++;
|
||||
this._proxy.$startWindow(handle, title);
|
||||
const { title, location } = options;
|
||||
this._proxy.$startProgress(handle, { location: ProgressLocation.from(location), title, tooltip: extension.name });
|
||||
return this._withProgress(handle, task);
|
||||
}
|
||||
|
||||
withScmProgress<R>(extension: IExtensionDescription, task: (progress: Progress<number>) => Thenable<R>): Thenable<R> {
|
||||
const handle = this._handles++;
|
||||
this._proxy.$startScm(handle);
|
||||
return this._withProgress(handle, task);
|
||||
}
|
||||
|
||||
private _withProgress<R>(handle: number, task: (progress: Progress<any>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
private _withProgress<R>(handle: number, task: (progress: Progress<IProgressStep>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
|
||||
const progress = {
|
||||
report: (message: string) => {
|
||||
this._proxy.$progressReport(handle, message);
|
||||
report: (p: IProgressStep) => {
|
||||
this._proxy.$progressReport(handle, p);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,3 +47,4 @@ export class ExtHostProgress {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import { Position as EditorPosition } from 'vs/platform/editor/common/editor';
|
||||
import { IDecorationOptions, EndOfLineSequence } from 'vs/editor/common/editorCommon';
|
||||
import * as vscode from 'vscode';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { ProgressLocation as MainProgressLocation } from 'vs/platform/progress/common/progress';
|
||||
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { IPosition } from "vs/editor/common/core/position";
|
||||
import { IRange } from "vs/editor/common/core/range";
|
||||
@@ -405,3 +406,12 @@ export namespace EndOfLine {
|
||||
}
|
||||
}
|
||||
|
||||
export namespace ProgressLocation {
|
||||
export function from(loc: vscode.ProgressLocation): MainProgressLocation {
|
||||
switch (loc) {
|
||||
case types.ProgressLocation.Scm: return MainProgressLocation.Scm;
|
||||
case types.ProgressLocation.Window: return MainProgressLocation.Window;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1266,3 +1266,8 @@ export class ShellTask extends BaseTask {
|
||||
this._options = value;
|
||||
}
|
||||
}
|
||||
|
||||
export enum ProgressLocation {
|
||||
Scm = 1,
|
||||
Window = 10,
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { IProgressService2, IProgress } from 'vs/platform/progress/common/progress';
|
||||
import { IProgressService2, IProgress, IProgressOptions, IProgressStep } from 'vs/platform/progress/common/progress';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { MainThreadProgressShape } from './extHost.protocol';
|
||||
|
||||
export class MainThreadProgress extends MainThreadProgressShape {
|
||||
|
||||
private _progressService: IProgressService2;
|
||||
private progress = new Map<number, { resolve: Function, progress: IProgress<any> }>();
|
||||
private progress = new Map<number, { resolve: Function, progress: IProgress<IProgressStep> }>();
|
||||
|
||||
constructor(
|
||||
@IProgressService2 progressService: IProgressService2
|
||||
@@ -20,26 +20,12 @@ export class MainThreadProgress extends MainThreadProgressShape {
|
||||
this._progressService = progressService;
|
||||
}
|
||||
|
||||
|
||||
$startWindow(handle: number, title: string): void {
|
||||
$startProgress(handle: number, options: IProgressOptions): void {
|
||||
const task = this._createTask(handle);
|
||||
this._progressService.withWindowProgress(title, task);
|
||||
this._progressService.withProgress(options, task);
|
||||
}
|
||||
|
||||
$startScm(handle: number): void {
|
||||
const task = this._createTask(handle);
|
||||
this._progressService.withViewletProgress('workbench.view.scm', task);
|
||||
}
|
||||
|
||||
private _createTask(handle: number) {
|
||||
return (progress: IProgress<any>) => {
|
||||
return new TPromise<any>(resolve => {
|
||||
this.progress.set(handle, { resolve, progress });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
$progressReport(handle: number, message: any): void {
|
||||
$progressReport(handle: number, message: IProgressStep): void {
|
||||
this.progress.get(handle).progress.report(message);
|
||||
}
|
||||
|
||||
@@ -47,4 +33,12 @@ export class MainThreadProgress extends MainThreadProgressShape {
|
||||
this.progress.get(handle).resolve();
|
||||
this.progress.delete(handle);
|
||||
}
|
||||
|
||||
private _createTask(handle: number) {
|
||||
return (progress: IProgress<IProgressStep>) => {
|
||||
return new TPromise<any>(resolve => {
|
||||
this.progress.set(handle, { resolve, progress });
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user