提交 79134b57 编写于 作者: I isidor

debug: polish and simplify debugConfigurationManager

上级 8236d1e9
......@@ -9,14 +9,14 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IAction } from 'vs/base/common/actions';
import { SelectActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDebugService, State } from 'vs/workbench/parts/debug/common/debug';
import { IDebugService, State, IGlobalConfig } from 'vs/workbench/parts/debug/common/debug';
export class DebugSelectActionItem extends SelectActionItem {
constructor(
action: IAction,
@IDebugService private debugService: IDebugService,
@IConfigurationService configurationService: IConfigurationService
@IConfigurationService private configurationService: IConfigurationService
) {
super(null, action, [], -1);
......@@ -38,20 +38,18 @@ export class DebugSelectActionItem extends SelectActionItem {
}
private updateOptions(changeDebugConfiguration: boolean): TPromise<any> {
const configurationManager = this.debugService.getConfigurationManager();
return configurationManager.loadLaunchConfig().then(config => {
if (!config || !config.configurations || config.configurations.length === 0) {
this.setOptions([nls.localize('noConfigurations', "No Configurations")], 0);
return changeDebugConfiguration ? this.actionRunner.run(this._action, null) : null;
}
const configurationNames = config.configurations.filter(cfg => !!cfg.name).map(cfg => cfg.name);
const selected = configurationNames.indexOf(this.debugService.getViewModel().selectedConfigurationName);
this.setOptions(configurationNames, selected);
if (changeDebugConfiguration) {
return this.actionRunner.run(this._action, this.getSelected());
}
});
const config = this.configurationService.getConfiguration<IGlobalConfig>('launch');
if (!config || !config.configurations || config.configurations.length === 0) {
this.setOptions([nls.localize('noConfigurations', "No Configurations")], 0);
return changeDebugConfiguration ? this.actionRunner.run(this._action, null) : TPromise.as(null);
}
const configurationNames = config.configurations.filter(cfg => !!cfg.name).map(cfg => cfg.name);
const selected = configurationNames.indexOf(this.debugService.getViewModel().selectedConfigurationName);
this.setOptions(configurationNames, selected);
if (changeDebugConfiguration) {
return this.actionRunner.run(this._action, this.getSelected());
}
}
}
......@@ -72,7 +72,6 @@ export enum SessionRequestType {
}
export interface ISession {
// TODO@Isidor consider removing this - feels ugly
requestType: SessionRequestType;
stackTrace(args: DebugProtocol.StackTraceArguments): TPromise<DebugProtocol.StackTraceResponse>;
scopes(args: DebugProtocol.ScopesArguments): TPromise<DebugProtocol.ScopesResponse>;
......@@ -350,9 +349,6 @@ export interface IConfigurationManager {
*/
openConfigFile(sideBySide: boolean): TPromise<boolean>;
// TODO@Isidor remove this from the interface
loadLaunchConfig(): TPromise<IGlobalConfig>;
/**
* Returns true if breakpoints can be set for a given editor model. Depends on mode.
*/
......
......@@ -8,7 +8,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
import strings = require('vs/base/common/strings');
import types = require('vs/base/common/types');
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
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';
......@@ -169,7 +168,6 @@ jsonRegistry.registerSchema(schemaId, schema);
export class ConfigurationManager implements debug.IConfigurationManager {
private adapters: Adapter[];
private allModeIdsForBreakpoints: { [key: string]: boolean };
private _onDidConfigurationChange: Emitter<debug.IConfig>;
constructor(
@IWorkspaceContextService private contextService: IWorkspaceContextService,
......@@ -181,7 +179,6 @@ export class ConfigurationManager implements debug.IConfigurationManager {
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService,
@IInstantiationService private instantiationService: IInstantiationService
) {
this._onDidConfigurationChange = new Emitter<debug.IConfig>();
this.adapters = [];
this.registerListeners();
this.allModeIdsForBreakpoints = {};
......@@ -243,63 +240,56 @@ export class ConfigurationManager implements debug.IConfigurationManager {
});
}
public get onDidConfigurationChange(): Event<debug.IConfig> {
return this._onDidConfigurationChange.event;
}
public getAdapter(type: string): Adapter {
return this.adapters.filter(adapter => strings.equalsIgnoreCase(adapter.type, type)).pop();
}
public getConfiguration(nameOrConfig: string | debug.IConfig): TPromise<debug.IConfig> {
return this.loadLaunchConfig().then(config => {
let result: debug.IConfig = null;
if (types.isObject(nameOrConfig)) {
result = objects.deepClone(nameOrConfig) as debug.IConfig;
} else {
if (!config || !config.configurations) {
return result;
}
// if the configuration name is not set yet, take the first launch config (can happen if debug viewlet has not been opened yet).
const filtered = config.configurations.filter(cfg => cfg.name === nameOrConfig);
const config = this.configurationService.getConfiguration<debug.IGlobalConfig>('launch');
result = filtered.length === 1 ? filtered[0] : config.configurations[0];
result = objects.deepClone(result);
if (config && result) {
result.debugServer = config.debugServer;
}
let result: debug.IConfig = null;
if (types.isObject(nameOrConfig)) {
result = objects.deepClone(nameOrConfig) as debug.IConfig;
} else {
if (!config || !config.configurations) {
return TPromise.as(null);
}
// if the configuration name is not set yet, take the first launch config (can happen if debug viewlet has not been opened yet).
const filtered = config.configurations.filter(cfg => cfg.name === nameOrConfig);
if (result) {
// Set operating system specific properties #1873
if (isWindows && result.windows) {
Object.keys(result.windows).forEach(key => {
result[key] = result.windows[key];
});
}
if (isMacintosh && result.osx) {
Object.keys(result.osx).forEach(key => {
result[key] = result.osx[key];
});
}
if (isLinux && result.linux) {
Object.keys(result.linux).forEach(key => {
result[key] = result.linux[key];
});
}
result = filtered.length === 1 ? filtered[0] : config.configurations[0];
result = objects.deepClone(result);
if (config && result) {
result.debugServer = config.debugServer;
}
}
// massage configuration attributes - append workspace path to relatvie paths, substitute variables in paths.
Object.keys(result).forEach(key => {
result[key] = this.configurationResolverService.resolveAny(result[key]);
if (result) {
// Set operating system specific properties #1873
if (isWindows && result.windows) {
Object.keys(result.windows).forEach(key => {
result[key] = result.windows[key];
});
const adapter = this.getAdapter(result.type);
return this.configurationResolverService.resolveInteractiveVariables(result, adapter ? adapter.variables : null);
}
}).then(result => {
this._onDidConfigurationChange.fire(result);
return result;
});
if (isMacintosh && result.osx) {
Object.keys(result.osx).forEach(key => {
result[key] = result.osx[key];
});
}
if (isLinux && result.linux) {
Object.keys(result.linux).forEach(key => {
result[key] = result.linux[key];
});
}
// massage configuration attributes - append workspace path to relatvie paths, substitute variables in paths.
Object.keys(result).forEach(key => {
result[key] = this.configurationResolverService.resolveAny(result[key]);
});
const adapter = this.getAdapter(result.type);
return this.configurationResolverService.resolveInteractiveVariables(result, adapter ? adapter.variables : null);
}
}
public openConfigFile(sideBySide: boolean): TPromise<boolean> {
......@@ -348,8 +338,4 @@ export class ConfigurationManager implements debug.IConfigurationManager {
return !!this.allModeIdsForBreakpoints[modeId];
}
public loadLaunchConfig(): TPromise<debug.IGlobalConfig> {
return TPromise.as(this.configurationService.getConfiguration<debug.IGlobalConfig>('launch'));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册