@@ -372,16 +372,16 @@ export async function showWebView(file: string, title: string, viewer: string |
372372}
373373
374374export async function showDataView ( source : string , type : string , title : string , file : string | undefined , data : string | object | undefined , viewer : string ) : Promise < void > {
375- console . info ( `[showDataView] source: ${ source } , type: ${ type } , title: ${ title } , file: ${ file } , viewer: ${ viewer } ` ) ;
375+ console . info ( `[showDataView] source: ${ source } , type: ${ type } , title: ${ title } , file: ${ file ?? 'none' } , viewer: ${ viewer } ` ) ;
376376 console . debug ( `data: ${ JSON . stringify ( data ) } ` ) ;
377377
378378 const getDataContent = async ( ) : Promise < string | undefined > => {
379379 if ( file === undefined ) {
380- return typeof data == " string" ? data : JSON . stringify ( data ) ;
380+ return typeof data === ' string' ? data : JSON . stringify ( data ) ;
381381 } else {
382382 const fileContent = await readContent ( file , 'utf8' ) ;
383- if ( fileContent == null ) {
384- console . error ( " Error: File wasn't found!" ) ;
383+ if ( fileContent === undefined ) {
384+ console . error ( ' Error: File wasn\ 't found!' ) ;
385385 return undefined ;
386386 }
387387 }
@@ -404,9 +404,11 @@ export async function showDataView(source: string, type: string, title: string,
404404 localResourceRoots : [ Uri . file ( resDir ) ] ,
405405 } ) ;
406406 const fileContent = await getDataContent ( ) ;
407- const content = await getTableHtml ( panel . webview , fileContent ! ) ;
408- panel . iconPath = new UriIcon ( 'open-preview' ) ;
409- panel . webview . html = content ;
407+ if ( fileContent !== undefined ) {
408+ const content = getTableHtml ( panel . webview , fileContent ) ;
409+ panel . iconPath = new UriIcon ( 'open-preview' ) ;
410+ panel . webview . html = content ;
411+ }
410412 } else if ( source === 'list' ) {
411413 const panel = window . createWebviewPanel ( 'dataview' , title ,
412414 {
@@ -420,14 +422,16 @@ export async function showDataView(source: string, type: string, title: string,
420422 localResourceRoots : [ Uri . file ( resDir ) ] ,
421423 } ) ;
422424 const fileContent = await getDataContent ( ) ;
423- const content = await getListHtml ( panel . webview , fileContent ! ) ;
424- panel . iconPath = new UriIcon ( 'open-preview' ) ;
425- panel . webview . html = content ;
425+ if ( fileContent !== undefined ) {
426+ const content = getListHtml ( panel . webview , fileContent ) ;
427+ panel . iconPath = new UriIcon ( 'open-preview' ) ;
428+ panel . webview . html = content ;
429+ }
426430 } else {
427431 if ( isGuestSession || file === undefined ) {
428432 const fileContent = file === undefined ? data as string : await rGuestService ?. requestFileContent ( file , 'utf8' ) ;
429433 if ( fileContent ) {
430- await openVirtualDoc ( file ?? " R View" , fileContent , true , true , ViewColumn [ viewer as keyof typeof ViewColumn ] ) ;
434+ await openVirtualDoc ( file ?? ' R View' , fileContent , true , true , ViewColumn [ viewer as keyof typeof ViewColumn ] ) ;
431435 }
432436 } else {
433437 await commands . executeCommand ( 'vscode.open' , Uri . file ( file ) , {
@@ -440,7 +444,7 @@ export async function showDataView(source: string, type: string, title: string,
440444 console . info ( '[showDataView] Done' ) ;
441445}
442446
443- export async function getTableHtml ( webview : Webview , content : string ) : Promise < string > {
447+ export function getTableHtml ( webview : Webview , content : string ) : string {
444448 resDir = isGuestSession ? guestResDir : resDir ;
445449 const pageSize = config ( ) . get < number > ( 'session.data.pageSize' , 500 ) ;
446450 return `
@@ -626,7 +630,7 @@ export async function getTableHtml(webview: Webview, content: string): Promise<s
626630` ;
627631}
628632
629- export async function getListHtml ( webview : Webview , content : string ) : Promise < string > {
633+ export function getListHtml ( webview : Webview , content : string ) : string {
630634 resDir = isGuestSession ? guestResDir : resDir ;
631635
632636 return `
@@ -816,8 +820,9 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
816820}
817821
818822function startIncomingRequestServer ( sessionStatusBarItem : StatusBarItem ) {
823+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
819824 const incomingRequestServer = new Server ( async ( socket : Socket ) => {
820- console . info ( `Incoming connection to the request server from ${ addressToStr ( socket . address ( ) as AddressInfo ) } ` )
825+ console . info ( `Incoming connection to the request server from ${ addressToStr ( socket . address ( ) as AddressInfo ) } ` ) ;
821826 if ( incomingRequestServerConnected ) {
822827 console . error ( 'A new connection to the incoming request server tries to connect but another connection currently connected!' ) ;
823828 return ;
@@ -828,27 +833,28 @@ function startIncomingRequestServer(sessionStatusBarItem: StatusBarItem) {
828833
829834 try {
830835 const promiseSocket = new PromiseSocket ( socket ) ;
831- console . info ( " Waiting for TCP input..." )
836+ console . info ( ' Waiting for TCP input...' ) ;
832837
833- let contentToProcess = "" ;
838+ let contentToProcess = '' ;
839+ // eslint-disable-next-line no-constant-condition
834840 while ( true ) {
835- const currentChunk = await promiseSocket . read ( ) ;
836- if ( currentChunk === undefined ) {
837- // The end of the socket
838- console . info ( "Incoming request server socket EOF" ) ;
839-
840- // Force cleaning even if somehow not detached
841- await cleanupSession ( ) ;
842-
843- if ( contentToProcess ) {
844- console . error ( "TCP connection recieved EOF, but the last content didn't end up with line break." )
845- }
846- incomingRequestServerConnected = false ;
847- return ;
841+ const currentChunk = await promiseSocket . read ( ) as string | undefined ;
842+ if ( currentChunk === undefined ) {
843+ // The end of the socket
844+ console . info ( 'Incoming request server socket EOF' ) ;
845+
846+ // Force cleaning even if somehow not detached
847+ await cleanupSession ( ) ;
848+
849+ if ( contentToProcess ) {
850+ console . error ( 'TCP connection recieved EOF, but the last content didn\'t end up with line break.' ) ;
848851 }
849- // otherwise
850-
851- contentToProcess = contentToProcess + currentChunk ;
852+ incomingRequestServerConnected = false ;
853+ return ;
854+ }
855+ // otherwise
856+
857+ contentToProcess = contentToProcess + currentChunk ;
852858
853859 const requests = contentToProcess . split ( ( / \r ? \n / ) ) ;
854860 for ( let i = 0 ; i < requests . length - 1 ; ++ i ) {
@@ -861,6 +867,7 @@ function startIncomingRequestServer(sessionStatusBarItem: StatusBarItem) {
861867 contentToProcess = requests [ requests . length - 1 ] ;
862868 }
863869 } catch ( err ) {
870+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
864871 console . error ( `Error while processing TCP connection: ${ err } ` ) ;
865872
866873 await cleanupSession ( ) ;
@@ -870,11 +877,11 @@ function startIncomingRequestServer(sessionStatusBarItem: StatusBarItem) {
870877
871878 const server = incomingRequestServer . listen ( config ( ) . get < number > ( 'sessionWatcherTCPServerPort' ) ,
872879 config ( ) . get < string > ( 'sessionWatcherTCPServerHostName' ) , function ( ) {
873- incomingRequestServerAddressInfo = server . address ( ) as AddressInfo ;
874- console . info ( `Started listening on ${ addressToStr ( incomingRequestServerAddressInfo ) } ` ) ;
880+ incomingRequestServerAddressInfo = server . address ( ) as AddressInfo ;
881+ console . info ( `Started listening on ${ addressToStr ( incomingRequestServerAddressInfo ) } ` ) ;
875882
876- updateSessionStatusBarItem ( sessionStatusBarItem ) ;
877- } ) ;
883+ updateSessionStatusBarItem ( sessionStatusBarItem ) ;
884+ } ) ;
878885
879886 return server ;
880887}
@@ -889,7 +896,7 @@ const create_tmp_file: (options: tmp.FileOptions) => Promise<{ name: string, fd:
889896 }
890897 } ) ;
891898 }
892- ) ;
899+ ) ;
893900
894901export async function processRequest ( request : ISessionRequest , socket : Socket | null , sessionStatusBarItem : StatusBarItem ) {
895902 switch ( request . command ) {
@@ -907,8 +914,8 @@ export async function processRequest(request: ISessionRequest, socket: Socket |
907914 break ;
908915 }
909916 case 'updateWorkspace' : {
910- if ( request . workspaceData == null ) {
911- console . error ( " [updateRequest] workspaceData is not set!" )
917+ if ( ! request . workspaceData ) {
918+ console . error ( ' [updateRequest] workspaceData is not set!' ) ;
912919 return ;
913920 }
914921
@@ -930,7 +937,7 @@ export async function processRequest(request: ISessionRequest, socket: Socket |
930937 // TODO: Log and show correct TCP info here
931938 console . info ( `[updateRequest] attach PID: ${ pid } ` ) ;
932939 updateSessionStatusBarItem ( sessionStatusBarItem ) ;
933- if ( socket == null ) {
940+ if ( socket === null ) {
934941 updateSessionWatcher ( ) ;
935942 }
936943
@@ -943,15 +950,15 @@ export async function processRequest(request: ISessionRequest, socket: Socket |
943950 if ( request . plot_url ) {
944951 await globalHttpgdManager ?. showViewer ( request . plot_url ) ;
945952 }
946- if ( socket == null ) {
953+ if ( socket === null ) {
947954 void watchProcess ( pid ) . then ( ( v : string ) => {
948955 void cleanupSession ( v ) ;
949956 } ) ;
950957 }
951958 break ;
952959 }
953960 case 'detach' : {
954- if ( socket == null ) {
961+ if ( socket === null ) {
955962 if ( request . pid ) {
956963 await cleanupSession ( request . pid ) ;
957964 }
@@ -981,14 +988,16 @@ export async function processRequest(request: ISessionRequest, socket: Socket |
981988 }
982989 case 'plot' : {
983990 if ( request . format !== 'image/png' ) {
984- console . info ( `Error: the format ${ request . format } isn't supported, only image/png is supported for now.` ) ;
991+ console . info ( `Error: the format ${ request . format || '(none)' } isn't supported, only image/png is supported for now.` ) ;
985992 break ;
986993 }
987994
988- const { name : filePath , fd } = await create_tmp_file ( { postfix : '.png' } ) ;
989- const arrayData = Buffer . from ( request . plot_base64 ! , 'base64' ) ;
990- await fs . writeFile ( fd , arrayData ) ;
991- showPlot ( filePath ) ;
995+ if ( request . plot_base64 ) {
996+ const { name : filePath , fd } = await create_tmp_file ( { postfix : '.png' } ) ;
997+ const arrayData = Buffer . from ( request . plot_base64 , 'base64' ) ;
998+ await fs . writeFile ( fd , arrayData ) ;
999+ showPlot ( filePath ) ;
1000+ }
9921001 break ;
9931002 }
9941003 case 'rstudioapi' : {
0 commit comments