@@ -777,15 +777,15 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
777777 if ( request . plot_url ) {
778778 await globalHttpgdManager ?. showViewer ( request . plot_url ) ;
779779 }
780- void watchProcess ( Number ( pid ) ) . then ( ( v ) => {
781- if ( v === Number ( pid ) ) {
782- cleanupSession ( ) ;
783- }
780+ void watchProcess ( pid ) . then ( ( v : string ) => {
781+ cleanupSession ( v ) ;
784782 } ) ;
785783 break ;
786784 }
787785 case 'detach' : {
788- cleanupSession ( ) ;
786+ if ( request . pid ) {
787+ cleanupSession ( request . pid ) ;
788+ }
789789 break ;
790790 }
791791 case 'browser' : {
@@ -826,19 +826,21 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
826826 }
827827}
828828
829- export function cleanupSession ( ) : void {
830- if ( sessionStatusBarItem ) {
831- sessionStatusBarItem . text = 'R: (not attached)' ;
832- sessionStatusBarItem . tooltip = 'Click to attach active terminal.' ;
829+ export function cleanupSession ( pidArg : string ) : void {
830+ if ( pid === pidArg ) {
831+ if ( sessionStatusBarItem ) {
832+ sessionStatusBarItem . text = 'R: (not attached)' ;
833+ sessionStatusBarItem . tooltip = 'Click to attach active terminal.' ;
834+ }
835+ workspaceData . globalenv = { } ;
836+ workspaceData . loaded_namespaces = [ ] ;
837+ workspaceData . search = [ ] ;
838+ rWorkspace ?. refresh ( ) ;
839+ removeSessionFiles ( ) ;
833840 }
834- workspaceData . globalenv = { } ;
835- workspaceData . loaded_namespaces = [ ] ;
836- workspaceData . search = [ ] ;
837- rWorkspace ?. refresh ( ) ;
838- removeSessionFiles ( ) ;
839841}
840842
841- async function watchProcess ( pid : number ) : Promise < number > {
843+ async function watchProcess ( pid : string ) : Promise < string > {
842844 function pidIsRunning ( pid : number ) {
843845 try {
844846 process . kill ( pid , 0 ) ;
@@ -848,9 +850,11 @@ async function watchProcess(pid: number): Promise<number> {
848850 }
849851 }
850852
853+ const pidArg = Number ( pid ) ;
854+
851855 let res = true ;
852856 do {
853- res = pidIsRunning ( pid ) ;
857+ res = pidIsRunning ( pidArg ) ;
854858 await new Promise ( resolve => {
855859 setTimeout ( resolve , 1000 ) ;
856860 } ) ;
0 commit comments