提交 929a29e5 编写于 作者: I isidor

debug: no folder debugging

fixes #285
上级 cebddf21
......@@ -11,7 +11,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IDebugService, State, IProcess, SessionRequestType, IThread, IEnablement, IBreakpoint, IStackFrame, IFunctionBreakpoint, IDebugEditorContribution, EDITOR_CONTRIBUTION_ID, IExpression, REPL_ID }
import { IDebugService, State, IProcess, SessionRequestType, IThread, IEnablement, IBreakpoint, IStackFrame, IFunctionBreakpoint, IDebugEditorContribution, EDITOR_CONTRIBUTION_ID, IExpression, REPL_ID, IConfig }
from 'vs/workbench/parts/debug/common/debug';
import { Variable, Expression, Thread, Breakpoint, Process } from 'vs/workbench/parts/debug/common/debugModel';
import { IPartService } from 'vs/workbench/services/part/common/partService';
......@@ -92,11 +92,11 @@ export class ConfigureAction extends AbstractDebugAction {
this.class = this.debugService.getViewModel().selectedConfigurationName ? 'debug-action configure' : 'debug-action configure notification';
}
protected isEnabled(): boolean {
return !!this.contextService.getWorkspace();
}
public run(event?: any): TPromise<any> {
if (!this.contextService.getWorkspace()) {
return TPromise.as(null);
}
const sideBySide = !!(event && (event.ctrlKey || event.metaKey));
return this.debugService.getConfigurationManager().openConfigFile(sideBySide);
}
......@@ -106,7 +106,12 @@ export class StartAction extends AbstractDebugAction {
static ID = 'workbench.action.debug.start';
static LABEL = nls.localize('startDebug', "Start Debugging");
constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService, @ICommandService private commandService: ICommandService) {
constructor(id: string, label: string,
@IDebugService debugService: IDebugService,
@IKeybindingService keybindingService: IKeybindingService,
@ICommandService private commandService: ICommandService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label, 'debug-action start', debugService, keybindingService);
this.debugService.getViewModel().onDidSelectConfiguration(() => {
this.updateEnablement();
......@@ -114,7 +119,19 @@ export class StartAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
return this.commandService.executeCommand('_workbench.startDebug', this.debugService.getViewModel().selectedConfigurationName);
const manager = this.debugService.getConfigurationManager();
const configName = this.debugService.getViewModel().selectedConfigurationName;
const configurationPromise: TPromise<IConfig> = configName && this.contextService.getWorkspace() ?
manager.getConfiguration(configName) : TPromise.as(null);
return configurationPromise.then(configuration => {
const command = manager.getStartSessionCommand(configuration ? configuration.type : undefined);
if (command) {
return this.commandService.executeCommand(command, configuration || { request: 'launch' });
}
return this.commandService.executeCommand('_workbench.startDebug', configName);
});
}
// Disabled if the launch drop down shows the launch config that is already running.
......@@ -691,15 +708,33 @@ export class RunAction extends AbstractDebugAction {
static ID = 'workbench.action.debug.run';
static LABEL = nls.localize('startWithoutDebugging', "Start Without Debugging");
constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) {
constructor(id: string, label: string,
@IDebugService debugService: IDebugService,
@IKeybindingService keybindingService: IKeybindingService,
@ICommandService private commandService: ICommandService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label, null, debugService, keybindingService);
}
public run(): TPromise<any> {
return this.debugService.getConfigurationManager().getConfiguration(this.debugService.getViewModel().selectedConfigurationName).then(configuration => {
const manager = this.debugService.getConfigurationManager();
const configName = this.debugService.getViewModel().selectedConfigurationName;
const configurationPromise: TPromise<IConfig> = configName && this.contextService.getWorkspace() ?
manager.getConfiguration(configName) : TPromise.as(null);
return configurationPromise.then(configuration => {
const command = manager.getStartSessionCommand(configuration ? configuration.type : undefined);
if (command) {
return this.commandService.executeCommand(command, configuration || {
request: 'launch',
noDebug: true
});
}
if (configuration) {
configuration.noDebug = true;
return this.debugService.createProcess(configuration);
return this.commandService.executeCommand('_workbench.startDebug', configuration);
}
});
}
......
......@@ -319,6 +319,8 @@ export interface IRawAdapter extends IRawEnvAdapter {
configurationAttributes?: any;
configurationSnippets?: IJSONSchemaSnippet[];
initialConfigurations?: any[] | string;
startSessionCommand?: string;
languages?: string[];
variables?: { [key: string]: string };
aiKey?: string;
win?: IRawEnvAdapter;
......@@ -357,6 +359,13 @@ export interface IConfigurationManager {
* Returns true if breakpoints can be set for a given editor model. Depends on mode.
*/
canSetBreakpointsIn(model: EditorIModel): boolean;
/**
* Returns a "startSessionCommand" contribution for an adapter with the passed type.
* If no type is specified will try to automatically pick an adapter by looking at
* the active editor language and matching it against the "languages" contribution of an adapter.
*/
getStartSessionCommand(type?: string): string;
}
// Debug service interfaces
......
......@@ -134,12 +134,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
handler(accessor: ServicesAccessor, configurationOrName: any) {
const debugService = accessor.get(IDebugService);
if (!configurationOrName) {
const viewModel = debugService.getViewModel();
if (!viewModel.selectedConfigurationName) {
const name = debugService.getConfigurationManager().getConfigurationNames().shift();
viewModel.setSelectedConfigurationName(name);
}
configurationOrName = viewModel.selectedConfigurationName;
configurationOrName = debugService.getViewModel().selectedConfigurationName;
}
return debugService.createProcess(configurationOrName);
......
......@@ -13,7 +13,7 @@ import uri from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import * as paths from 'vs/base/common/paths';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { IModel } from 'vs/editor/common/editorCommon';
import { IModel, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import * as extensionsRegistry from 'vs/platform/extensions/common/extensionsRegistry';
import { Registry } from 'vs/platform/platform';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
......@@ -71,6 +71,14 @@ export const debuggersExtPoint = extensionsRegistry.ExtensionsRegistry.registerE
description: nls.localize('vscode.extension.contributes.debuggers.initialConfigurations', "Configurations for generating the initial \'launch.json\'."),
type: ['array', 'string'],
},
languages: {
description: nls.localize('vscode.extension.contributes.debuggers.languages', "List of languages for which the debug extension could be considered the \"default debugger\"."),
type: 'array'
},
startSessionCommand: {
description: nls.localize('vscode.extension.contributes.debuggers.startSessionCommand', "If specified VS Code will call this command for the \"debug\" or \"run\" actions targeted for this extension."),
type: 'string'
},
configurationSnippets: {
description: nls.localize('vscode.extension.contributes.debuggers.configurationSnippets', "Snippets for adding new configurations in \'launch.json\'."),
type: 'array'
......@@ -307,6 +315,10 @@ export class ConfigurationManager implements debug.IConfigurationManager {
result = objects.deepClone(filtered[0]);
}
if (!this.contextService.getWorkspace()) {
return TPromise.as(result);
}
// Set operating system specific properties #1873
const setOSProperties = (flag: boolean, osConfig: debug.IEnvConfig) => {
if (flag && osConfig) {
......@@ -375,6 +387,27 @@ export class ConfigurationManager implements debug.IConfigurationManager {
});
}
public getStartSessionCommand(type?: string): string {
if (type) {
const adapter = this.adapters.filter(a => a.type === type).pop();
if (adapter) {
return adapter.startSessionCommand;
}
} else {
const editor = this.editorService.getActiveEditor();
if (editor) {
const model = (<ICommonCodeEditor>editor.getControl()).getModel();
const language = model ? model.getLanguageIdentifier().language : undefined;
const adapter = this.adapters.filter(a => a.languages && a.languages.indexOf(language) >= 0).pop();
if (adapter) {
return adapter.startSessionCommand;
}
}
}
return undefined;
}
public canSetBreakpointsIn(model: IModel): boolean {
if (model.uri.scheme === Schemas.inMemory) {
return false;
......
......@@ -131,7 +131,7 @@ export class DebugService implements debug.IDebugService {
this.toDispose.push(this.windowService.onBroadcast(this.onBroadcast, this));
this.toDispose.push(this.configurationService.onDidUpdateConfiguration((event) => {
if (event.sourceConfig.launch) {
if (event.sourceConfig) {
const names = this.configurationManager.getConfigurationNames();
if (names.every(name => name !== this.viewModel.selectedConfigurationName)) {
// Current selected configuration no longer exists - take the first configuration instead.
......@@ -610,6 +610,10 @@ export class DebugService implements debug.IDebugService {
});
});
}, err => {
if (!this.contextService.getWorkspace()) {
return this.messageService.show(severity.Error, nls.localize('noFolderWorkspaceDebugError', "The active file can not be debugged. Make sure it is saved on disk and that you have a debug extension installed for that file type."));
}
return this.configurationManager.openConfigFile(false).then(openend => {
if (openend) {
this.messageService.show(severity.Info, nls.localize('NewLaunchConfig', "Please set up the launch configuration file for your application. {0}", err.message));
......
......@@ -76,6 +76,14 @@ export class Adapter {
return this.rawAdapter.configurationSnippets;
}
public get languages(): string[] {
return this.rawAdapter.languages;
}
public get startSessionCommand(): string {
return this.rawAdapter.startSessionCommand;
}
public merge(secondRawAdapter: IRawAdapter, extensionDescription: IExtensionDescription): void {
// Give priority to built in debug adapters
if (extensionDescription.isBuiltin) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册