'use strict' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import { workspace , ExtensionContext } from 'vscode' ; import { WorkspaceFolder , DebugConfiguration , ProviderResult , CancellationToken } from 'vscode' ; import { C64jasmDebugSession } from './c64jasmDebug' ; import * as Net from 'net' ; import { LanguageClient , LanguageClientOptions , ServerOptions , TransportKind } from 'vscode-languageclient' ; const LANGUAGE_SERVER_ENABLED = false ; const EMBED_DEBUG_ADAPTER = true ; let client ; function activateDebugger ( context ) { context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.c64jasm.getProgramName' , _config => { return vscode . window . showInputBox ( { placeHolder : "Please enter the name of your .asm entry file in the workspace folder" , value : "main.asm" } ) ; } ) ) ; const provider = new C64jasmConfigurationProvider ( ) ; context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( 'c64jasm' , provider ) ) ; context . subscriptions . push ( provider ) ; } class C64jasmConfigurationProvider implements vscode . DebugConfigurationProvider { private _server ? : Net . Server ; /**
     * Massage a debug configuration just before a debug session is being launched,
     * e.g. add all missing attributes to the debug configuration.
     */ resolveDebugConfiguration ( folder , config , token ? ) { if ( ! config . type && ! config . request && ! config . name ) { const editor = vscode . window . activeTextEditor ; if ( editor && editor . document . languageId === 'asm' ) { config . type = 'c64jasm' ; config . name = 'Launch' ; config . request = 'launch' ; config . program = '${file}' ; config . stopOnEntry = true ; } } if ( ! config . program ) { return vscode . window . showInformationMessage ( "Cannot find a program to debug" ) . then ( _ => { return undefined ; } ) ; } if ( EMBED_DEBUG_ADAPTER ) { if ( ! this . _server ) { this . _server = Net . createServer ( socket => { const session = new C64jasmDebugSession ( ) ; const vicePath = vscode . workspace . getConfiguration ( ) . get ( "c64jasm-client.vicePath" , "x64" ) ; session . setVicePath ( vicePath ) ; session . setRunAsServer ( true ) ; session . start ( < NodeJS . ReadableStream > socket , socket ) ; } ) . listen ( 0 ) ; } config . debugServer = this . _server . address ( ) . port ; } return config ; } dispose ( ) { if ( this . _server ) { this . _server . close ( ) ; } } } export function activate ( context ) { activateDebugger ( context ) ; if ( ! LANGUAGE_SERVER_ENABLED ) { return ; } let serverModule = context . asAbsolutePath ( path . join ( 'server' , 'out' , 'server.js' ) ) ; let debugOptions = { execArgv : [ '--nolazy' , '--inspect=6009' ] } ; let serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; let clientOptions = { documentSelector : [ { scheme : 'file' , language : 'asm' } ] , synchronize : { fileEvents : workspace . createFileSystemWatcher ( '**/.clientrc' ) } } ; client = new LanguageClient ( 'c64jasm-client' , 'C64jasm language and debug support' , serverOptions , clientOptions ) ; client . start ( ) ; } export function deactivate ( ) { if ( ! client ) { return undefined ; } return client . stop ( ) ; }