@@ -494,28 +494,28 @@ async function activateWithInstalledDistribution(
494494 }
495495 }
496496
497+ const tmpDir = tmp . dirSync ( { prefix : 'qhelp_' , keep : false , unsafeCleanup : true } ) ;
498+ ctx . subscriptions . push ( { dispose : tmpDir . removeCallback } ) ;
499+
497500 async function previewQueryHelp (
498501 selectedQuery : Uri
499502 ) : Promise < void > {
500- const pathToQhelp = selectedQuery ? selectedQuery . fsPath : window . activeTextEditor ! . document . uri . fsPath ;
503+ // selectedQuery is unpopulated when executing through the command palette
504+ const pathToQhelp = selectedQuery ? selectedQuery . fsPath : window . activeTextEditor ! . document . uri . fsPath ;
501505 if ( pathToQhelp ) {
502506 // Create temporary directory
503- return tmp . dir ( ) . then ( async o => {
504- const relativePathToMd = path . basename ( pathToQhelp , '.qhelp' ) + '.md' ;
505- const absolutePathToMd = path . join ( o . path , relativePathToMd ) ;
506- const uri = Uri . file ( absolutePathToMd ) ;
507- try {
508- await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
509- await commands . executeCommand ( 'markdown.showPreviewToSide' , uri ) ;
510- } catch ( err ) {
511- const errorMessage = err . message . includes ( 'Generating qhelp in markdown' ) ? (
512- `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
513- ) : `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
514- void helpers . showAndLogErrorMessage ( errorMessage , { fullMessage : `${ errorMessage } \n${ err } ` } ) ;
515- }
516- // Manual cleanup
517- void o . cleanup ( ) ;
518- } ) ;
507+ const relativePathToMd = path . basename ( pathToQhelp , '.qhelp' ) + '.md' ;
508+ const absolutePathToMd = path . join ( tmpDir . name , relativePathToMd ) ;
509+ const uri = Uri . file ( absolutePathToMd ) ;
510+ try {
511+ await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
512+ await commands . executeCommand ( 'markdown.showPreviewToSide' , uri ) ;
513+ } catch ( err ) {
514+ const errorMessage = err . message . includes ( 'Generating qhelp in markdown' ) ? (
515+ `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
516+ ) : `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
517+ void helpers . showAndLogErrorMessage ( errorMessage , { fullMessage : `${ errorMessage } \n${ err } ` } ) ;
518+ }
519519 }
520520
521521 }
0 commit comments