Skip to content

Commit 522e914

Browse files
Gracefully fail when trying to debug an Untitled file using Temp debugging because it's not supported (#2458)
1 parent cc9ce31 commit 522e914

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/features/DebugSession.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
145145
const generateLaunchConfig = !config.request;
146146

147147
const settings = Settings.load();
148-
let createNewIntegratedConsole = settings.debugging.createTemporaryIntegratedConsole;
148+
149+
// If the createTemporaryIntegratedConsole field is not specified in the launch config, set the field using
150+
// the value from the corresponding setting. Otherwise, the launch config value overrides the setting.
151+
if (config.createTemporaryIntegratedConsole === undefined) {
152+
config.createTemporaryIntegratedConsole = settings.debugging.createTemporaryIntegratedConsole;
153+
}
149154

150155
if (config.request === "attach") {
151156
const platformDetails = getPlatformDetails();
@@ -192,7 +197,7 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
192197
? currentDocument.uri.toString()
193198
: currentDocument.fileName;
194199

195-
if (settings.debugging.createTemporaryIntegratedConsole) {
200+
if (config.createTemporaryIntegratedConsole) {
196201
// For a folder-less workspace, vscode.workspace.rootPath will be undefined.
197202
// PSES will convert that undefined to a reasonable working dir.
198203
config.cwd =
@@ -222,6 +227,12 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
222227
}
223228

224229
if (currentDocument.isUntitled) {
230+
if (config.createTemporaryIntegratedConsole) {
231+
const msg = "Debugging Untitled files in a temporary console is currently not supported.";
232+
vscode.window.showErrorMessage(msg);
233+
return;
234+
}
235+
225236
if (currentDocument.languageId === "powershell") {
226237
if (!generateLaunchConfig) {
227238
// Cover the case of existing launch.json but unsaved (Untitled) document.
@@ -264,14 +275,6 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
264275
if ((currentDocument !== undefined) && (config.cwd === "${file}")) {
265276
config.cwd = currentDocument.fileName;
266277
}
267-
268-
// If the createTemporaryIntegratedConsole field is not specified in the launch config, set the field using
269-
// the value from the corresponding setting. Otherwise, the launch config value overrides the setting.
270-
if (config.createTemporaryIntegratedConsole === undefined) {
271-
config.createTemporaryIntegratedConsole = createNewIntegratedConsole;
272-
} else {
273-
createNewIntegratedConsole = config.createTemporaryIntegratedConsole;
274-
}
275278
}
276279

277280
// Prevent the Debug Console from opening
@@ -282,7 +285,7 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
282285

283286
const sessionFilePath = utils.getDebugSessionFilePath();
284287

285-
if (createNewIntegratedConsole) {
288+
if (config.createTemporaryIntegratedConsole) {
286289
if (this.tempDebugProcess) {
287290
this.tempDebugProcess.dispose();
288291
}

0 commit comments

Comments
 (0)