提交 dd7801f8 编写于 作者: I isidor

debug debt: make service interface slimmer, introduce IConfigurationManager

上级 46d223fe
......@@ -66,7 +66,7 @@ export class SelectConfigActionItem extends BaseActionItem {
let previousSelectedIndex = this.select.selectedIndex;
this.select.options.length = 0;
return this.debugService.loadLaunchConfig().then(config => {
return this.debugService.getConfigurationManager().loadLaunchConfig().then(config => {
if (!config || !config.configurations) {
this.select.add(this.createOption(`<${ nls.localize('none', "none") }>`));
this.select.disabled = true;
......@@ -77,7 +77,7 @@ export class SelectConfigActionItem extends BaseActionItem {
this.select.disabled = configurations.length < 1;
let found = false;
const configurationName = this.debugService.getConfigurationName();
const configurationName = this.debugService.getConfigurationManager().configurationName;
for (let i = 0; i < configurations.length; i++) {
this.select.add(this.createOption(configurations[i].name));
if (configurationName === configurations[i].name) {
......
......@@ -77,7 +77,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution {
if (e.target.type !== editorcommon.MouseTargetType.GUTTER_GLYPH_MARGIN || /* after last line */ e.target.detail) {
return;
}
if (!this.debugService.canSetBreakpointsIn(this.editor.getModel())) {
if (!this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
return;
}
......@@ -100,7 +100,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution {
this.toDispose.push(this.editor.addListener2(editorcommon.EventType.MouseMove, (e: editorbrowser.IEditorMouseEvent) => {
var showBreakpointHintAtLineNumber = -1;
if (e.target.type === editorcommon.MouseTargetType.GUTTER_GLYPH_MARGIN && this.debugService.canSetBreakpointsIn(this.editor.getModel())) {
if (e.target.type === editorcommon.MouseTargetType.GUTTER_GLYPH_MARGIN && this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
if (!e.target.detail) {
// is not after last line
showBreakpointHintAtLineNumber = e.target.position.lineNumber;
......
......@@ -6,6 +6,7 @@
import uri from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IActionRunner } from 'vs/base/common/actions';
import Event from 'vs/base/common/event';
import ee = require('vs/base/common/eventEmitter');
import severity from 'vs/base/common/severity';
import { IViewletView } from 'vs/workbench/browser/viewlet';
......@@ -149,8 +150,7 @@ export var ViewModelEvents = {
};
export var ServiceEvents = {
STATE_CHANGED: 'StateChanged',
CONFIGURATION_CHANGED: 'ConfigurationChanged'
STATE_CHANGED: 'StateChanged'
};
export var SessionEvents = {
......@@ -264,17 +264,29 @@ export interface IRawDebugSession extends ee.EventEmitter {
evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;
}
export interface IConfigurationManager {
configurationName: string;
setConfiguration(name: string): TPromise<void>;
openConfigFile(sideBySide: boolean): TPromise<boolean>;
loadLaunchConfig(): TPromise<IGlobalConfig>;
canSetBreakpointsIn(model: editor.IModel): boolean;
/**
* Allows to register on change of debug configuration.
*/
onDidConfigurationChange: Event<string>;
}
export var IDebugService = createDecorator<IDebugService>(DEBUG_SERVICE_ID);
export interface IDebugService extends ee.IEventEmitter {
serviceId: ServiceIdentifier<any>;
getState(): State;
canSetBreakpointsIn(model: editor.IModel): boolean;
getConfigurationName(): string;
setConfiguration(name: string): TPromise<void>;
openConfigFile(sideBySide: boolean): TPromise<boolean>;
loadLaunchConfig(): TPromise<IGlobalConfig>;
/**
* Gets the current configuration manager.
*/
getConfigurationManager(): IConfigurationManager;
/**
* Sets the focused stack frame and evaluates all expresions against the newly focused stack frame,
......
......@@ -80,14 +80,14 @@ export class ConfigureAction extends AbstractDebugAction {
constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) {
super(id, label, 'debug-action configure', debugService, keybindingService);
this.toDispose.push(debugService.addListener2(debug.ServiceEvents.CONFIGURATION_CHANGED, e => {
this.class = this.debugService.getConfigurationName() ? 'debug-action configure' : 'debug-action configure notification';
this.toDispose.push(debugService.getConfigurationManager().onDidConfigurationChange((configurationName) => {
this.class = configurationName ? 'debug-action configure' : 'debug-action configure notification';
}));
}
public run(event?: any): TPromise<any> {
const sideBySide = !!(event && (event.ctrlKey || event.metaKey));
return this.debugService.openConfigFile(sideBySide);
return this.debugService.getConfigurationManager().openConfigFile(sideBySide);
}
}
......@@ -100,7 +100,7 @@ export class SelectConfigAction extends AbstractDebugAction {
}
public run(configName: string): TPromise<any> {
return this.debugService.setConfiguration(configName);
return this.debugService.getConfigurationManager().setConfiguration(configName);
}
protected isEnabled(): boolean {
......@@ -453,7 +453,7 @@ export class ToggleBreakpointAction extends EditorAction {
if (this.debugService.getState() !== debug.State.Disabled) {
const lineNumber = this.editor.getPosition().lineNumber;
const modelUrl = this.editor.getModel().getAssociatedResource();
if (this.debugService.canSetBreakpointsIn(this.editor.getModel())) {
if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
return this.debugService.toggleBreakpoint({ uri: modelUrl, lineNumber: lineNumber });
}
}
......@@ -472,7 +472,7 @@ export class EditorConditionalBreakpointAction extends EditorAction {
public run(): TPromise<any> {
if (this.debugService.getState() !== debug.State.Disabled) {
const lineNumber = this.editor.getPosition().lineNumber;
if (this.debugService.canSetBreakpointsIn(this.editor.getModel())) {
if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
return this.debugService.editBreakpoint(<editorbrowser.ICodeEditor>this.editor, lineNumber);
}
}
......@@ -584,7 +584,7 @@ export class SelectionToWatchExpressionsAction extends EditorAction {
const selection = this.editor.getSelection();
const text = this.editor.getModel().getValueInRange(selection);
return !!selection && !selection.isEmpty() && this.debugService.getConfigurationName() && text && /\S/.test(text);
return !!selection && !selection.isEmpty() && this.debugService.getConfigurationManager().configurationName && text && /\S/.test(text);
}
}
......
......@@ -14,7 +14,6 @@ import types = require('vs/base/common/types');
import errors = require('vs/base/common/errors');
import severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base';
import editor = require('vs/editor/common/editorCommon');
import aria = require('vs/base/browser/ui/aria/aria');
import { AIAdapter } from 'vs/base/node/aiAdapter';
import editorbrowser = require('vs/editor/browser/editorBrowser');
......@@ -272,7 +271,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
aria.status(nls.localize('debuggingContinued', "Debugging continued."));
this.model.continueThreads();
this.setFocusedStackFrameAndEvaluate(null).done(null, errors.onUnexpectedError);
this.setStateAndEmit(this.configurationManager.getConfiguration().noDebug ? debug.State.RunningNoDebug : debug.State.Running);
this.setStateAndEmit(this.configurationManager.configuration.noDebug ? debug.State.RunningNoDebug : debug.State.Running);
}));
this.toDisposeOnSessionEnd.push(this.session.addListener2(debug.SessionEvents.THREAD, (event: DebugProtocol.ThreadEvent) => {
......@@ -531,9 +530,9 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
return this.textFileService.saveAll()
.then(() => this.extensionService.onReady()
.then(() => this.setConfiguration(this.configurationManager.getConfigurationName())
.then(() => this.configurationManager.setConfiguration((this.configurationManager.configurationName))
.then(() => {
const configuration = this.configurationManager.getConfiguration();
const configuration = this.configurationManager.configuration;
if (!configuration) {
return this.configurationManager.openConfigFile(false).then(openend => {
if (openend) {
......@@ -543,7 +542,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
configuration.noDebug = noDebug;
if (!this.configurationManager.getAdapter()) {
if (!this.configurationManager.adapter) {
return configuration.type ? TPromise.wrapError(new Error(nls.localize('debugTypeNotSupported', "Configured debug type '{0}' is not supported.", configuration.type)))
: TPromise.wrapError(errors.create(nls.localize('debugTypeMissing', "Missing property 'type' for the selected configuration in launch.json."),
{ actions: [CloseAction, this.instantiationService.createInstance(debugactions.ConfigureAction, debugactions.ConfigureAction.ID, debugactions.ConfigureAction.LABEL)] }));
......@@ -580,14 +579,14 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
private doCreateSession(configuration: debug.IConfig, changeViewState: boolean): TPromise<any> {
this.setStateAndEmit(debug.State.Initializing);
const key = this.configurationManager.getAdapter().aiKey;
const key = this.configurationManager.adapter.aiKey;
const telemetryInfo = Object.create(null);
this.telemetryService.getTelemetryInfo().then(info => {
telemetryInfo['common.vscodemachineid'] = info.machineId;
telemetryInfo['common.vscodesessionid'] = info.sessionId;
}, errors.onUnexpectedError);
this.telemetryAdapter = new AIAdapter(key, this.configurationManager.getAdapter().type, null, telemetryInfo);
this.session = new session.RawDebugSession(this.messageService, this.telemetryService, configuration.debugServer, this.configurationManager.getAdapter(), this.telemetryAdapter);
this.telemetryAdapter = new AIAdapter(key, this.configurationManager.adapter.type, null, telemetryInfo);
this.session = new session.RawDebugSession(this.messageService, this.telemetryService, configuration.debugServer, this.configurationManager.adapter, this.telemetryAdapter);
this.registerSessionListeners();
......@@ -686,8 +685,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
this.session.disconnect().done(null, errors.onUnexpectedError);
}
const configuration = this.configurationManager.getConfiguration();
this.setStateAndEmit(debug.State.Initializing);
const configuration = this.configurationManager.configuration;
return this.doCreateSession({
type: configuration.type,
request: 'attach',
......@@ -823,24 +822,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
return this.editorService.openEditor(editorInput, wbeditorcommon.TextEditorOptions.create({ preserveFocus: true }), sideBySide);
}
public canSetBreakpointsIn(model: editor.IModel): boolean {
return this.configurationManager.canSetBreakpointsIn(model);
}
public getConfigurationName(): string {
return this.configurationManager.getConfigurationName();
}
public setConfiguration(name: string): TPromise<void> {
return this.configurationManager.setConfiguration(name).then(() => this.emit(debug.ServiceEvents.CONFIGURATION_CHANGED));
}
public openConfigFile(sideBySide: boolean): TPromise<boolean> {
return this.configurationManager.openConfigFile(sideBySide);
}
public loadLaunchConfig(): TPromise<debug.IGlobalConfig> {
return this.configurationManager.loadLaunchConfig();
public getConfigurationManager(): debug.IConfigurationManager {
return this.configurationManager;
}
private getDebugStringEditorInput(source: Source, value: string, mtype: string): DebugStringEditorInput {
......@@ -922,7 +905,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
this.storageService.store(DEBUG_BREAKPOINTS_ACTIVATED_KEY, this.model.areBreakpointsActivated() ? 'true' : 'false', StorageScope.WORKSPACE);
this.storageService.store(DEBUG_FUNCTION_BREAKPOINTS_KEY, JSON.stringify(this.model.getFunctionBreakpoints()), StorageScope.WORKSPACE);
this.storageService.store(DEBUG_EXCEPTION_BREAKPOINTS_KEY, JSON.stringify(this.model.getExceptionBreakpoints()), StorageScope.WORKSPACE);
this.storageService.store(DEBUG_SELECTED_CONFIG_NAME_KEY, this.configurationManager.getConfigurationName(), StorageScope.WORKSPACE);
this.storageService.store(DEBUG_SELECTED_CONFIG_NAME_KEY, this.configurationManager.configurationName, StorageScope.WORKSPACE);
this.storageService.store(DEBUG_WATCH_EXPRESSIONS_KEY, JSON.stringify(this.model.getWatchExpressions()), StorageScope.WORKSPACE);
}
......
......@@ -7,6 +7,7 @@ import path = require('path');
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import strings = require('vs/base/common/strings');
import Event, { Emitter } from 'vs/base/common/event';
import objects = require('vs/base/common/objects');
import uri from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
......@@ -143,12 +144,13 @@ const jsonRegistry = <jsonContributionRegistry.IJSONContributionRegistry>platfor
jsonRegistry.registerSchema(schemaId, schema);
jsonRegistry.addSchemaFileAssociation('/.vscode/launch.json', schemaId);
export class ConfigurationManager {
export class ConfigurationManager implements debug.IConfigurationManager {
private configuration: debug.IConfig;
public configuration: debug.IConfig;
private systemVariables: SystemVariables;
private adapters: Adapter[];
private allModeIdsForBreakpoints: { [key: string]: boolean };
private _onDidConfigurationChange: Emitter<string>;
constructor(
configName: string,
......@@ -159,6 +161,7 @@ export class ConfigurationManager {
@IConfigurationService private configurationService: IConfigurationService,
@IQuickOpenService private quickOpenService: IQuickOpenService
) {
this._onDidConfigurationChange = new Emitter<string>();
this.systemVariables = this.contextService.getWorkspace() ? new SystemVariables(this.editorService, this.contextService) : null;
this.setConfiguration(configName);
this.adapters = [];
......@@ -214,15 +217,15 @@ export class ConfigurationManager {
});
}
public getConfiguration(): debug.IConfig {
return this.configuration;
public get onDidConfigurationChange(): Event<string> {
return this._onDidConfigurationChange.event;
}
public getConfigurationName(): string {
public get configurationName(): string {
return this.configuration ? this.configuration.name : null;
}
public getAdapter(): Adapter {
public get adapter(): Adapter {
return this.adapters.filter(adapter => strings.equalsIgnoreCase(adapter.type, this.configuration.type)).pop();
}
......@@ -246,7 +249,7 @@ export class ConfigurationManager {
}
this.configuration.debugServer = config.debugServer;
}
});
}).then(() => this._onDidConfigurationChange.fire(this.configurationName));
}
public openConfigFile(sideBySide: boolean): TPromise<boolean> {
......
......@@ -25,26 +25,10 @@ export class MockDebugService extends ee.EventEmitter implements debug.IDebugSer
return null;
}
public canSetBreakpointsIn(model: editor.IModel): boolean {
return false;
}
public getConfigurationName(): string {
public getConfigurationManager(): debug.IConfigurationManager {
return null;
}
public setConfiguration(name: string): TPromise<void> {
return TPromise.as(null);
}
public openConfigFile(sideBySide: boolean): TPromise<boolean> {
return TPromise.as(false);
}
public loadLaunchConfig(): TPromise<debug.IGlobalConfig> {
return TPromise.as(null);
}
public setFocusedStackFrameAndEvaluate(focusedStackFrame: debug.IStackFrame): TPromise<void> {
return TPromise.as(null);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册