diff --git a/src/vs/workbench/api/browser/mainThreadDebugService.ts b/src/vs/workbench/api/browser/mainThreadDebugService.ts index c0ec9d1b550..1b0e0389246 100644 --- a/src/vs/workbench/api/browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/browser/mainThreadDebugService.ts @@ -223,6 +223,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb const folderUri = folder ? uri.revive(folder) : undefined; const launch = this.debugService.getConfigurationManager().getLaunch(folderUri); const parentSession = this.getSession(options.parentSessionID); + const saveBeforeStart = typeof options.suppressSaveBeforeStart === 'boolean' ? !options.suppressSaveBeforeStart : undefined; const debugOptions: IDebugSessionOptions = { noDebug: options.noDebug, parentSession, @@ -230,11 +231,11 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb repl: options.repl, compact: options.compact, debugUI: options.debugUI, - compoundRoot: parentSession?.compoundRoot + compoundRoot: parentSession?.compoundRoot, + saveBeforeStart: saveBeforeStart }; try { - const saveBeforeStart = typeof options.suppressSaveBeforeStart === 'boolean' ? !options.suppressSaveBeforeStart : undefined; - return this.debugService.startDebugging(launch, nameOrConfig, debugOptions, saveBeforeStart); + return this.debugService.startDebugging(launch, nameOrConfig, debugOptions); } catch (err) { throw new ErrorNoTelemetry(err && err.message ? err.message : 'cannot start debugging'); } diff --git a/src/vs/workbench/contrib/debug/browser/debugCommands.ts b/src/vs/workbench/contrib/debug/browser/debugCommands.ts index 25da3464ac6..596bbd9c32d 100644 --- a/src/vs/workbench/contrib/debug/browser/debugCommands.ts +++ b/src/vs/workbench/contrib/debug/browser/debugCommands.ts @@ -723,7 +723,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ const { launch, name, getConfig } = debugService.getConfigurationManager().selectedConfiguration; const config = await getConfig(); const configOrName = config ? Object.assign(deepClone(config), debugStartOptions?.config) : name; - await debugService.startDebugging(launch, configOrName, { noDebug: debugStartOptions?.noDebug, startedByUser: true }, false); + await debugService.startDebugging(launch, configOrName, { noDebug: debugStartOptions?.noDebug, startedByUser: true, saveBeforeStart: false }); } }); diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index b308716a8bb..2474922a5ad 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -312,7 +312,10 @@ export class DebugService implements IDebugService { * main entry point * properly manages compounds, checks for errors and handles the initializing state. */ - async startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions, saveBeforeStart = !options?.parentSession): Promise { + async startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions): Promise { + + const saveBeforeStart = options?.saveBeforeStart ?? !options?.parentSession; + const message = options && options.noDebug ? nls.localize('runTrust', "Running executes build tasks and program code from your workspace.") : nls.localize('debugTrust', "Debugging executes build tasks and program code from your workspace."); const trust = await this.workspaceTrustRequestService.requestWorkspaceTrust({ message }); if (!trust) { @@ -701,7 +704,10 @@ export class DebugService implements IDebugService { } async restartSession(session: IDebugSession, restartData?: any): Promise { - await this.editorService.saveAll(); + if (session.saveBeforeStart) { + await saveAllBeforeDebugStart(this.configurationService, this.editorService); + } + const isAutoRestart = !!restartData; const runTasks: () => Promise = async () => { diff --git a/src/vs/workbench/contrib/debug/browser/debugSession.ts b/src/vs/workbench/contrib/debug/browser/debugSession.ts index de26f713ef0..29a568d478b 100644 --- a/src/vs/workbench/contrib/debug/browser/debugSession.ts +++ b/src/vs/workbench/contrib/debug/browser/debugSession.ts @@ -164,6 +164,10 @@ export class DebugSession implements IDebugSession { return !!this._options.compact; } + get saveBeforeStart(): boolean { + return this._options.saveBeforeStart ?? !this._options?.parentSession; + } + get compoundRoot(): DebugCompoundRoot | undefined { return this._options.compoundRoot; } diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index a8397f69aef..21dc92d475c 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -206,6 +206,7 @@ export interface IDebugSessionOptions { simple?: boolean; }; startedByUser?: boolean; + saveBeforeStart?: boolean; } export interface IDataBreakpointInfoResponse { @@ -296,6 +297,7 @@ export interface IDebugSession extends ITreeElement { readonly subId: string | undefined; readonly compact: boolean; readonly compoundRoot: DebugCompoundRoot | undefined; + readonly saveBeforeStart: boolean; readonly name: string; readonly isSimpleUI: boolean; readonly autoExpandLazyVariables: boolean; @@ -1088,7 +1090,7 @@ export interface IDebugService { * Returns true if the start debugging was successful. For compound launches, all configurations have to start successfully for it to return success. * On errors the startDebugging will throw an error, however some error and cancelations are handled and in that case will simply return false. */ - startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions, saveBeforeStart?: boolean): Promise; + startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions): Promise; /** * Restarts a session or creates a new one if there is no active session. diff --git a/src/vs/workbench/contrib/debug/test/browser/mockDebug.ts b/src/vs/workbench/contrib/debug/test/browser/mockDebug.ts index 1bebaa31adb..1596e346e31 100644 --- a/src/vs/workbench/contrib/debug/test/browser/mockDebug.ts +++ b/src/vs/workbench/contrib/debug/test/browser/mockDebug.ts @@ -190,6 +190,10 @@ export class MockSession implements IDebugSession { return undefined; } + get saveBeforeStart(): boolean { + return true; + } + get isSimpleUI(): boolean { return false; }