Skip to content

Commit 411da92

Browse files
committed
get Python interpreter based on program file when resolving launch configurations
1 parent 2322819 commit 411da92

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/extension/debugger/configuration/debugConfigurationService.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
3+
import * as fs from 'fs';
44
import { cloneDeep } from 'lodash';
5-
import { CancellationToken, DebugConfiguration, QuickPickItem, WorkspaceFolder } from 'vscode';
5+
import { CancellationToken, DebugConfiguration, QuickPickItem, Uri, WorkspaceFolder } from 'vscode';
66
import { DebugConfigStrings } from '../../common/utils/localize';
77
import { IMultiStepInputFactory, InputStep, IQuickPickParameters, MultiStepInput } from '../../common/multiStepInput';
88
import { AttachRequestArguments, DebugConfigurationArguments, LaunchRequestArguments } from '../../types';
@@ -17,6 +17,7 @@ import { buildPyramidLaunchConfiguration } from './providers/pyramidLaunch';
1717
import { buildRemoteAttachConfiguration } from './providers/remoteAttach';
1818
import { IDebugConfigurationResolver } from './types';
1919
import { buildFileWithArgsLaunchDebugConfiguration } from './providers/fileLaunchWithArgs';
20+
import { getInterpreterDetails } from '../../common/python';
2021

2122
export class PythonDebugConfigurationService implements IDebugConfigurationService {
2223
private cacheDebugConfig: DebugConfiguration | undefined = undefined;
@@ -77,6 +78,19 @@ export class PythonDebugConfigurationService implements IDebugConfigurationServi
7778
this.cacheDebugConfig = cloneDeep(debugConfiguration);
7879
}
7980
}
81+
82+
if (debugConfiguration.program !== undefined) {
83+
if (debugConfiguration.python === undefined) {
84+
// If program is a valid file, get interpreter for that file
85+
if (fs.existsSync(debugConfiguration.program) && fs.statSync(debugConfiguration.program).isFile()) {
86+
const interpreter = await getInterpreterDetails(Uri.file(debugConfiguration.program));
87+
if (interpreter?.path && interpreter.path.length > 0) {
88+
debugConfiguration.python = interpreter.path[0];
89+
}
90+
}
91+
}
92+
}
93+
8094
return this.launchResolver.resolveDebugConfiguration(
8195
folder,
8296
debugConfiguration as LaunchRequestArguments,

0 commit comments

Comments
 (0)