import { DebugConfiguration , Extension , extensions , WorkspaceFolder } from 'vscode' ; import { hostStartTaskName , localhost } from '../constants' ; import { localize } from '../localize' ; import { FuncDebugProviderBase } from './FuncDebugProviderBase' ; export const defaultPythonDebugPort = 9091 ; export const pythonDebugConfig = { name : localize ( 'attachPython' , 'Attach to Python Functions' ) , type : 'python' , request : 'attach' , port : defaultPythonDebugPort , preLaunchTask : hostStartTaskName } ; export class PythonDebugProvider extends FuncDebugProviderBase { public readonly workerArgKey : string = 'languageWorkers__python__arguments' ; protected readonly defaultPortOrPipeName : number = defaultPythonDebugPort ; protected readonly debugConfig : DebugConfiguration = pythonDebugConfig ; public async getWorkerArgValue ( folder ) { const port = < number > this . getDebugPortOrPipeName ( folder ) ; return await getPythonCommand ( localhost , port ) ; } } async function getPythonCommand ( host , port ) { const pyExtensionId = 'ms-python.python' ; const pyExtension = extensions . getExtension < IPythonExtensionApi > ( pyExtensionId ) ; if ( pyExtension ) { if ( ! pyExtension . isActive ) { await pyExtension . activate ( ) ; } if ( pyExtension . exports && pyExtension . exports . debug ) { return ( await pyExtension . exports . debug . getRemoteLauncherCommand ( host , port , false ) ) . join ( ' ' ) ; } else { throw new Error ( localize ( 'pyExtOutOfDate' , 'You must update extension with id "{0}" to debug Python projects.' , pyExtensionId ) ) ; } } else { throw new Error ( localize ( 'noPyExt' , 'You must install extension with id "{0}" to debug Python projects.' , pyExtensionId ) ) ; } }