Skip to content

Commit 6008c13

Browse files
committed
warn the user if they try to do run without debugging in unsupported scenarios
1 parent de0e20c commit 6008c13

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

Extension/src/Debugger/debugAdapterDescriptorFactory.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as os from 'os';
77
import * as path from 'path';
88
import * as vscode from "vscode";
99
import * as nls from 'vscode-nls';
10+
import { getOutputChannel } from '../logger';
1011
import { RunWithoutDebuggingAdapter } from './runWithoutDebuggingAdapter';
1112

1213
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
@@ -27,10 +28,13 @@ abstract class AbstractDebugAdapterDescriptorFactory implements vscode.DebugAdap
2728
}
2829

2930
export class CppdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
30-
3131
async createDebugAdapterDescriptor(session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor> {
3232
if (session.configuration.noDebug) {
33-
return new vscode.DebugAdapterInlineImplementation(new RunWithoutDebuggingAdapter());
33+
if (noDebugSupported(session.configuration)) {
34+
return new vscode.DebugAdapterInlineImplementation(new RunWithoutDebuggingAdapter());
35+
}
36+
// If the configuration is not supported, gracefully fall back to a regular debug session and log a message to the user.
37+
logReasonForNoDebugNotSupported(session.configuration);
3438
}
3539

3640
const adapter: string = "./debugAdapters/bin/OpenDebugAD7" + (os.platform() === 'win32' ? ".exe" : "");
@@ -42,10 +46,13 @@ export class CppdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDes
4246
}
4347

4448
export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
45-
4649
async createDebugAdapterDescriptor(session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor | null> {
4750
if (session.configuration.noDebug) {
48-
return new vscode.DebugAdapterInlineImplementation(new RunWithoutDebuggingAdapter());
51+
if (noDebugSupported(session.configuration)) {
52+
return new vscode.DebugAdapterInlineImplementation(new RunWithoutDebuggingAdapter());
53+
}
54+
// If the configuration is not supported, gracefully fall back to a regular debug session and log a message to the user.
55+
logReasonForNoDebugNotSupported(session.configuration);
4956
}
5057

5158
if (os.platform() !== 'win32') {
@@ -59,3 +66,28 @@ export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterD
5966
}
6067
}
6168
}
69+
70+
function noDebugSupported(configuration: vscode.DebugConfiguration): boolean {
71+
// Don't attempt to start a noDebug session if the configuration has any of these properties, which require a debug adapter to function.
72+
return configuration.request === 'launch' && !configuration.pipeTransport && !configuration.debugServerPath && !configuration.miDebuggerServerAddress && !configuration.coreDumpPath;
73+
}
74+
75+
function logReasonForNoDebugNotSupported(configuration: vscode.DebugConfiguration): void {
76+
const outputChannel = getOutputChannel();
77+
if (configuration.request !== 'launch') {
78+
outputChannel.appendLine(localize("debugger.noDebug.requestType.not.supported", "Run Without Debugging is only supported for launch configurations."));
79+
}
80+
if (configuration.pipeTransport) {
81+
outputChannel.appendLine(localize("debugger.noDebug.pipeTransport.not.supported", "Run Without Debugging is not supported for configurations with 'pipeTransport' set."));
82+
}
83+
if (configuration.debugServerPath) {
84+
outputChannel.appendLine(localize("debugger.noDebug.debugServerPath.not.supported", "Run Without Debugging is not supported for configurations with 'debugServerPath' set."));
85+
}
86+
if (configuration.miDebuggerServerAddress) {
87+
outputChannel.appendLine(localize("debugger.noDebug.miDebuggerServerAddress.not.supported", "Run Without Debugging is not supported for configurations with 'miDebuggerServerAddress' set."));
88+
}
89+
if (configuration.coreDumpPath) {
90+
outputChannel.appendLine(localize("debugger.noDebug.coreDumpPath.not.supported", "Run Without Debugging is not supported for configurations with 'coreDumpPath' set."));
91+
}
92+
outputChannel.show(true);
93+
}

0 commit comments

Comments
 (0)