提交 13cf79ac 编写于 作者: I isidor

debug debt: debug service is no longer an event emitter

上级 238cc8ae
...@@ -10,7 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -10,7 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import dom = require('vs/base/browser/dom'); import dom = require('vs/base/browser/dom');
import { IAction } from 'vs/base/common/actions'; import { IAction } from 'vs/base/common/actions';
import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { IDebugService, ServiceEvents, State } from 'vs/workbench/parts/debug/common/debug'; import { IDebugService, State } from 'vs/workbench/parts/debug/common/debug';
import { IConfigurationService, ConfigurationServiceEventTypes } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService, ConfigurationServiceEventTypes } from 'vs/platform/configuration/common/configuration';
export class SelectConfigActionItem extends BaseActionItem { export class SelectConfigActionItem extends BaseActionItem {
...@@ -36,8 +36,8 @@ export class SelectConfigActionItem extends BaseActionItem { ...@@ -36,8 +36,8 @@ export class SelectConfigActionItem extends BaseActionItem {
this.toDispose.push(dom.addStandardDisposableListener(this.select, 'change', (e) => { this.toDispose.push(dom.addStandardDisposableListener(this.select, 'change', (e) => {
this.actionRunner.run(this._action, e.target.value).done(null, errors.onUnexpectedError); this.actionRunner.run(this._action, e.target.value).done(null, errors.onUnexpectedError);
})); }));
this.toDispose.push(this.debugService.addListener2(ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState(state => {
this.select.disabled = this.debugService.getState() !== State.Inactive; this.select.disabled = state !== State.Inactive;
})); }));
this.toDispose.push(configurationService.addListener2(ConfigurationServiceEventTypes.UPDATED, e => { this.toDispose.push(configurationService.addListener2(ConfigurationServiceEventTypes.UPDATED, e => {
this.setOptions().done(null, errors.onUnexpectedError); this.setOptions().done(null, errors.onUnexpectedError);
......
...@@ -55,8 +55,8 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution { ...@@ -55,8 +55,8 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution {
} }
private registerListeners(): void { private registerListeners(): void {
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState(state => {
this.onDebugStateChange(); this.onDebugStateChange(state);
})); }));
this.toDispose.push(this.actionBar.actionRunner.addListener2(events.EventType.RUN, (e: any) => { this.toDispose.push(this.actionBar.actionRunner.addListener2(events.EventType.RUN, (e: any) => {
// check for error // check for error
...@@ -75,8 +75,7 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution { ...@@ -75,8 +75,7 @@ export class DebugActionsWidget implements wbext.IWorkbenchContribution {
return DebugActionsWidget.ID; return DebugActionsWidget.ID;
} }
private onDebugStateChange(): void { private onDebugStateChange(state: debug.State): void {
const state = this.debugService.getState();
if (state === debug.State.Disabled || state === debug.State.Inactive || state === debug.State.Initializing) { if (state === debug.State.Disabled || state === debug.State.Inactive || state === debug.State.Initializing) {
return this.hide(); return this.hide();
} }
......
...@@ -111,7 +111,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { ...@@ -111,7 +111,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution {
this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseLeave, (e: editorbrowser.IEditorMouseEvent) => { this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseLeave, (e: editorbrowser.IEditorMouseEvent) => {
this.ensureBreakpointHintDecoration(-1); this.ensureBreakpointHintDecoration(-1);
})); }));
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => this.onDebugStateUpdate())); this.toDispose.push(this.debugService.onDidChangeState(state => this.onDebugStateUpdate(state)));
// hover listeners & hover widget // hover listeners & hover widget
this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseDown, (e: editorbrowser.IEditorMouseEvent) => this.onEditorMouseDown(e))); this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseDown, (e: editorbrowser.IEditorMouseEvent) => this.onEditorMouseDown(e)));
...@@ -147,12 +147,12 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { ...@@ -147,12 +147,12 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution {
this.breakpointHintDecoration = this.editor.deltaDecorations(this.breakpointHintDecoration, newDecoration); this.breakpointHintDecoration = this.editor.deltaDecorations(this.breakpointHintDecoration, newDecoration);
} }
private onDebugStateUpdate(): void { private onDebugStateUpdate(state: debug.State): void {
if (this.debugService.getState() !== debug.State.Stopped) { if (state !== debug.State.Stopped) {
this.hideHoverWidget(); this.hideHoverWidget();
} }
this.contextService.updateOptions('editor', { this.contextService.updateOptions('editor', {
hover: this.debugService.getState() !== debug.State.Stopped hover: state !== debug.State.Stopped
}); });
} }
......
...@@ -8,7 +8,7 @@ import objects = require('vs/base/common/objects'); ...@@ -8,7 +8,7 @@ import objects = require('vs/base/common/objects');
import lifecycle = require('vs/base/common/lifecycle'); import lifecycle = require('vs/base/common/lifecycle');
import editorcommon = require('vs/editor/common/editorCommon'); import editorcommon = require('vs/editor/common/editorCommon');
import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IDebugService, IBreakpoint, IRawBreakpoint, State, ServiceEvents } from 'vs/workbench/parts/debug/common/debug'; import { IDebugService, IBreakpoint, IRawBreakpoint, State } from 'vs/workbench/parts/debug/common/debug';
import { IModelService } from 'vs/editor/common/services/modelService'; import { IModelService } from 'vs/editor/common/services/modelService';
function toMap(arr: string[]): { [key: string]: boolean; } { function toMap(arr: string[]): { [key: string]: boolean; } {
...@@ -82,8 +82,8 @@ export class DebugEditorModelManager implements IWorkbenchContribution { ...@@ -82,8 +82,8 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
this.toDispose.push(this.debugService.getModel().onDidChangeBreakpoints(() => this.onBreakpointsChange())); this.toDispose.push(this.debugService.getModel().onDidChangeBreakpoints(() => this.onBreakpointsChange()));
this.toDispose.push(this.debugService.getViewModel().onDidFocusStackFrame(() => this.onFocusStackFrame())); this.toDispose.push(this.debugService.getViewModel().onDidFocusStackFrame(() => this.onFocusStackFrame()));
this.toDispose.push(this.debugService.addListener2(ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState(state => {
if (this.debugService.getState() === State.Inactive) { if (state === State.Inactive) {
Object.keys(this.modelData).forEach(key => this.modelData[key].dirty = false); Object.keys(this.modelData).forEach(key => this.modelData[key].dirty = false);
} }
})); }));
......
...@@ -51,8 +51,8 @@ export class DebugViewlet extends Viewlet { ...@@ -51,8 +51,8 @@ export class DebugViewlet extends Viewlet {
this.progressRunner = null; this.progressRunner = null;
this.viewletSettings = this.getMemento(storageService, memento.Scope.WORKSPACE); this.viewletSettings = this.getMemento(storageService, memento.Scope.WORKSPACE);
this.toDispose = []; this.toDispose = [];
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState((state) => {
this.onDebugServiceStateChange(); this.onDebugServiceStateChange(state);
})); }));
} }
...@@ -144,12 +144,12 @@ export class DebugViewlet extends Viewlet { ...@@ -144,12 +144,12 @@ export class DebugViewlet extends Viewlet {
return null; return null;
} }
private onDebugServiceStateChange(): void { private onDebugServiceStateChange(newState: debug.State): void {
if (this.progressRunner) { if (this.progressRunner) {
this.progressRunner.done(); this.progressRunner.done();
} }
if (this.debugService.getState() === debug.State.Initializing) { if (newState === debug.State.Initializing) {
this.progressRunner = this.progressService.show(true); this.progressRunner = this.progressService.show(true);
} else { } else {
this.progressRunner = null; this.progressRunner = null;
......
...@@ -83,8 +83,8 @@ export class VariablesView extends viewlet.CollapsibleViewletView { ...@@ -83,8 +83,8 @@ export class VariablesView extends viewlet.CollapsibleViewletView {
this.toolBar.setActions(actionbarregistry.prepareActions([collapseAction]))(); this.toolBar.setActions(actionbarregistry.prepareActions([collapseAction]))();
this.toDispose.push(viewModel.onDidFocusStackFrame(sf => this.onFocusStackFrame(sf))); this.toDispose.push(viewModel.onDidFocusStackFrame(sf => this.onFocusStackFrame(sf)));
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState(state => {
collapseAction.enabled = this.debugService.getState() === debug.State.Running || this.debugService.getState() === debug.State.Stopped; collapseAction.enabled = state === debug.State.Running || state === debug.State.Stopped;
})); }));
this.toDispose.push(this.tree.addListener2(events.EventType.FOCUS, (e: tree.IFocusEvent) => { this.toDispose.push(this.tree.addListener2(events.EventType.FOCUS, (e: tree.IFocusEvent) => {
......
...@@ -134,10 +134,6 @@ export interface IExceptionBreakpoint extends IEnablement { ...@@ -134,10 +134,6 @@ export interface IExceptionBreakpoint extends IEnablement {
label: string; label: string;
} }
export var ServiceEvents = {
STATE_CHANGED: 'StateChanged'
};
export var SessionEvents = { export var SessionEvents = {
INITIALIZED: 'initialized', INITIALIZED: 'initialized',
STOPPED: 'stopped', STOPPED: 'stopped',
...@@ -273,7 +269,7 @@ export interface IConfigurationManager { ...@@ -273,7 +269,7 @@ export interface IConfigurationManager {
export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID); export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);
export interface IDebugService extends ee.IEventEmitter { export interface IDebugService {
serviceId: ServiceIdentifier<any>; serviceId: ServiceIdentifier<any>;
/** /**
...@@ -281,6 +277,11 @@ export interface IDebugService extends ee.IEventEmitter { ...@@ -281,6 +277,11 @@ export interface IDebugService extends ee.IEventEmitter {
*/ */
getState(): State; getState(): State;
/**
* Allows to register on debug state changes.
*/
onDidChangeState: Event<State>;
/** /**
* Gets the current configuration manager. * Gets the current configuration manager.
*/ */
......
...@@ -35,7 +35,7 @@ export class AbstractDebugAction extends actions.Action { ...@@ -35,7 +35,7 @@ export class AbstractDebugAction extends actions.Action {
this.debugService = debugService; this.debugService = debugService;
this.keybindingService = keybindingService; this.keybindingService = keybindingService;
this.toDispose = []; this.toDispose = [];
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => this.updateEnablement())); this.toDispose.push(this.debugService.onDidChangeState(() => this.updateEnablement()));
const keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k)); const keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) { if (keys && keys.length) {
...@@ -134,7 +134,7 @@ export class RestartDebugAction extends AbstractDebugAction { ...@@ -134,7 +134,7 @@ export class RestartDebugAction extends AbstractDebugAction {
constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) {
super(id, label, 'debug-action restart', debugService, keybindingService); super(id, label, 'debug-action restart', debugService, keybindingService);
this.updateEnablement(); this.updateEnablement();
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState(() => {
const session = this.debugService.getActiveSession(); const session = this.debugService.getActiveSession();
if (session) { if (session) {
this.updateLabel(session.isAttach ? RestartDebugAction.RECONNECT_LABEL : RestartDebugAction.LABEL); this.updateLabel(session.isAttach ? RestartDebugAction.RECONNECT_LABEL : RestartDebugAction.LABEL);
...@@ -209,7 +209,7 @@ export class StopDebugAction extends AbstractDebugAction { ...@@ -209,7 +209,7 @@ export class StopDebugAction extends AbstractDebugAction {
constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) {
super(id, label, 'debug-action stop', debugService, keybindingService); super(id, label, 'debug-action stop', debugService, keybindingService);
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => { this.toDispose.push(this.debugService.onDidChangeState(() => {
const session = this.debugService.getActiveSession(); const session = this.debugService.getActiveSession();
if (session) { if (session) {
this.updateLabel(session.isAttach ? StopDebugAction.DISCONNECT_LABEL : StopDebugAction.LABEL); this.updateLabel(session.isAttach ? StopDebugAction.DISCONNECT_LABEL : StopDebugAction.LABEL);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import nls = require('vs/nls'); import nls = require('vs/nls');
import lifecycle = require('vs/base/common/lifecycle'); import lifecycle = require('vs/base/common/lifecycle');
import mime = require('vs/base/common/mime'); import mime = require('vs/base/common/mime');
import ee = require('vs/base/common/eventEmitter'); import Event, { Emitter } from 'vs/base/common/event';
import uri from 'vs/base/common/uri'; import uri from 'vs/base/common/uri';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
import arrays = require('vs/base/common/arrays'); import arrays = require('vs/base/common/arrays');
...@@ -56,10 +56,11 @@ const DEBUG_EXCEPTION_BREAKPOINTS_KEY = 'debug.exceptionbreakpoint'; ...@@ -56,10 +56,11 @@ const DEBUG_EXCEPTION_BREAKPOINTS_KEY = 'debug.exceptionbreakpoint';
const DEBUG_WATCH_EXPRESSIONS_KEY = 'debug.watchexpressions'; const DEBUG_WATCH_EXPRESSIONS_KEY = 'debug.watchexpressions';
const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname'; const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname';
export class DebugService extends ee.EventEmitter implements debug.IDebugService { export class DebugService implements debug.IDebugService {
public serviceId = debug.IDebugService; public serviceId = debug.IDebugService;
private state: debug.State; private state: debug.State;
private _onDidChangeState: Emitter<debug.State>;
private session: session.RawDebugSession; private session: session.RawDebugSession;
private model: model.Model; private model: model.Model;
private viewModel: viewmodel.ViewModel; private viewModel: viewmodel.ViewModel;
...@@ -91,13 +92,12 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService ...@@ -91,13 +92,12 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
@IMarkerService private markerService: IMarkerService, @IMarkerService private markerService: IMarkerService,
@ITaskService private taskService: ITaskService @ITaskService private taskService: ITaskService
) { ) {
super();
this.toDispose = []; this.toDispose = [];
this.toDisposeOnSessionEnd = []; this.toDisposeOnSessionEnd = [];
this.debugStringEditorInputs = []; this.debugStringEditorInputs = [];
this.session = null; this.session = null;
this.state = debug.State.Inactive; this.state = debug.State.Inactive;
this._onDidChangeState = new Emitter<debug.State>();
if (!this.contextService.getWorkspace()) { if (!this.contextService.getWorkspace()) {
this.state = debug.State.Disabled; this.state = debug.State.Disabled;
...@@ -404,9 +404,13 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService ...@@ -404,9 +404,13 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
return this.state; return this.state;
} }
public get onDidChangeState(): Event<debug.State> {
return this._onDidChangeState.event;
}
private setStateAndEmit(newState: debug.State): void { private setStateAndEmit(newState: debug.State): void {
this.state = newState; this.state = newState;
this.emit(debug.ServiceEvents.STATE_CHANGED); this._onDidChangeState.fire(newState);
} }
public get enabled(): boolean { public get enabled(): boolean {
......
...@@ -3,21 +3,21 @@ ...@@ -3,21 +3,21 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import debug = require('vs/workbench/parts/debug/common/debug'); import Event from 'vs/base/common/event';
import editor = require('vs/editor/common/editorCommon');
import ee = require('vs/base/common/eventEmitter'); import ee = require('vs/base/common/eventEmitter');
import uri from 'vs/base/common/uri'; import uri from 'vs/base/common/uri';
import editorbrowser = require('vs/editor/browser/editorBrowser');
import severity from 'vs/base/common/severity'; import severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import editor = require('vs/editor/common/editorCommon');
import editorbrowser = require('vs/editor/browser/editorBrowser');
import debug = require('vs/workbench/parts/debug/common/debug');
import { Source } from 'vs/workbench/parts/debug/common/debugSource'; import { Source } from 'vs/workbench/parts/debug/common/debugSource';
export class MockDebugService extends ee.EventEmitter implements debug.IDebugService { export class MockDebugService implements debug.IDebugService {
private session: MockRawSession; private session: MockRawSession;
public serviceId = debug.IDebugService; public serviceId = debug.IDebugService;
constructor() { constructor() {
super();
this.session = new MockRawSession(); this.session = new MockRawSession();
} }
...@@ -25,6 +25,10 @@ export class MockDebugService extends ee.EventEmitter implements debug.IDebugSer ...@@ -25,6 +25,10 @@ export class MockDebugService extends ee.EventEmitter implements debug.IDebugSer
return null; return null;
} }
public get onDidChangeState(): Event<debug.State> {
return null;
}
public getConfigurationManager(): debug.IConfigurationManager { public getConfigurationManager(): debug.IConfigurationManager {
return null; return null;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册