提交 0b4d2dcd 编写于 作者: B Benjamin Pasero

debt - reduce scope of local progress service

上级 abac09b4
......@@ -19,7 +19,7 @@ import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/commo
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { CodeActionModel, SUPPORTED_CODE_ACTIONS, CodeActionsState } from './codeActionModel';
import { CodeActionAutoApply, CodeActionFilter, CodeActionKind, CodeActionTrigger } from './codeActionTrigger';
import { CodeActionWidget } from './codeActionWidget';
......@@ -52,7 +52,7 @@ export class QuickFixController extends Disposable implements IEditorContributio
editor: ICodeEditor,
@IMarkerService markerService: IMarkerService,
@IContextKeyService contextKeyService: IContextKeyService,
@ILocalProgressService progressService: ILocalProgressService,
@IEditorProgressService progressService: IEditorProgressService,
@IContextMenuService contextMenuService: IContextMenuService,
@ICommandService private readonly _commandService: ICommandService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
......
......@@ -14,7 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import { CodeActionProviderRegistry } from 'vs/editor/common/modes';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { getCodeActions, CodeActionSet } from './codeAction';
import { CodeActionTrigger } from './codeActionTrigger';
......@@ -167,7 +167,7 @@ export class CodeActionModel extends Disposable {
private readonly _editor: ICodeEditor,
private readonly _markerService: IMarkerService,
contextKeyService: IContextKeyService,
private readonly _progressService?: ILocalProgressService
private readonly _progressService?: IEditorProgressService
) {
super();
this._supportedCodeActions = SUPPORTED_CODE_ACTIONS.bindTo(contextKeyService);
......
......@@ -25,7 +25,7 @@ import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition, getDeclarationsAtPosition } from './goToDefinition';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { EditorStateCancellationTokenSource, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState';
......@@ -58,7 +58,7 @@ export class DefinitionAction extends EditorAction {
}
const notificationService = accessor.get(INotificationService);
const editorService = accessor.get(ICodeEditorService);
const progressService = accessor.get(ILocalProgressService);
const progressService = accessor.get(IEditorProgressService);
const symbolNavService = accessor.get(ISymbolNavigationService);
const model = editor.getModel();
......
......@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import { illegalArgument, onUnexpectedError } from 'vs/base/common/errors';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction, EditorCommand, registerEditorCommand, registerDefaultLanguageCommand } from 'vs/editor/browser/editorExtensions';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
......@@ -114,7 +114,7 @@ class RenameController extends Disposable implements IEditorContribution {
private readonly editor: ICodeEditor,
@INotificationService private readonly _notificationService: INotificationService,
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
@ILocalProgressService private readonly _progressService: ILocalProgressService,
@IEditorProgressService private readonly _progressService: IEditorProgressService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IThemeService private readonly _themeService: IThemeService,
) {
......
......@@ -38,7 +38,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { ILabelService, ResourceLabelFormatter } from 'vs/platform/label/common/label';
import { INotification, INotificationHandle, INotificationService, IPromptChoice, IPromptOptions, NoOpNotification, IStatusMessageOptions } from 'vs/platform/notification/common/notification';
import { IProgressRunner, ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IProgressRunner, IEditorProgressService } from 'vs/platform/progress/common/progress';
import { ITelemetryInfo, ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspace, IWorkspaceContextService, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, WorkbenchState, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
......@@ -137,7 +137,7 @@ export class SimpleEditorModelResolverService implements ITextModelService {
}
}
export class SimpleLocalProgressService implements ILocalProgressService {
export class SimpleEditorProgressService implements IEditorProgressService {
_serviceBrand: any;
private static NULL_PROGRESS_RUNNER: IProgressRunner = {
......@@ -149,7 +149,7 @@ export class SimpleLocalProgressService implements ILocalProgressService {
show(infinite: true, delay?: number): IProgressRunner;
show(total: number, delay?: number): IProgressRunner;
show(): IProgressRunner {
return SimpleLocalProgressService.NULL_PROGRESS_RUNNER;
return SimpleEditorProgressService.NULL_PROGRESS_RUNNER;
}
showWhile(promise: Promise<any>, delay?: number): Promise<void> {
......
......@@ -13,7 +13,7 @@ import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
import { SimpleBulkEditService, SimpleConfigurationService, SimpleDialogService, SimpleNotificationService, SimpleLocalProgressService, SimpleResourceConfigurationService, SimpleResourcePropertiesService, SimpleUriLabelService, SimpleWorkspaceContextService, StandaloneCommandService, StandaloneKeybindingService, StandaloneTelemetryService, SimpleLayoutService } from 'vs/editor/standalone/browser/simpleServices';
import { SimpleBulkEditService, SimpleConfigurationService, SimpleDialogService, SimpleNotificationService, SimpleEditorProgressService, SimpleResourceConfigurationService, SimpleResourcePropertiesService, SimpleUriLabelService, SimpleWorkspaceContextService, StandaloneCommandService, StandaloneKeybindingService, StandaloneTelemetryService, SimpleLayoutService } from 'vs/editor/standalone/browser/simpleServices';
import { StandaloneCodeEditorServiceImpl } from 'vs/editor/standalone/browser/standaloneCodeServiceImpl';
import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standaloneThemeServiceImpl';
import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
......@@ -36,7 +36,7 @@ import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { MarkerService } from 'vs/platform/markers/common/markerService';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
......@@ -154,7 +154,7 @@ export module StaticServices {
export const codeEditorService = define(ICodeEditorService, (o) => new StandaloneCodeEditorServiceImpl(standaloneThemeService.get(o)));
export const localProgressService = define(ILocalProgressService, () => new SimpleLocalProgressService());
export const editorProgressService = define(IEditorProgressService, () => new SimpleEditorProgressService());
export const storageService = define(IStorageService, () => new InMemoryStorageService());
......
......@@ -20,15 +20,7 @@ export interface IProgressService {
withProgress<R = any>(options: IProgressOptions | IProgressNotificationOptions | IProgressCompositeOptions, task: (progress: IProgress<IProgressStep>) => Promise<R>, onDidCancel?: () => void): Promise<R>;
}
export const ILocalProgressService = createDecorator<ILocalProgressService>('localProgressService');
/**
* A progress service that will report progress local to the UI piece triggered from. E.g.
* if used from an action of a viewlet, the progress will be reported in that viewlet.
*/
export interface ILocalProgressService {
_serviceBrand: ServiceIdentifier<ILocalProgressService>;
export interface IProgressIndicator {
/**
* Show progress customized with the provided flags.
......@@ -132,7 +124,7 @@ export class LongRunningOperation extends Disposable {
private currentProgressTimeout: any;
constructor(
private localProgressService: ILocalProgressService
private progressIndicator: IProgressIndicator
) {
super();
}
......@@ -147,7 +139,7 @@ export class LongRunningOperation extends Disposable {
const newOperationToken = new CancellationTokenSource();
this.currentProgressTimeout = setTimeout(() => {
if (newOperationId === this.currentOperationId) {
this.currentProgressRunner = this.localProgressService.show(true);
this.currentProgressRunner = this.progressIndicator.show(true);
}
}, progressDelay);
......@@ -173,3 +165,13 @@ export class LongRunningOperation extends Disposable {
}
}
}
export const IEditorProgressService = createDecorator<IEditorProgressService>('editorProgressService');
/**
* A progress service that will report progress local to the editor triggered from.
*/
export interface IEditorProgressService extends IProgressIndicator {
_serviceBrand: ServiceIdentifier<IEditorProgressService>;
}
......@@ -18,13 +18,12 @@ import { IAction } from 'vs/base/common/actions';
import { Part, IPartOptions } from 'vs/workbench/browser/part';
import { Composite, CompositeRegistry } from 'vs/workbench/browser/composite';
import { IComposite } from 'vs/workbench/common/composite';
import { ScopedProgressService } from 'vs/workbench/services/progress/browser/localProgressService';
import { CompositeProgressIndicator } from 'vs/workbench/services/progress/browser/progressIndicator';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IProgressIndicator } from 'vs/platform/progress/common/progress';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IThemeService } from 'vs/platform/theme/common/themeService';
......@@ -50,7 +49,7 @@ export interface ICompositeTitleLabel {
interface CompositeItem {
composite: Composite;
disposable: IDisposable;
localProgressService: ILocalProgressService;
progress: IProgressIndicator;
}
export abstract class CompositePart<T extends Composite> extends Part {
......@@ -169,17 +168,18 @@ export abstract class CompositePart<T extends Composite> extends Part {
// Instantiate composite from registry otherwise
const compositeDescriptor = this.registry.getComposite(id);
if (compositeDescriptor) {
const localProgressService = this.instantiationService.createInstance(ScopedProgressService, this.progressBar, compositeDescriptor.id, isActive);
const compositeInstantiationService = this.instantiationService.createChild(new ServiceCollection([ILocalProgressService, localProgressService]));
const composite = compositeDescriptor.instantiate(compositeInstantiationService);
const disposables = new DisposableStore();
const composite = compositeDescriptor.instantiate(this.instantiationService);
const disposable = new DisposableStore();
// Remember as Instantiated
this.instantiatedCompositeItems.set(id, { composite, disposable: disposables, localProgressService });
this.instantiatedCompositeItems.set(id, {
composite,
disposable,
progress: this._register(this.instantiationService.createInstance(CompositeProgressIndicator, this.progressBar, compositeDescriptor.id, isActive))
});
// Register to title area update events from the composite
disposables.add(composite.onTitleAreaUpdate(() => this.onTitleAreaUpdate(composite.getId()), this));
disposable.add(composite.onTitleAreaUpdate(() => this.onTitleAreaUpdate(composite.getId()), this));
return composite;
}
......@@ -451,10 +451,10 @@ export abstract class CompositePart<T extends Composite> extends Part {
return contentContainer;
}
getProgressIndicator(id: string): ILocalProgressService | null {
getProgressIndicator(id: string): IProgressIndicator | null {
const compositeItem = this.instantiatedCompositeItems.get(id);
return compositeItem ? compositeItem.localProgressService : null;
return compositeItem ? compositeItem.progress : null;
}
protected getActions(): ReadonlyArray<IAction> {
......
......@@ -11,7 +11,7 @@ import { IEditorRegistry, Extensions as EditorExtensions, IEditorDescriptor } fr
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILocalProgressService, LongRunningOperation } from 'vs/platform/progress/common/progress';
import { IEditorProgressService, LongRunningOperation } from 'vs/platform/progress/common/progress';
import { IEditorGroupView, DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor';
import { Event, Emitter } from 'vs/base/common/event';
import { IVisibleEditor } from 'vs/workbench/services/editor/common/editorService';
......@@ -47,11 +47,11 @@ export class EditorControl extends Disposable {
private groupView: IEditorGroupView,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@ILocalProgressService localProgressService: ILocalProgressService
@IEditorProgressService editorProgressService: IEditorProgressService
) {
super();
this.editorOperation = this._register(new LongRunningOperation(localProgressService));
this.editorOperation = this._register(new LongRunningOperation(editorProgressService));
}
get activeControl(): IVisibleEditor | null {
......
......@@ -20,8 +20,8 @@ import { Themable, EDITOR_GROUP_HEADER_TABS_BORDER, EDITOR_GROUP_HEADER_TABS_BAC
import { IMoveEditorOptions, ICopyEditorOptions, ICloseEditorsFilter, IGroupChangeEvent, GroupChangeKind, EditorsOrder, GroupsOrder, ICloseEditorOptions } from 'vs/workbench/services/editor/common/editorGroupsService';
import { TabsTitleControl } from 'vs/workbench/browser/parts/editor/tabsTitleControl';
import { EditorControl } from 'vs/workbench/browser/parts/editor/editorControl';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { LocalProgressService } from 'vs/workbench/services/progress/browser/localProgressService';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { EditorProgressService } from 'vs/workbench/services/progress/browser/editorProgressService';
import { localize } from 'vs/nls';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { dispose, MutableDisposable } from 'vs/base/common/lifecycle';
......@@ -178,7 +178,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
const scopedContextKeyService = this._register(this.contextKeyService.createScoped(this.element));
this.scopedInstantiationService = this.instantiationService.createChild(new ServiceCollection(
[IContextKeyService, scopedContextKeyService],
[ILocalProgressService, new LocalProgressService(this.progressBar)]
[IEditorProgressService, new EditorProgressService(this.progressBar)]
));
// Context keys
......
......@@ -31,7 +31,7 @@ import { ConfigurationTarget } from 'vs/platform/configuration/common/configurat
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { Registry } from 'vs/platform/registry/common/platform';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
......@@ -94,7 +94,7 @@ export class PreferencesEditor extends BaseEditor {
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IThemeService themeService: IThemeService,
@ILocalProgressService private readonly progressService: ILocalProgressService,
@IEditorProgressService private readonly editorProgressService: IEditorProgressService,
@IStorageService storageService: IStorageService
) {
super(PreferencesEditor.ID, telemetryService, themeService, storageService);
......@@ -237,7 +237,7 @@ export class PreferencesEditor extends BaseEditor {
if (query) {
return Promise.all([
this.localSearchDelayer.trigger(() => this.preferencesRenderers.localFilterPreferences(query).then(() => { })),
this.remoteSearchThrottle.trigger(() => Promise.resolve(this.progressService.showWhile(this.preferencesRenderers.remoteSearchPreferences(query), 500)))
this.remoteSearchThrottle.trigger(() => Promise.resolve(this.editorProgressService.showWhile(this.preferencesRenderers.remoteSearchPreferences(query), 500)))
]).then(() => { });
} else {
// When clearing the input, update immediately to clear it
......
......@@ -8,7 +8,7 @@ import { IPanel } from 'vs/workbench/common/panel';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { IBadge } from 'vs/workbench/services/activity/common/activity';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IProgressIndicator } from 'vs/platform/progress/common/progress';
export const IPanelService = createDecorator<IPanelService>('panelService');
......@@ -53,7 +53,7 @@ export interface IPanelService {
/**
* Returns the progress indicator for the panel bar.
*/
getProgressIndicator(id: string): ILocalProgressService | null;
getProgressIndicator(id: string): IProgressIndicator | null;
/**
* Show an activity in a panel.
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ProgressBarIndicator } from 'vs/workbench/services/progress/browser/progressIndicator';
export class EditorProgressService extends ProgressBarIndicator {
_serviceBrand: ServiceIdentifier<IEditorProgressService>;
}
......@@ -4,14 +4,58 @@
*--------------------------------------------------------------------------------------------*/
import { Disposable } from 'vs/base/common/lifecycle';
import * as types from 'vs/base/common/types';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ILocalProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { IProgressRunner, IProgressIndicator } from 'vs/platform/progress/common/progress';
namespace ProgressState {
export class ProgressBarIndicator implements IProgressIndicator {
constructor(private progressbar: ProgressBar) { }
show(infinite: true, delay?: number): IProgressRunner;
show(total: number, delay?: number): IProgressRunner;
show(infiniteOrTotal: true | number, delay?: number): IProgressRunner {
if (typeof infiniteOrTotal === 'boolean') {
this.progressbar.infinite().show(delay);
} else {
this.progressbar.total(infiniteOrTotal).show(delay);
}
return {
total: (total: number) => {
this.progressbar.total(total);
},
worked: (worked: number) => {
if (this.progressbar.hasTotal()) {
this.progressbar.worked(worked);
} else {
this.progressbar.infinite().show();
}
},
done: () => {
this.progressbar.stop().hide();
}
};
}
async showWhile(promise: Promise<any>, delay?: number): Promise<void> {
try {
this.progressbar.infinite().show(delay);
await promise;
} catch (error) {
// ignore
} finally {
this.progressbar.stop().hide();
}
}
}
namespace ProgressIndicatorState {
export const enum Type {
None,
......@@ -52,7 +96,7 @@ namespace ProgressState {
| Work;
}
export abstract class ScopedService extends Disposable {
export abstract class CompositeScope extends Disposable {
constructor(
private viewletService: IViewletService,
......@@ -89,13 +133,10 @@ export abstract class ScopedService extends Disposable {
abstract onScopeDeactivated(): void;
}
export class ScopedProgressService extends ScopedService implements ILocalProgressService {
_serviceBrand: ServiceIdentifier<ILocalProgressService>;
export class CompositeProgressIndicator extends CompositeScope implements IProgressIndicator {
private isActive: boolean;
private progressbar: ProgressBar;
private progressState: ProgressState.State = ProgressState.None;
private progressState: ProgressIndicatorState.State = ProgressIndicatorState.None;
constructor(
progressbar: ProgressBar,
......@@ -107,7 +148,7 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
super(viewletService, panelService, scopeId);
this.progressbar = progressbar;
this.isActive = isActive || types.isUndefinedOrNull(scopeId); // If service is unscoped, enable by default
this.isActive = isActive || isUndefinedOrNull(scopeId); // If service is unscoped, enable by default
}
onScopeDeactivated(): void {
......@@ -118,12 +159,12 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
this.isActive = true;
// Return early if progress state indicates that progress is done
if (this.progressState.type === ProgressState.Done.type) {
if (this.progressState.type === ProgressIndicatorState.Done.type) {
return;
}
// Replay Infinite Progress from Promise
if (this.progressState.type === ProgressState.Type.While) {
if (this.progressState.type === ProgressIndicatorState.Type.While) {
let delay: number | undefined;
if (this.progressState.whileDelay > 0) {
const remainingDelay = this.progressState.whileDelay - (Date.now() - this.progressState.whileStart);
......@@ -136,12 +177,12 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
}
// Replay Infinite Progress
else if (this.progressState.type === ProgressState.Type.Infinite) {
else if (this.progressState.type === ProgressIndicatorState.Type.Infinite) {
this.progressbar.infinite().show();
}
// Replay Finite Progress (Total & Worked)
else if (this.progressState.type === ProgressState.Type.Work) {
else if (this.progressState.type === ProgressIndicatorState.Type.Work) {
if (this.progressState.total) {
this.progressbar.total(this.progressState.total).show();
}
......@@ -158,30 +199,30 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
// Sort out Arguments
if (typeof infiniteOrTotal === 'boolean') {
this.progressState = ProgressState.Infinite;
this.progressState = ProgressIndicatorState.Infinite;
} else {
this.progressState = new ProgressState.Work(infiniteOrTotal, undefined);
this.progressState = new ProgressIndicatorState.Work(infiniteOrTotal, undefined);
}
// Active: Show Progress
if (this.isActive) {
// Infinite: Start Progressbar and Show after Delay
if (this.progressState.type === ProgressState.Type.Infinite) {
if (this.progressState.type === ProgressIndicatorState.Type.Infinite) {
this.progressbar.infinite().show(delay);
}
// Finite: Start Progressbar and Show after Delay
else if (this.progressState.type === ProgressState.Type.Work && typeof this.progressState.total === 'number') {
else if (this.progressState.type === ProgressIndicatorState.Type.Work && typeof this.progressState.total === 'number') {
this.progressbar.total(this.progressState.total).show(delay);
}
}
return {
total: (total: number) => {
this.progressState = new ProgressState.Work(
this.progressState = new ProgressIndicatorState.Work(
total,
this.progressState.type === ProgressState.Type.Work ? this.progressState.worked : undefined);
this.progressState.type === ProgressIndicatorState.Type.Work ? this.progressState.worked : undefined);
if (this.isActive) {
this.progressbar.total(total);
......@@ -192,9 +233,9 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
// Verify first that we are either not active or the progressbar has a total set
if (!this.isActive || this.progressbar.hasTotal()) {
this.progressState = new ProgressState.Work(
this.progressState.type === ProgressState.Type.Work ? this.progressState.total : undefined,
this.progressState.type === ProgressState.Type.Work && typeof this.progressState.worked === 'number' ? this.progressState.worked + worked : worked);
this.progressState = new ProgressIndicatorState.Work(
this.progressState.type === ProgressIndicatorState.Type.Work ? this.progressState.total : undefined,
this.progressState.type === ProgressIndicatorState.Type.Work && typeof this.progressState.worked === 'number' ? this.progressState.worked + worked : worked);
if (this.isActive) {
this.progressbar.worked(worked);
......@@ -203,13 +244,13 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
// Otherwise the progress bar does not support worked(), we fallback to infinite() progress
else {
this.progressState = ProgressState.Infinite;
this.progressState = ProgressIndicatorState.Infinite;
this.progressbar.infinite().show();
}
},
done: () => {
this.progressState = ProgressState.Done;
this.progressState = ProgressIndicatorState.Done;
if (this.isActive) {
this.progressbar.stop().hide();
......@@ -221,12 +262,12 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
async showWhile(promise: Promise<any>, delay?: number): Promise<void> {
// Join with existing running promise to ensure progress is accurate
if (this.progressState.type === ProgressState.Type.While) {
if (this.progressState.type === ProgressIndicatorState.Type.While) {
promise = Promise.all([promise, this.progressState.whilePromise]);
}
// Keep Promise in State
this.progressState = new ProgressState.While(promise, delay || 0, Date.now());
this.progressState = new ProgressIndicatorState.While(promise, delay || 0, Date.now());
try {
this.doShowWhile(delay);
......@@ -237,10 +278,10 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
} finally {
// If this is not the last promise in the list of joined promises, skip this
if (this.progressState.type !== ProgressState.Type.While || this.progressState.whilePromise === promise) {
if (this.progressState.type !== ProgressIndicatorState.Type.While || this.progressState.whilePromise === promise) {
// The while promise is either null or equal the promise we last hooked on
this.progressState = ProgressState.None;
this.progressState = ProgressIndicatorState.None;
if (this.isActive) {
this.progressbar.stop().hide();
......@@ -257,50 +298,3 @@ export class ScopedProgressService extends ScopedService implements ILocalProgre
}
}
}
export class LocalProgressService implements ILocalProgressService {
_serviceBrand: ServiceIdentifier<ILocalProgressService>;
constructor(private progressbar: ProgressBar) { }
show(infinite: true, delay?: number): IProgressRunner;
show(total: number, delay?: number): IProgressRunner;
show(infiniteOrTotal: true | number, delay?: number): IProgressRunner {
if (typeof infiniteOrTotal === 'boolean') {
this.progressbar.infinite().show(delay);
} else {
this.progressbar.total(infiniteOrTotal).show(delay);
}
return {
total: (total: number) => {
this.progressbar.total(total);
},
worked: (worked: number) => {
if (this.progressbar.hasTotal()) {
this.progressbar.worked(worked);
} else {
this.progressbar.infinite().show();
}
},
done: () => {
this.progressbar.stop().hide();
}
};
}
async showWhile(promise: Promise<any>, delay?: number): Promise<void> {
try {
this.progressbar.infinite().show(delay);
await promise;
} catch (error) {
// ignore
} finally {
this.progressbar.stop().hide();
}
}
}
......@@ -7,7 +7,7 @@ import 'vs/css!./media/progressService';
import { localize } from 'vs/nls';
import { IDisposable, dispose, DisposableStore, MutableDisposable, Disposable } from 'vs/base/common/lifecycle';
import { IProgressService, IProgressOptions, IProgressStep, ProgressLocation, IProgress, Progress, IProgressCompositeOptions, IProgressNotificationOptions, IProgressRunner, ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IProgressService, IProgressOptions, IProgressStep, ProgressLocation, IProgress, Progress, IProgressCompositeOptions, IProgressNotificationOptions, IProgressRunner, IProgressIndicator } from 'vs/platform/progress/common/progress';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { StatusbarAlignment, IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { timeout } from 'vs/base/common/async';
......@@ -286,7 +286,7 @@ export class ProgressService extends Disposable implements IProgressService {
return this.withCompositeProgress(this.panelService.getProgressIndicator(panelid), task, options);
}
private withCompositeProgress<P extends Promise<R>, R = unknown>(compositeProgressService: ILocalProgressService | null, task: (progress: IProgress<IProgressStep>) => P, options: IProgressCompositeOptions): P {
private withCompositeProgress<P extends Promise<R>, R = unknown>(progressIndicator: IProgressIndicator | null, task: (progress: IProgress<IProgressStep>) => P, options: IProgressCompositeOptions): P {
let progressRunner: IProgressRunner | undefined = undefined;
const promise = task({
......@@ -305,12 +305,12 @@ export class ProgressService extends Disposable implements IProgressService {
}
});
if (compositeProgressService) {
if (progressIndicator) {
if (typeof options.total === 'number') {
progressRunner = compositeProgressService.show(options.total, options.delay);
progressRunner = progressIndicator.show(options.total, options.delay);
promise.catch(() => undefined /* ignore */).finally(() => progressRunner ? progressRunner.done() : undefined);
} else {
compositeProgressService.showWhile(promise, options.delay);
progressIndicator.showWhile(promise, options.delay);
}
}
......
......@@ -6,7 +6,7 @@
import * as assert from 'assert';
import { IAction, IActionViewItem } from 'vs/base/common/actions';
import { IEditorControl } from 'vs/workbench/common/editor';
import { ScopedProgressService, ScopedService } from 'vs/workbench/services/progress/browser/localProgressService';
import { CompositeScope, CompositeProgressIndicator } from 'vs/workbench/services/progress/browser/progressIndicator';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IViewlet } from 'vs/workbench/common/viewlet';
......@@ -16,106 +16,55 @@ class TestViewlet implements IViewlet {
constructor(private id: string) { }
getId(): string {
return this.id;
}
/**
* Returns the name of this composite to show in the title area.
*/
getTitle(): string {
return this.id;
}
/**
* Returns the primary actions of the composite.
*/
getActions(): IAction[] {
return [];
}
/**
* Returns the secondary actions of the composite.
*/
getSecondaryActions(): IAction[] {
return [];
}
/**
* Returns an array of actions to show in the context menu of the composite
*/
public getContextMenuActions(): IAction[] {
return [];
}
/**
* Returns the action item for a specific action.
*/
getActionViewItem(action: IAction): IActionViewItem {
return null!;
}
/**
* Returns the underlying control of this composite.
*/
getControl(): IEditorControl {
return null!;
}
/**
* Asks the underlying control to focus.
*/
focus(): void {
}
getOptimalWidth(): number {
return 10;
}
getId(): string { return this.id; }
getTitle(): string { return this.id; }
getActions(): IAction[] { return []; }
getSecondaryActions(): IAction[] { return []; }
getContextMenuActions(): IAction[] { return []; }
getActionViewItem(action: IAction): IActionViewItem { return null!; }
getControl(): IEditorControl { return null!; }
focus(): void { }
getOptimalWidth(): number { return 10; }
}
class TestScopedService extends ScopedService {
public isActive: boolean;
class TestCompositeScope extends CompositeScope {
isActive: boolean;
constructor(viewletService: IViewletService, panelService: IPanelService, scopeId: string) {
super(viewletService, panelService, scopeId);
}
public onScopeActivated() {
this.isActive = true;
}
public onScopeDeactivated() {
this.isActive = false;
}
onScopeActivated() { this.isActive = true; }
onScopeDeactivated() { this.isActive = false; }
}
class TestProgressBar {
public fTotal: number;
public fWorked: number;
public fInfinite: boolean;
public fDone: boolean;
fTotal: number;
fWorked: number;
fInfinite: boolean;
fDone: boolean;
constructor() {
}
constructor() { }
public infinite() {
infinite() {
this.fDone = null!;
this.fInfinite = true;
return this;
}
public total(total: number) {
total(total: number) {
this.fDone = null!;
this.fTotal = total;
return this;
}
public hasTotal() {
hasTotal() {
return !!this.fTotal;
}
public worked(worked: number) {
worked(worked: number) {
this.fDone = null!;
if (this.fWorked) {
......@@ -127,7 +76,7 @@ class TestProgressBar {
return this;
}
public done() {
done() {
this.fDone = true;
this.fInfinite = null!;
......@@ -137,25 +86,21 @@ class TestProgressBar {
return this;
}
public stop() {
stop() {
return this.done();
}
public show(): void {
}
public hide(): void {
show(): void { }
}
hide(): void { }
}
suite('Progress Service', () => {
suite('Progress Indicator', () => {
test('ScopedService', () => {
test('CompositeScope', () => {
let viewletService = new TestViewletService();
let panelService = new TestPanelService();
let service = new TestScopedService(viewletService, panelService, 'test.scopeId');
let service = new TestCompositeScope(viewletService, panelService, 'test.scopeId');
const testViewlet = new TestViewlet('test.scopeId');
assert(!service.isActive);
......@@ -167,11 +112,11 @@ suite('Progress Service', () => {
});
test('WorkbenchProgressService', async () => {
test('CompositeProgressIndicator', async () => {
let testProgressBar = new TestProgressBar();
let viewletService = new TestViewletService();
let panelService = new TestPanelService();
let service = new ScopedProgressService((<any>testProgressBar), 'test.scopeId', true, viewletService, panelService);
let service = new CompositeProgressIndicator((<any>testProgressBar), 'test.scopeId', true, viewletService, panelService);
// Active: Show (Infinite)
let fn = service.show(true);
......
......@@ -7,7 +7,7 @@ import { IViewlet } from 'vs/workbench/common/viewlet';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { Event } from 'vs/base/common/event';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { ILocalProgressService } from 'vs/platform/progress/common/progress';
import { IProgressIndicator } from 'vs/platform/progress/common/progress';
export const IViewletService = createDecorator<IViewletService>('viewletService');
......@@ -48,7 +48,7 @@ export interface IViewletService {
/**
* Returns the progress indicator for the side bar.
*/
getProgressIndicator(id: string): ILocalProgressService | null;
getProgressIndicator(id: string): IProgressIndicator | null;
/**
* Hide the active viewlet.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册