From 1fd7873ceeddc6a15e61c5b5d363c5fbd5226963 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 12 Aug 2021 15:24:50 +0200 Subject: [PATCH] make sure to save launch config before debugging starts to have freshest content fixes #125259 --- .../contrib/debug/browser/debugCommands.ts | 4 +++- .../browser/debugConfigurationManager.ts | 2 +- .../contrib/debug/browser/debugService.ts | 19 ++++--------------- .../workbench/contrib/debug/common/debug.ts | 2 +- .../contrib/debug/common/debugUtils.ts | 17 +++++++++++++++++ 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/debugCommands.ts b/src/vs/workbench/contrib/debug/browser/debugCommands.ts index ee286f2795f..99f21a5714b 100644 --- a/src/vs/workbench/contrib/debug/browser/debugCommands.ts +++ b/src/vs/workbench/contrib/debug/browser/debugCommands.ts @@ -30,6 +30,7 @@ import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; import { IViewsService } from 'vs/workbench/common/views'; import { deepClone } from 'vs/base/common/objects'; import { isWeb, isWindows } from 'vs/base/common/platform'; +import { saveAllBeforeDebugStart } from 'vs/workbench/contrib/debug/common/debugUtils'; export const ADD_CONFIGURATION_ID = 'debug.addConfiguration'; export const TOGGLE_INLINE_BREAKPOINT_ID = 'editor.debug.action.toggleInlineBreakpoint'; @@ -421,10 +422,11 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUG_STATE.isEqualTo('inactive')), handler: async (accessor: ServicesAccessor, debugStartOptions?: { config?: Partial; noDebug?: boolean }) => { const debugService = accessor.get(IDebugService); + await saveAllBeforeDebugStart(accessor.get(IConfigurationService), accessor.get(IEditorService)); let { 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 }); + await debugService.startDebugging(launch, configOrName, { noDebug: debugStartOptions?.noDebug }, false); } }); diff --git a/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts b/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts index 5570ee9fa99..6a179d201fe 100644 --- a/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts +++ b/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts @@ -371,7 +371,7 @@ export class ConfigurationManager implements IConfigurationManager { } const names = launch ? launch.getConfigurationNames() : []; - this.getSelectedConfig = () => Promise.resolve(config); + this.getSelectedConfig = () => Promise.resolve(this.selectedName ? launch?.getConfiguration(this.selectedName) : undefined); let type = config?.type; if (name && names.indexOf(name) >= 0) { this.setSelectedLaunchName(name); diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index f64a81779dc..e9d5200f4cf 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -31,7 +31,7 @@ import { deepClone, equals } from 'vs/base/common/objects'; import { DebugSession } from 'vs/workbench/contrib/debug/browser/debugSession'; import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import { IDebugService, State, IDebugSession, CONTEXT_DEBUG_TYPE, CONTEXT_DEBUG_STATE, CONTEXT_IN_DEBUG_MODE, IThread, IDebugConfiguration, VIEWLET_ID, IConfig, ILaunch, IViewModel, IConfigurationManager, IDebugModel, IEnablement, IBreakpoint, IBreakpointData, ICompound, IStackFrame, getStateLabel, IDebugSessionOptions, CONTEXT_DEBUG_UX, REPL_VIEW_ID, CONTEXT_BREAKPOINTS_EXIST, IGlobalConfig, CALLSTACK_VIEW_ID, IAdapterManager, IExceptionBreakpoint, CONTEXT_DISASSEMBLY_VIEW_FOCUS } from 'vs/workbench/contrib/debug/common/debug'; -import { getExtensionHostDebugSession } from 'vs/workbench/contrib/debug/common/debugUtils'; +import { getExtensionHostDebugSession, saveAllBeforeDebugStart } from 'vs/workbench/contrib/debug/common/debugUtils'; import { raceTimeout, RunOnceScheduler } from 'vs/base/common/async'; import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug'; import { isCodeEditor } from 'vs/editor/browser/editorBrowser'; @@ -301,7 +301,7 @@ 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): Promise { + async startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions, saveBeforeStart = !options?.parentSession): Promise { 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) { @@ -311,20 +311,9 @@ export class DebugService implements IDebugService { try { // make sure to save all files and that the configuration is up to date await this.extensionService.activateByEvent('onDebug'); - if (!options?.parentSession) { - const saveBeforeStartConfig: string = this.configurationService.getValue('debug.saveBeforeStart', { overrideIdentifier: this.editorService.activeTextEditorMode }); - if (saveBeforeStartConfig !== 'none') { - await this.editorService.saveAll(); - if (saveBeforeStartConfig === 'allEditorsInActiveGroup') { - const activeEditor = this.editorService.activeEditorPane; - if (activeEditor) { - // Make sure to save the active editor in case it is in untitled file it wont be saved as part of saveAll #111850 - await this.editorService.save({ editor: activeEditor.input, groupId: activeEditor.group.id }); - } - } - } + if (saveBeforeStart) { + await saveAllBeforeDebugStart(this.configurationService, this.editorService); } - await this.configurationService.reloadConfiguration(launch ? launch.workspace : undefined); await this.extensionService.whenInstalledExtensionsRegistered(); let config: IConfig | undefined; diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index 4397702f9d8..c585d8131aa 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -961,7 +961,7 @@ export interface IDebugService { * Returns true if the start debugging was successfull. For compound launches, all configurations have to start successfuly 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): Promise; + startDebugging(launch: ILaunch | undefined, configOrName?: IConfig | string, options?: IDebugSessionOptions, saveBeforeStart?: boolean): Promise; /** * Restarts a session or creates a new one if there is no active session. diff --git a/src/vs/workbench/contrib/debug/common/debugUtils.ts b/src/vs/workbench/contrib/debug/common/debugUtils.ts index c7ee9b0c9fc..7805552de35 100644 --- a/src/vs/workbench/contrib/debug/common/debugUtils.ts +++ b/src/vs/workbench/contrib/debug/common/debugUtils.ts @@ -9,6 +9,8 @@ import { URI as uri } from 'vs/base/common/uri'; import { isAbsolute } from 'vs/base/common/path'; import { deepClone } from 'vs/base/common/objects'; import { Schemas } from 'vs/base/common/network'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; const _formatPIIRegexp = /{([^}]+)}/g; @@ -303,3 +305,18 @@ function compareOrders(first: number | undefined, second: number | undefined): n return first - second; } + +export async function saveAllBeforeDebugStart(configurationService: IConfigurationService, editorService: IEditorService): Promise { + const saveBeforeStartConfig: string = configurationService.getValue('debug.saveBeforeStart', { overrideIdentifier: editorService.activeTextEditorMode }); + if (saveBeforeStartConfig !== 'none') { + await editorService.saveAll(); + if (saveBeforeStartConfig === 'allEditorsInActiveGroup') { + const activeEditor = editorService.activeEditorPane; + if (activeEditor) { + // Make sure to save the active editor in case it is in untitled file it wont be saved as part of saveAll #111850 + await editorService.save({ editor: activeEditor.input, groupId: activeEditor.group.id }); + } + } + } + await configurationService.reloadConfiguration(); +}