Skip to content

Commit e624120

Browse files
committed
use fileToCommandArgumentForPythonExt and add test
1 parent 5955540 commit e624120

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/extension/debugger/adapter/factory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Commands, EXTENSION_ROOT_DIR } from '../../common/constants';
2525
import { Common, DebugConfigStrings, Interpreters } from '../../common/utils/localize';
2626
import { IPersistentStateFactory } from '../../common/types';
2727
import { ResolvedEnvironment } from '@vscode/python-extension';
28+
import { fileToCommandArgumentForPythonExt } from '../../common/stringUtils';
2829

2930
// persistent state names, exported to make use of in testing
3031
export enum debugStateKeys {
@@ -85,7 +86,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
8586
if (configuration.debugAdapterPath !== undefined) {
8687
const args = command.concat([configuration.debugAdapterPath, ...logArgs]);
8788
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
88-
executable = `"${executable}"`; // surround executable with quotes to handle spaces
89+
executable = fileToCommandArgumentForPythonExt(executable);
8990
return new DebugAdapterExecutable(executable, args);
9091
}
9192

src/test/unittest/adapter/factory.unit.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ suite('Debugging - Adapter Factory', () => {
4141

4242
const nodeExecutable = undefined;
4343
const debugAdapterPath = path.join(EXTENSION_ROOT_DIR, 'bundled', 'libs', 'debugpy', 'adapter');
44-
const pythonPath = path.join('path', 'to', 'python', 'interpreter');
44+
const pythonPath = path.join('path', 'to', 'pythonA', 'interpreter');
4545
const interpreter = {
4646
architecture: Architecture.Unknown,
4747
path: pythonPath,
@@ -291,6 +291,27 @@ suite('Debugging - Adapter Factory', () => {
291291

292292
assert.deepStrictEqual(descriptor, debugExecutable);
293293
});
294+
test('Add quotes to interpreter path with spaces', async () => {
295+
const customAdapterPath = 'custom/debug/adapter/customAdapterPath';
296+
const session = createSession({ debugAdapterPath: customAdapterPath });
297+
const interpreterPathSpaces = '/path/to/python interpreter with spaces';
298+
const interpreterPathSpacesQuoted = `"${interpreterPathSpaces}"`;
299+
const debugExecutable = new DebugAdapterExecutable(interpreterPathSpacesQuoted, [customAdapterPath]);
300+
301+
getInterpreterDetailsStub.resolves({ path: [interpreterPathSpaces] });
302+
const interpreterSpacePath = {
303+
architecture: Architecture.Unknown,
304+
path: interpreterPathSpaces,
305+
sysPrefix: '',
306+
sysVersion: '',
307+
envType: 'Unknow',
308+
version: new SemVer('3.7.4-test'),
309+
};
310+
resolveEnvironmentStub.withArgs(interpreterPathSpaces).resolves(interpreterSpacePath);
311+
const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable);
312+
313+
assert.deepStrictEqual(descriptor, debugExecutable);
314+
});
294315

295316
test('Use "debugAdapterPython" when specified', async () => {
296317
const session = createSession({ debugAdapterPython: '/bin/custompy' });

0 commit comments

Comments
 (0)