import { CancellationToken , DebugConfiguration , DebugConfigurationProvider , WorkspaceFolder } from 'vscode' ; import { callWithTelemetryAndErrorHandling , IActionContext } from 'vscode-azureextensionui' ; import { isFunctionProject } from '../commands/createNewProject/verifyIsProject' ; import { hostStartTaskName } from '../constants' ; import { IPreDebugValidateResult , preDebugValidate } from './validatePreDebug' ; export abstract class FuncDebugProviderBase implements DebugConfigurationProvider { public abstract workerArgKey : string ; protected abstract defaultPortOrPipeName : number | string ; protected abstract debugConfig : DebugConfiguration ; private readonly _debugPorts = new Map < WorkspaceFolder | undefined , number | undefined > ( ) ; public abstract getWorkerArgValue ( folder ) ; public async provideDebugConfigurations ( folder , _token ? ) { const configs = await callWithTelemetryAndErrorHandling ( 'provideDebugConfigurations' , async ( context ) => { context . telemetry . properties . isActivationEvent = 'true' ; context . errorHandling . suppressDisplay = true ; context . telemetry . suppressIfSuccessful = true ; const result = [ ] ; if ( folder ) { if ( await isFunctionProject ( folder . uri . fsPath ) ) { result . push ( this . debugConfig ) ; } } return result ; } ) ; return configs || [ ] ; } public async resolveDebugConfiguration ( folder , debugConfiguration , _token ? ) { let result = debugConfiguration ; await callWithTelemetryAndErrorHandling ( 'resolveDebugConfiguration' , async ( context ) => { context . telemetry . properties . isActivationEvent = 'true' ; context . errorHandling . suppressDisplay = true ; context . telemetry . suppressIfSuccessful = true ; this . _debugPorts . set ( folder , < number | undefined > debugConfiguration . port ) ; if ( debugConfiguration . preLaunchTask === hostStartTaskName ) { context . telemetry . properties . isActivationEvent = 'false' ; context . telemetry . suppressIfSuccessful = false ; const preDebugResult = await preDebugValidate ( context , debugConfiguration ) ; if ( ! preDebugResult . shouldContinue ) { result = undefined ; } } } ) ; return result ; } protected getDebugPortOrPipeName ( folder ) { return this . _debugPorts . get ( folder ) || this . defaultPortOrPipeName ; } }