Skip to content

Commit dd00f2c

Browse files
author
Kartik Raj
committed
Support ${command:python.interpreterPath} with this envs
1 parent 22ccb95 commit dd00f2c

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/client/debugger/extension/configuration/launch.json/interpreterPathCommand.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import { Uri } from 'vscode';
88
import { IExtensionSingleActivationService } from '../../../../activation/types';
99
import { ICommandManager } from '../../../../common/application/types';
1010
import { Commands } from '../../../../common/constants';
11-
import { IConfigurationService, IDisposable, IDisposableRegistry } from '../../../../common/types';
11+
import { IDisposable, IDisposableRegistry } from '../../../../common/types';
12+
import { IInterpreterService } from '../../../../interpreter/contracts';
1213

1314
@injectable()
1415
export class InterpreterPathCommand implements IExtensionSingleActivationService {
1516
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };
1617
constructor(
1718
@inject(ICommandManager) private readonly commandManager: ICommandManager,
18-
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
19+
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
1920
@inject(IDisposableRegistry) private readonly disposables: IDisposable[],
2021
) {}
2122

@@ -27,7 +28,7 @@ export class InterpreterPathCommand implements IExtensionSingleActivationService
2728
);
2829
}
2930

30-
public _getSelectedInterpreterPath(args: { workspaceFolder: string } | string[]): string {
31+
public async _getSelectedInterpreterPath(args: { workspaceFolder: string } | string[]): Promise<string> {
3132
// If `launch.json` is launching this command, `args.workspaceFolder` carries the workspaceFolder
3233
// If `tasks.json` is launching this command, `args[1]` carries the workspaceFolder
3334
const workspaceFolder = 'workspaceFolder' in args ? args.workspaceFolder : args[1] ? args[1] : undefined;
@@ -38,6 +39,6 @@ export class InterpreterPathCommand implements IExtensionSingleActivationService
3839
workspaceFolderUri = undefined;
3940
}
4041

41-
return this.configurationService.getSettings(workspaceFolderUri).pythonPath;
42+
return (await this.interpreterService.getActiveInterpreter(workspaceFolderUri))?.path ?? 'python';
4243
}
4344
}

src/client/debugger/extension/configuration/resolvers/attach.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CancellationToken, Uri, WorkspaceFolder } from 'vscode';
88
import { IDocumentManager, IWorkspaceService } from '../../../../common/application/types';
99
import { IPlatformService } from '../../../../common/platform/types';
1010
import { IConfigurationService } from '../../../../common/types';
11+
import { IInterpreterService } from '../../../../interpreter/contracts';
1112
import { AttachRequestArguments, DebugOptions, PathMapping } from '../../../types';
1213
import { BaseConfigurationResolver } from './base';
1314

@@ -18,8 +19,9 @@ export class AttachConfigurationResolver extends BaseConfigurationResolver<Attac
1819
@inject(IDocumentManager) documentManager: IDocumentManager,
1920
@inject(IPlatformService) platformService: IPlatformService,
2021
@inject(IConfigurationService) configurationService: IConfigurationService,
22+
@inject(IInterpreterService) interpreterService: IInterpreterService,
2123
) {
22-
super(workspaceService, documentManager, platformService, configurationService);
24+
super(workspaceService, documentManager, platformService, configurationService, interpreterService);
2325
}
2426

2527
public async resolveDebugConfigurationWithSubstitutedVariables(

src/client/debugger/extension/configuration/resolvers/base.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { PYTHON_LANGUAGE } from '../../../../common/constants';
1111
import { IPlatformService } from '../../../../common/platform/types';
1212
import { IConfigurationService } from '../../../../common/types';
1313
import { SystemVariables } from '../../../../common/variables/systemVariables';
14+
import { IInterpreterService } from '../../../../interpreter/contracts';
1415
import { sendTelemetryEvent } from '../../../../telemetry';
1516
import { EventName } from '../../../../telemetry/constants';
1617
import { DebuggerTelemetry } from '../../../../telemetry/types';
@@ -28,6 +29,7 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
2829
protected readonly documentManager: IDocumentManager,
2930
protected readonly platformService: IPlatformService,
3031
protected readonly configurationService: IConfigurationService,
32+
protected readonly interpreterService: IInterpreterService,
3133
) {}
3234

