11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
3-
3+ import * as fs from 'fs' ;
44import { cloneDeep } from 'lodash' ;
5- import { CancellationToken , DebugConfiguration , QuickPickItem , WorkspaceFolder } from 'vscode' ;
5+ import { CancellationToken , DebugConfiguration , QuickPickItem , Uri , WorkspaceFolder } from 'vscode' ;
66import { DebugConfigStrings } from '../../common/utils/localize' ;
77import { IMultiStepInputFactory , InputStep , IQuickPickParameters , MultiStepInput } from '../../common/multiStepInput' ;
88import { AttachRequestArguments , DebugConfigurationArguments , LaunchRequestArguments } from '../../types' ;
@@ -17,6 +17,7 @@ import { buildPyramidLaunchConfiguration } from './providers/pyramidLaunch';
1717import { buildRemoteAttachConfiguration } from './providers/remoteAttach' ;
1818import { IDebugConfigurationResolver } from './types' ;
1919import { buildFileWithArgsLaunchDebugConfiguration } from './providers/fileLaunchWithArgs' ;
20+ import { getInterpreterDetails } from '../../common/python' ;
2021
2122export 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