提交 c1bed7af 编写于 作者: J jeanp413

Address feedback

上级 35fe5974
...@@ -82,7 +82,7 @@ export class ConfigureAction extends AbstractDebugAction { ...@@ -82,7 +82,7 @@ export class ConfigureAction extends AbstractDebugAction {
} }
async run(event?: any): Promise<any> { async run(event?: any): Promise<any> {
if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) { if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY || this.contextService.getWorkspace().folders.length === 0) {
this.notificationService.info(nls.localize('noFolderDebugConfig', "Please first open a folder in order to do advanced debug configuration.")); this.notificationService.info(nls.localize('noFolderDebugConfig', "Please first open a folder in order to do advanced debug configuration."));
return; return;
} }
...@@ -97,7 +97,7 @@ export class ConfigureAction extends AbstractDebugAction { ...@@ -97,7 +97,7 @@ export class ConfigureAction extends AbstractDebugAction {
launch = launches[0]; launch = launches[0];
} else { } else {
const picks = launches.map(l => ({ label: l.name, launch: l })); const picks = launches.map(l => ({ label: l.name, launch: l }));
const picked = await this.quickInputService.pick<{ label: string, launch: ILaunch }>(picks, { activeItem: picks[0], placeHolder: nls.localize('selectWorkspaceFolder', "Select a workspace folder to create a launch.json file in") }); const picked = await this.quickInputService.pick<{ label: string, launch: ILaunch }>(picks, { activeItem: picks[0], placeHolder: nls.localize('selectWorkspaceFolder', "Select a workspace folder to create a launch.json file in or add it to the workspace config file") });
if (picked) { if (picked) {
launch = picked.launch; launch = picked.launch;
} }
......
...@@ -388,7 +388,7 @@ export class ConfigurationManager implements IConfigurationManager { ...@@ -388,7 +388,7 @@ export class ConfigurationManager implements IConfigurationManager {
if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) { if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) {
this.launches.push(this.instantiationService.createInstance(WorkspaceLaunch, this)); this.launches.push(this.instantiationService.createInstance(WorkspaceLaunch, this));
} }
this.launches.push(this.instantiationService.createInstance(UserLaunch)); this.launches.push(this.instantiationService.createInstance(UserLaunch, this));
if (this.selectedLaunch && this.launches.indexOf(this.selectedLaunch) === -1) { if (this.selectedLaunch && this.launches.indexOf(this.selectedLaunch) === -1) {
this.selectConfiguration(undefined); this.selectConfiguration(undefined);
...@@ -566,6 +566,9 @@ export class ConfigurationManager implements IConfigurationManager { ...@@ -566,6 +566,9 @@ export class ConfigurationManager implements IConfigurationManager {
abstract class AbstractLaunch { abstract class AbstractLaunch {
protected abstract getConfig(): IGlobalConfig | undefined; protected abstract getConfig(): IGlobalConfig | undefined;
constructor(protected configurationManager: ConfigurationManager) {
}
getCompound(name: string): ICompound | undefined { getCompound(name: string): ICompound | undefined {
const config = this.getConfig(); const config = this.getConfig();
if (!config || !config.compounds) { if (!config || !config.compounds) {
...@@ -606,6 +609,16 @@ abstract class AbstractLaunch { ...@@ -606,6 +609,16 @@ abstract class AbstractLaunch {
return config.configurations.find(config => config && config.name === name); return config.configurations.find(config => config && config.name === name);
} }
async getInitialConfigurationContent(folderUri?: uri, type?: string, token?: CancellationToken): Promise<string> {
let content = '';
const adapter = await this.configurationManager.guessDebugger(type);
if (adapter) {
const initialConfigs = await this.configurationManager.provideDebugConfigurations(folderUri, adapter.type, token || CancellationToken.None);
content = await adapter.getInitialConfigurationContent(initialConfigs);
}
return content;
}
get hidden(): boolean { get hidden(): boolean {
return false; return false;
} }
...@@ -614,14 +627,14 @@ abstract class AbstractLaunch { ...@@ -614,14 +627,14 @@ abstract class AbstractLaunch {
class Launch extends AbstractLaunch implements ILaunch { class Launch extends AbstractLaunch implements ILaunch {
constructor( constructor(
private configurationManager: ConfigurationManager, configurationManager: ConfigurationManager,
public workspace: IWorkspaceFolder, public workspace: IWorkspaceFolder,
@IFileService private readonly fileService: IFileService, @IFileService private readonly fileService: IFileService,
@ITextFileService private readonly textFileService: ITextFileService, @ITextFileService private readonly textFileService: ITextFileService,
@IEditorService private readonly editorService: IEditorService, @IEditorService private readonly editorService: IEditorService,
@IConfigurationService private readonly configurationService: IConfigurationService @IConfigurationService private readonly configurationService: IConfigurationService
) { ) {
super(); super(configurationManager);
} }
get uri(): uri { get uri(): uri {
...@@ -645,12 +658,7 @@ class Launch extends AbstractLaunch implements ILaunch { ...@@ -645,12 +658,7 @@ class Launch extends AbstractLaunch implements ILaunch {
content = fileContent.value.toString(); content = fileContent.value.toString();
} catch { } catch {
// launch.json not found: create one by collecting launch configs from debugConfigProviders // launch.json not found: create one by collecting launch configs from debugConfigProviders
const adapter = await this.configurationManager.guessDebugger(type); content = await this.getInitialConfigurationContent(this.workspace.uri, type, token);
if (adapter) {
const initialConfigs = await this.configurationManager.provideDebugConfigurations(this.workspace.uri, adapter.type, token || CancellationToken.None);
content = await adapter.getInitialConfigurationContent(initialConfigs);
}
if (content) { if (content) {
created = true; // pin only if config file is created #8727 created = true; // pin only if config file is created #8727
try { try {
...@@ -693,12 +701,12 @@ class Launch extends AbstractLaunch implements ILaunch { ...@@ -693,12 +701,12 @@ class Launch extends AbstractLaunch implements ILaunch {
class WorkspaceLaunch extends AbstractLaunch implements ILaunch { class WorkspaceLaunch extends AbstractLaunch implements ILaunch {
constructor( constructor(
private configurationManager: ConfigurationManager, configurationManager: ConfigurationManager,
@IEditorService private readonly editorService: IEditorService, @IEditorService private readonly editorService: IEditorService,
@IConfigurationService private readonly configurationService: IConfigurationService, @IConfigurationService private readonly configurationService: IConfigurationService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService @IWorkspaceContextService private readonly contextService: IWorkspaceContextService
) { ) {
super(); super(configurationManager);
} }
get workspace(): undefined { get workspace(): undefined {
...@@ -710,7 +718,7 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch { ...@@ -710,7 +718,7 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch {
} }
get name(): string { get name(): string {
return nls.localize('workspace', "workspace"); return nls.localize('workspace', "Workspace");
} }
protected getConfig(): IGlobalConfig | undefined { protected getConfig(): IGlobalConfig | undefined {
...@@ -718,28 +726,19 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch { ...@@ -718,28 +726,19 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch {
} }
async openConfigFile(sideBySide: boolean, preserveFocus: boolean, type?: string, token?: CancellationToken): Promise<{ editor: IEditorPane | null, created: boolean }> { async openConfigFile(sideBySide: boolean, preserveFocus: boolean, type?: string, token?: CancellationToken): Promise<{ editor: IEditorPane | null, created: boolean }> {
const ws = this.contextService.getWorkspace();
if (ws.folders.length === 0) {
return { editor: null, created: false };
}
let launchExistInFile = !!this.getConfig(); let launchExistInFile = !!this.getConfig();
if (!launchExistInFile) { if (!launchExistInFile) {
// Launch property in workspace config not found: create one by collecting launch configs from debugConfigProviders // Launch property in workspace config not found: create one by collecting launch configs from debugConfigProviders
let content = ''; let content = await this.getInitialConfigurationContent(undefined, type, token);
const adapter = await this.configurationManager.guessDebugger(type);
if (adapter) {
const initialConfigs = await this.configurationManager.provideDebugConfigurations(undefined, adapter.type, token || CancellationToken.None);
content = await adapter.getInitialConfigurationContent(initialConfigs);
}
if (content) { if (content) {
await this.configurationService.updateValue('launch', json.parse(content), ConfigurationTarget.WORKSPACE); await this.configurationService.updateValue('launch', json.parse(content), ConfigurationTarget.WORKSPACE);
} else {
return { editor: null, created: false };
} }
} }
const editor = await this.editorService.openEditor({ const editor = await this.editorService.openEditor({
resource: ws.configuration!, resource: this.contextService.getWorkspace().configuration!,
options: { preserveFocus } options: { preserveFocus }
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP); }, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
...@@ -753,10 +752,11 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch { ...@@ -753,10 +752,11 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch {
class UserLaunch extends AbstractLaunch implements ILaunch { class UserLaunch extends AbstractLaunch implements ILaunch {
constructor( constructor(
configurationManager: ConfigurationManager,
@IConfigurationService private readonly configurationService: IConfigurationService, @IConfigurationService private readonly configurationService: IConfigurationService,
@IPreferencesService private readonly preferencesService: IPreferencesService @IPreferencesService private readonly preferencesService: IPreferencesService
) { ) {
super(); super(configurationManager);
} }
get workspace(): undefined { get workspace(): undefined {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册