import * as path from "path" ; import * as vscode from "vscode" ; import { IDebugProvider , PortInfo , Cancellable } from "./debugProvider" ; import { ProcessInfo } from "./debugUtils" ; import * as extensionUtils from "../extensionUtils" ; import { Kubectl } from "../kubectl" ; import { kubeChannel } from "../kubeChannel" ; import { IDockerfile } from "../docker/parser" ; import { Dictionary } from "../utils/dictionary" ; import * as extensionConfig from '../components/config/config' ; const defaultDotnetDebuggerExtensionId = "ms-dotnettools.csharp" ; const defaultDotnetDebuggerExtension = "C# for Visual Studio Code" ; const defaultDotnetDebuggerConfigType = "dotnet" ; export class DotNetDebugProvider implements IDebugProvider { public getDebuggerType ( ) { return defaultDotnetDebuggerConfigType ; } public async isDebuggerInstalled ( ) { if ( vscode . extensions . getExtension ( defaultDotnetDebuggerExtensionId ) ) { return true ; } const answer = await vscode . window . showInformationMessage ( `Dotnet debugging requires the '${ defaultDotnetDebuggerExtension }' extension. Would you like to install it now?` , "Install Now" ) ; if ( answer === "Install Now" ) { return await extensionUtils . installVscodeExtension ( defaultDotnetDebuggerExtensionId ) ; } return false ; } public async startDebugging ( workspaceFolder , _sessionName , _port , pod , pidToDebug ) { const processId = pidToDebug ? pidToDebug . toString ( ) : "${command:pickRemoteProcess}" ; const debugConfiguration = { name : ".NET Core Kubernetes Attach" , type : "coreclr" , request : "attach" , processId : processId , pipeTransport : { pipeProgram : "kubectl" , pipeArgs : [ "exec" , "-i" , pod , "--" , "/bin/sh" , "-c" ] , debuggerPath : extensionConfig . getDotnetVsdbgPath ( ) , pipeCwd : workspaceFolder , quoteArgs : true } } ; const map = extensionConfig . getDotnetDebugSourceFileMap ( ) ; if ( map ) { try { const json = `{"${ map . replace ( /\\/g , "\\\\" ) }":"${ workspaceFolder . replace ( /\\/g , "\\\\" ) }"}` ; const sourceFileMap = JSON . parse ( json ) ; debugConfiguration [ 'sourceFileMap' ] = sourceFileMap ; } catch ( error ) { kubeChannel . showOutput ( error . message ) ; } } const currentFolder = ( vscode . workspace . workspaceFolders || [ ] ) . find ( ( folder ) => folder . name === path . basename ( workspaceFolder ) ) ; const result = await vscode . debug . startDebugging ( currentFolder , debugConfiguration ) ; if ( ! result ) { kubeChannel . showOutput ( `${ defaultDotnetDebuggerConfigType } debug attach failed for pod ${ pod }.\nSee https://github.com/Azure/vscode-kubernetes-tools/blob/master/debug-on-kubernetes.md for troubleshooting.` , "Failed to attach" ) ; } return result ; } public isSupportedImage ( _baseImage ) { return false ; } public async resolvePortsFromFile ( _dockerfile , _env ) { return undefined ; } public async resolvePortsFromContainer ( _kubectl , _pod , _podNamespace , _container ) { return undefined ; } public filterSupportedProcesses ( processes ) { return processes . filter ( ( processInfo ) => ( processInfo . command . toLowerCase ( ) . startsWith ( 'dotnet ' ) || processInfo . command . indexOf ( '/dotnet ' ) >= 0 ) ) ; } public isPortRequired ( ) { return false ; } public async getDebugArgs ( ) { return { cancelled : false } ; } }