3335
// This is a legacy hook used solely for backwards-compatible manual substitution
@@ -81,12 +83,12 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
8183
}
8284
}
8385

84-
protected resolveAndUpdatePaths(
86+
protected async resolveAndUpdatePaths(
8587
workspaceFolder: Uri | undefined,
8688
debugConfiguration: LaunchRequestArguments,
87-
): void {
89+
): Promise<void> {
8890
this.resolveAndUpdateEnvFilePath(workspaceFolder, debugConfiguration);
89-
this.resolveAndUpdatePythonPath(workspaceFolder, debugConfiguration);
91+
await this.resolveAndUpdatePythonPath(workspaceFolder, debugConfiguration);
9092
}
9193

9294
protected resolveAndUpdateEnvFilePath(
@@ -105,10 +107,10 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
105107
}
106108
}
107109

108-
protected resolveAndUpdatePythonPath(
110+
protected async resolveAndUpdatePythonPath(
109111
workspaceFolder: Uri | undefined,
110112
debugConfiguration: LaunchRequestArguments,
111-
): void {
113+
): Promise<void> {
112114
if (!debugConfiguration) {
113115
return;
114116
}
@@ -118,8 +120,9 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
118120
this.workspaceService,
119121
);
120122
if (debugConfiguration.pythonPath === '${command:python.interpreterPath}' || !debugConfiguration.pythonPath) {
121-
const pythonPath = this.configurationService.getSettings(workspaceFolder).pythonPath;
122-
debugConfiguration.pythonPath = pythonPath;
123+
const interpreterPath =
124+
(await this.interpreterService.getActiveInterpreter(workspaceFolder))?.path ?? 'python';
125+
debugConfiguration.pythonPath = interpreterPath;
123126
this.pythonPathSource = PythonPathSource.settingsJson;
124127
} else {
125128
debugConfiguration.pythonPath = systemVariables.resolveAny(debugConfiguration.pythonPath);

src/client/debugger/extension/configuration/resolvers/launch.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IDiagnosticsService, IInvalidPythonPathInDebuggerService } from '../../
1010
import { IDocumentManager, IWorkspaceService } from '../../../../common/application/types';
1111
import { IPlatformService } from '../../../../common/platform/types';
1212
import { IConfigurationService } from '../../../../common/types';
13+
import { IInterpreterService } from '../../../../interpreter/contracts';
1314
import { DebuggerTypeName } from '../../../constants';
1415
import { DebugOptions, DebugPurpose, LaunchRequestArguments } from '../../../types';
1516
import { PythonPathSource } from '../../types';
@@ -27,8 +28,9 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
2728
@inject(IPlatformService) platformService: IPlatformService,
2829
@inject(IConfigurationService) configurationService: IConfigurationService,
2930
@inject(IDebugEnvironmentVariablesService) private readonly debugEnvHelper: IDebugEnvironmentVariablesService,
31+
@inject(IInterpreterService) interpreterService: IInterpreterService,
3032
) {
31-
super(workspaceService, documentManager, platformService, configurationService);
33+
super(workspaceService, documentManager, platformService, configurationService, interpreterService);
3234
}
3335

3436
public async resolveDebugConfiguration(
@@ -52,7 +54,7 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
5254
}
5355

5456
const workspaceFolder = this.getWorkspaceFolder(folder);
55-
this.resolveAndUpdatePaths(workspaceFolder, debugConfiguration);
57+
await this.resolveAndUpdatePaths(workspaceFolder, debugConfiguration);
5658
return debugConfiguration;
5759
}
5860

0 commit comments

Comments
 (0)