Skip to content

Commit 368400c

Browse files
authored
Check save settings before debug restart (microsoft#154206)
* Fix bug: Files automatically saved when restarting debugger, even though it is set not to Fixes microsoft#149885
1 parent 1cc52ae commit 368400c

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

src/vs/workbench/api/browser/mainThreadDebugService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,19 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
223223
const folderUri = folder ? uri.revive(folder) : undefined;
224224
const launch = this.debugService.getConfigurationManager().getLaunch(folderUri);
225225
const parentSession = this.getSession(options.parentSessionID);
226+
const saveBeforeStart = typeof options.suppressSaveBeforeStart === 'boolean' ? !options.suppressSaveBeforeStart : undefined;
226227
const debugOptions: IDebugSessionOptions = {
227228
noDebug: options.noDebug,
228229
parentSession,
229230
lifecycleManagedByParent: options.lifecycleManagedByParent,
230231
repl: options.repl,
231232
compact: options.compact,
232233
debugUI: options.debugUI,
233-
compoundRoot: parentSession?.compoundRoot
234+
compoundRoot: parentSession?.compoundRoot,
235+
saveBeforeStart: saveBeforeStart
234236
};
235237
try {
236-
const saveBeforeStart = typeof options.suppressSaveBeforeStart === 'boolean' ? !options.suppressSaveBeforeStart : undefined;
237-
return this.debugService.startDebugging(launch, nameOrConfig, debugOptions, saveBeforeStart);
238+
return this.debugService.startDebugging(launch, nameOrConfig, debugOptions);
238239
} catch (err) {
239240
throw new ErrorNoTelemetry(err && err.message ? err.message : 'cannot start debugging');
240241
}

src/vs/workbench/contrib/debug/browser/debugCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
723723
const { launch, name, getConfig } = debugService.getConfigurationManager().selectedConfiguration;
724724
const config = await getConfig();
725725
const configOrName = config ? Object.assign(deepClone(config), debugStartOptions?.config) : name;
726-
await debugService.startDebugging(launch, configOrName, { noDebug: debugStartOptions?.noDebug, startedByUser: true }, false);
726+
await debugService.startDebugging(launch, configOrName, { noDebug: debugStartOptions?.noDebug, startedByUser: true, saveBeforeStart: false });
727727
}
728728
});
729729

src/vs/workbench/contrib/debug/browser/debugService.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ export class DebugService implements IDebugService {
312312
* main entry point
313313
* properly manages compounds, checks for errors and handles the initializing state.
314314
*/
315-
async startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions, saveBeforeStart = !options?.parentSession): Promise<boolean> {
315+
async startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions): Promise<boolean> {
316+
317+
const saveBeforeStart = options?.saveBeforeStart ?? !options?.parentSession;
318+
316319
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.");
317320
const trust = await this.workspaceTrustRequestService.requestWorkspaceTrust({ message });
318321
if (!trust) {
@@ -701,7 +704,10 @@ export class DebugService implements IDebugService {
701704
}
702705

703706
async restartSession(session: IDebugSession, restartData?: any): Promise<any> {
704-
await this.editorService.saveAll();
707+
if (session.saveBeforeStart) {
708+
await saveAllBeforeDebugStart(this.configurationService, this.editorService);
709+
}
710+
705711
const isAutoRestart = !!restartData;
706712

707713
const runTasks: () => Promise<TaskRunResult> = async () => {

src/vs/workbench/contrib/debug/browser/debugSession.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ export class DebugSession implements IDebugSession {
164164
return !!this._options.compact;
165165
}
166166

167+
get saveBeforeStart(): boolean {
168+
return this._options.saveBeforeStart ?? !this._options?.parentSession;
169+
}
170+
167171
get compoundRoot(): DebugCompoundRoot | undefined {
168172
return this._options.compoundRoot;
169173
}

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export interface IDebugSessionOptions {
206206
simple?: boolean;
207207
};
208208
startedByUser?: boolean;
209+
saveBeforeStart?: boolean;
209210
}
210211

211212
export interface IDataBreakpointInfoResponse {
@@ -296,6 +297,7 @@ export interface IDebugSession extends ITreeElement {
296297
readonly subId: string | undefined;
297298
readonly compact: boolean;
298299
readonly compoundRoot: DebugCompoundRoot | undefined;
300+
readonly saveBeforeStart: boolean;
299301
readonly name: string;
300302
readonly isSimpleUI: boolean;
301303
readonly autoExpandLazyVariables: boolean;
@@ -1088,7 +1090,7 @@ export interface IDebugService {
10881090
* Returns true if the start debugging was successful. For compound launches, all configurations have to start successfully for it to return success.
10891091
* On errors the startDebugging will throw an error, however some error and cancelations are handled and in that case will simply return false.
10901092
*/
1091-
startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions, saveBeforeStart?: boolean): Promise<boolean>;
1093+
startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions): Promise<boolean>;
10921094

10931095
/**
10941096
* Restarts a session or creates a new one if there is no active session.

src/vs/workbench/contrib/debug/test/browser/mockDebug.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ export class MockSession implements IDebugSession {
190190
return undefined;
191191
}
192192

193+
get saveBeforeStart(): boolean {
194+
return true;
195+
}
196+
193197
get isSimpleUI(): boolean {
194198
return false;
195199
}

0 commit comments

Comments
 (0)