11import * as fs from 'fs' ;
2+ import * as net from 'net' ;
23import * as os from 'os' ;
34import * as path from 'path' ;
45import * as ssh2Streams from 'ssh2-streams' ;
56import * as temp from 'temp' ;
67
78import * as vscode from 'vscode' ;
89
9- import { LaunchRequestArguments } from './debugServer' ;
10+ import { Ev3devBrowserDebugSession , LaunchRequestArguments } from './debugServer' ;
1011import { Brickd } from './brickd' ;
1112import { Device } from './device' ;
1213import {
@@ -34,6 +35,7 @@ export function activate(context: vscode.ExtensionContext): void {
3435 resourceDir = context . asAbsolutePath ( 'resources' ) ;
3536
3637 ev3devBrowserProvider = new Ev3devBrowserProvider ( ) ;
38+ const factory = new Ev3devDebugAdapterDescriptorFactory ( ) ;
3739 context . subscriptions . push (
3840 output , ev3devBrowserProvider ,
3941 vscode . window . registerTreeDataProvider ( 'ev3devBrowser' , ev3devBrowserProvider ) ,
@@ -52,10 +54,33 @@ export function activate(context: vscode.ExtensionContext): void {
5254 vscode . commands . registerCommand ( 'ev3devBrowser.action.pickDevice' , ( ) => pickDevice ( ) ) ,
5355 vscode . commands . registerCommand ( 'ev3devBrowser.action.download' , ( ) => downloadAll ( ) ) ,
5456 vscode . commands . registerCommand ( 'ev3devBrowser.action.refresh' , ( ) => refresh ( ) ) ,
55- vscode . debug . onDidReceiveDebugSessionCustomEvent ( e => handleCustomDebugEvent ( e ) )
57+ vscode . debug . onDidReceiveDebugSessionCustomEvent ( e => handleCustomDebugEvent ( e ) ) ,
58+ vscode . debug . registerDebugAdapterDescriptorFactory ( 'ev3devBrowser' , factory ) ,
5659 ) ;
5760}
5861
62+ class Ev3devDebugAdapterDescriptorFactory implements vscode . DebugAdapterDescriptorFactory {
63+ private server ?: net . Server ;
64+
65+ createDebugAdapterDescriptor ( session : vscode . DebugSession , executable : vscode . DebugAdapterExecutable | undefined ) : vscode . ProviderResult < vscode . DebugAdapterDescriptor > {
66+ if ( ! this . server ) {
67+ // start listening on a random port
68+ this . server = net . createServer ( socket => {
69+ const session = new Ev3devBrowserDebugSession ( ) ;
70+ session . setRunAsServer ( true ) ;
71+ session . start ( < NodeJS . ReadableStream > socket , socket ) ;
72+ } ) . listen ( 0 ) ;
73+ }
74+
75+ // make VS Code connect to debug server
76+ return new vscode . DebugAdapterServer ( this . server . address ( ) . port ) ;
77+ }
78+
79+ dispose ( ) {
80+ this . server ?. close ( ) ;
81+ }
82+ }
83+
5984// this method is called when your extension is deactivated
6085export function deactivate ( ) : void {
6186 // The "temp" module should clean up automatically, but do this just in case.
0 commit comments