11import { ChildProcess , spawn } from 'child_process' ;
2- import { commands , ExtensionContext , Uri , ViewColumn , WebviewView , WebviewViewProvider , WebviewViewResolveContext , window , workspace } from 'vscode' ;
2+ import { commands , ExtensionContext , Uri , WebviewView , WebviewViewProvider , WebviewViewResolveContext , window , workspace } from 'vscode' ;
33import { state } from './extension' ;
44import { dirname } from 'path' ;
5- import treeKill = require ( 'tree-kill' ) ;
5+ import * as treeKill from 'tree-kill' ;
66
77export default function setupConsole ( context : ExtensionContext ) {
8- // Convert to array to allow for waiting on the process to end
9- let sketchProcess : ChildProcess | undefined = undefined ;
8+ const sketchProcesses : ChildProcess [ ] = [ ] ;
109
1110 const provider = new ProcessingConsoleViewProvider ( ) ;
1211
@@ -49,12 +48,12 @@ export default function setupConsole(context: ExtensionContext) {
4948 } ) ;
5049 proc . on ( 'close' , ( code ) => {
5150 provider . webview ?. webview . postMessage ( { type : 'close' , value : code ?. toString ( ) } ) ;
52- sketchProcess = undefined ;
51+ sketchProcesses . splice ( sketchProcesses . indexOf ( proc ) , 1 ) ;
5352 commands . executeCommand ( 'setContext' , 'processing.sketch.running' , false ) ;
5453 } ) ;
5554 provider . webview ?. show ?.( true ) ;
5655 provider . webview ?. webview . postMessage ( { type : 'clear' } ) ;
57- sketchProcess = proc ;
56+ sketchProcesses . push ( proc ) ;
5857 commands . executeCommand ( 'setContext' , 'processing.sketch.running' , true ) ;
5958 } ) ;
6059
@@ -63,10 +62,9 @@ export default function setupConsole(context: ExtensionContext) {
6362 } ) ;
6463
6564 const stopSketch = commands . registerCommand ( 'processing.sketch.stop' , ( ) => {
66- if ( sketchProcess === undefined ) {
67- return ;
65+ for ( const proc of sketchProcesses ) {
66+ treeKill ( proc . pid as number ) ;
6867 }
69- treeKill ( sketchProcess ?. pid as number ) ;
7068 } ) ;
7169
7270 context . subscriptions . push (
0 commit comments