start with contributable progress locations

This commit is contained in:
Johannes Rieken 2021-11-25 12:30:37 +01:00
parent 5e5bb86a25
commit 0ee22a1bd6
No known key found for this signature in database
GPG key ID: 96634B5AF12F8798
3 changed files with 31 additions and 4 deletions

View file

@ -6,7 +6,7 @@
import { IAction } from 'vs/base/common/actions';
import { DeferredPromise } from 'vs/base/common/async';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IProgressService = createDecorator<IProgressService>('progressService');
@ -23,8 +23,16 @@ export interface IProgressService {
task: (progress: IProgress<IProgressStep>) => Promise<R>,
onDidCancel?: (choice?: number) => void
): Promise<R>;
registerProgressLocation(location: string, handle: ICustomProgressLocation): IDisposable;
}
export type ICustomProgressLocation = <R>(
options: IProgressOptions | IProgressDialogOptions | IProgressNotificationOptions | IProgressWindowOptions | IProgressCompositeOptions,
task: (progress: IProgress<IProgressStep>) => Promise<R>,
onDidCancel?: (choice?: number) => void
) => Promise<R>;
export interface IProgressIndicator {
/**

View file

@ -7,7 +7,7 @@ import 'vs/css!./media/progressService';
import { localize } from 'vs/nls';
import { IDisposable, dispose, DisposableStore, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IProgressService, IProgressOptions, IProgressStep, ProgressLocation, IProgress, Progress, IProgressCompositeOptions, IProgressNotificationOptions, IProgressRunner, IProgressIndicator, IProgressWindowOptions, IProgressDialogOptions } from 'vs/platform/progress/common/progress';
import { IProgressService, IProgressOptions, IProgressStep, ProgressLocation, IProgress, Progress, IProgressCompositeOptions, IProgressNotificationOptions, IProgressRunner, IProgressIndicator, IProgressWindowOptions, IProgressDialogOptions, ICustomProgressLocation } from 'vs/platform/progress/common/progress';
import { StatusbarAlignment, IStatusbarService, IStatusbarEntryAccessor, IStatusbarEntry } from 'vs/workbench/services/statusbar/browser/statusbar';
import { DeferredPromise, RunOnceScheduler, timeout } from 'vs/base/common/async';
import { ProgressBadge, IActivityService } from 'vs/workbench/services/activity/common/activity';
@ -26,10 +26,12 @@ import { parseLinkedText } from 'vs/base/common/linkedText';
import { IViewsService, IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
export class ProgressService extends Disposable implements IProgressService {
export class ProgressService implements IProgressService {
declare readonly _serviceBrand: undefined;
private readonly customProgessLocations = new Map<string, ICustomProgressLocation>();
constructor(
@IActivityService private readonly activityService: IActivityService,
@IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService,
@ -41,7 +43,15 @@ export class ProgressService extends Disposable implements IProgressService {
@IThemeService private readonly themeService: IThemeService,
@IKeybindingService private readonly keybindingService: IKeybindingService
) {
super();
}
registerProgressLocation(location: string, handle: ICustomProgressLocation): IDisposable {
if (this.customProgessLocations.has(location)) {
throw new Error(`${location} already used`);
}
this.customProgessLocations.set(location, handle);
return toDisposable(() => this.customProgessLocations.delete(location));
}
async withProgress<R = unknown>(options: IProgressOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: (choice?: number) => void): Promise<R> {
@ -60,6 +70,11 @@ export class ProgressService extends Disposable implements IProgressService {
return this.withViewProgress(location, task, { ...options, location });
}
const customLocation = this.customProgessLocations.get(location);
if (customLocation) {
return customLocation<R>(options, task, onDidCancel);
}
throw new Error(`Bad progress location: ${location}`);
}

View file

@ -441,6 +441,10 @@ export class TestProgressService implements IProgressService {
declare readonly _serviceBrand: undefined;
registerProgressLocation(): IDisposable {
return Disposable.None;
}
withProgress(
options: IProgressOptions | IProgressDialogOptions | IProgressWindowOptions | IProgressNotificationOptions | IProgressCompositeOptions,
task: (progress: IProgress<IProgressStep>) => Promise<any>,