From b6e341e4522165092fc5a5d4c1bdc36e30275ff6 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Mon, 28 Jul 2025 11:42:26 -0700 Subject: [PATCH 1/3] add workspace folder for debugpy launch.json config --- src/client/interpreter/interpreterPathCommand.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/client/interpreter/interpreterPathCommand.ts b/src/client/interpreter/interpreterPathCommand.ts index 0dce208c9bfc..12f6756dafeb 100644 --- a/src/client/interpreter/interpreterPathCommand.ts +++ b/src/client/interpreter/interpreterPathCommand.ts @@ -4,12 +4,13 @@ 'use strict'; import { inject, injectable } from 'inversify'; -import { Uri } from 'vscode'; +import { Uri, workspace } from 'vscode'; import { IExtensionSingleActivationService } from '../activation/types'; import { Commands } from '../common/constants'; import { IDisposable, IDisposableRegistry } from '../common/types'; import { registerCommand } from '../common/vscodeApis/commandApis'; import { IInterpreterService } from './contracts'; +import { useEnvExtension } from '../envExt/api.internal'; @injectable() export class InterpreterPathCommand implements IExtensionSingleActivationService { @@ -26,7 +27,9 @@ export class InterpreterPathCommand implements IExtensionSingleActivationService ); } - public async _getSelectedInterpreterPath(args: { workspaceFolder: string } | string[]): Promise { + public async _getSelectedInterpreterPath( + args: { workspaceFolder: string; type: string } | string[], + ): Promise { // If `launch.json` is launching this command, `args.workspaceFolder` carries the workspaceFolder // If `tasks.json` is launching this command, `args[1]` carries the workspaceFolder let workspaceFolder; @@ -35,6 +38,11 @@ export class InterpreterPathCommand implements IExtensionSingleActivationService } else if (args[1]) { const [, second] = args; workspaceFolder = second; + } else if (useEnvExtension() && 'type' in args && args.type === 'debugpy') { + // If using the envsExt and the type is debugpy, we need to add the workspace folder to get the interpreter path. + if (Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) { + workspaceFolder = workspace.workspaceFolders[0].uri.fsPath; + } } else { workspaceFolder = undefined; } From cbbe400671517a264d0d3ec94f4b6cab8545235f Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Mon, 28 Jul 2025 11:50:51 -0700 Subject: [PATCH 2/3] update test --- src/test/interpreters/interpreterPathCommand.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/interpreters/interpreterPathCommand.unit.test.ts b/src/test/interpreters/interpreterPathCommand.unit.test.ts index be94be654861..fe03477c759b 100644 --- a/src/test/interpreters/interpreterPathCommand.unit.test.ts +++ b/src/test/interpreters/interpreterPathCommand.unit.test.ts @@ -43,7 +43,7 @@ suite('Interpreter Path Command', () => { }); test('If `workspaceFolder` property exists in `args`, it is used to retrieve setting from config', async () => { - const args = { workspaceFolder: 'folderPath' }; + const args = { workspaceFolder: 'folderPath', type: 'debugpy' }; when(interpreterService.getActiveInterpreter(anything())).thenCall((arg) => { assert.deepEqual(arg, Uri.file('folderPath')); From fc5e15e73f77ae5e6a29a3fcb75b2ed55edf18e1 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:54:40 -0700 Subject: [PATCH 3/3] correct mocking --- src/test/interpreters/interpreterPathCommand.unit.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/interpreters/interpreterPathCommand.unit.test.ts b/src/test/interpreters/interpreterPathCommand.unit.test.ts index fe03477c759b..8d45ad82577c 100644 --- a/src/test/interpreters/interpreterPathCommand.unit.test.ts +++ b/src/test/interpreters/interpreterPathCommand.unit.test.ts @@ -13,15 +13,19 @@ import * as commandApis from '../../client/common/vscodeApis/commandApis'; import { InterpreterPathCommand } from '../../client/interpreter/interpreterPathCommand'; import { IInterpreterService } from '../../client/interpreter/contracts'; import { PythonEnvironment } from '../../client/pythonEnvironments/info'; +import * as workspaceApis from '../../client/common/vscodeApis/workspaceApis'; suite('Interpreter Path Command', () => { let interpreterService: IInterpreterService; let interpreterPathCommand: InterpreterPathCommand; let registerCommandStub: sinon.SinonStub; + let getConfigurationStub: sinon.SinonStub; + setup(() => { interpreterService = mock(); registerCommandStub = sinon.stub(commandApis, 'registerCommand'); interpreterPathCommand = new InterpreterPathCommand(instance(interpreterService), []); + getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); }); teardown(() => { @@ -76,6 +80,10 @@ suite('Interpreter Path Command', () => { }); test('If neither of these exists, value of workspace folder is `undefined`', async () => { + getConfigurationStub.withArgs('python').returns({ + get: sinon.stub().returns(false), + }); + const args = ['command']; when(interpreterService.getActiveInterpreter(undefined)).thenReturn(