import * as vscode from "vscode" ; import { DukDebugSession } from "./DukDebugger" ; import * as Net from "net" ; const EXTENSION_DEBUG_TYPE = "duk" ; export function activate ( context ) { console . log ( "Duk Debugger Extension Activated" ) ; if ( process . env . NODE_ENV === "development" ) { const factory = new DukDebugAdapterDescriptorFactory ( ) ; context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( EXTENSION_DEBUG_TYPE , factory ) ) ; context . subscriptions . push ( factory ) ; } } export function deactivate ( ) { } class DukDebugAdapterDescriptorFactory implements vscode . DebugAdapterDescriptorFactory { private server ? : Net . Server ; createDebugAdapterDescriptor ( session , executable ) { if ( ! this . server ) { this . server = Net . createServer ( socket => { const session = new DukDebugSession ( ) ; session . setRunAsServer ( true ) ; session . start ( < NodeJS . ReadableStream > socket , socket ) ; } ) . listen ( 0 ) ; } const { port } = this . server . address ( ) as Net . AddressInfo ; return new vscode . DebugAdapterServer ( port ) ; } dispose ( ) { if ( this . server ) { this . server . close ( ) ; } } }