@@ -136,6 +136,7 @@ import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filt
136136import { DbModule } from "./databases/db-module" ;
137137import { redactableError } from "./pure/errors" ;
138138import { QueryHistoryDirs } from "./query-history/query-history-dirs" ;
139+ import { DirResult } from "tmp" ;
139140
140141/**
141142 * extension.ts
@@ -744,32 +745,6 @@ async function activateWithInstalledDistribution(
744745 } ) ;
745746 ctx . subscriptions . push ( { dispose : qhelpTmpDir . removeCallback } ) ;
746747
747- async function previewQueryHelp ( selectedQuery : Uri ) : Promise < void > {
748- // selectedQuery is unpopulated when executing through the command palette
749- const pathToQhelp = selectedQuery
750- ? selectedQuery . fsPath
751- : window . activeTextEditor ?. document . uri . fsPath ;
752- if ( pathToQhelp ) {
753- // Create temporary directory
754- const relativePathToMd = `${ basename ( pathToQhelp , ".qhelp" ) } .md` ;
755- const absolutePathToMd = join ( qhelpTmpDir . name , relativePathToMd ) ;
756- const uri = Uri . file ( absolutePathToMd ) ;
757- try {
758- await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
759- await commands . executeCommand ( "markdown.showPreviewToSide" , uri ) ;
760- } catch ( e ) {
761- const errorMessage = getErrorMessage ( e ) . includes (
762- "Generating qhelp in markdown" ,
763- )
764- ? redactableError `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
765- : redactableError `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
766- void showAndLogExceptionWithTelemetry ( errorMessage , {
767- fullMessage : `${ errorMessage } \n${ getErrorMessage ( e ) } ` ,
768- } ) ;
769- }
770- }
771- }
772-
773748 async function openReferencedFile ( selectedQuery : Uri ) : Promise < void > {
774749 // If no file is selected, the path of the file in the editor is selected
775750 const path =
@@ -1316,7 +1291,9 @@ async function activateWithInstalledDistribution(
13161291 ) ;
13171292
13181293 ctx . subscriptions . push (
1319- commandRunner ( "codeQL.previewQueryHelp" , previewQueryHelp ) ,
1294+ commandRunner ( "codeQL.previewQueryHelp" , async ( selectedQuery : Uri ) => {
1295+ await previewQueryHelp ( cliServer , selectedQuery , qhelpTmpDir ) ;
1296+ } ) ,
13201297 ) ;
13211298
13221299 ctx . subscriptions . push (
@@ -1875,6 +1852,36 @@ async function compileAndRunQueryOnMultipleDatabases(
18751852 }
18761853}
18771854
1855+ async function previewQueryHelp (
1856+ cliServer : CodeQLCliServer ,
1857+ selectedQuery : Uri ,
1858+ qhelpTmpDir : DirResult ,
1859+ ) : Promise < void > {
1860+ // selectedQuery is unpopulated when executing through the command palette
1861+ const pathToQhelp = selectedQuery
1862+ ? selectedQuery . fsPath
1863+ : window . activeTextEditor ?. document . uri . fsPath ;
1864+ if ( pathToQhelp ) {
1865+ // Create temporary directory
1866+ const relativePathToMd = `${ basename ( pathToQhelp , ".qhelp" ) } .md` ;
1867+ const absolutePathToMd = join ( qhelpTmpDir . name , relativePathToMd ) ;
1868+ const uri = Uri . file ( absolutePathToMd ) ;
1869+ try {
1870+ await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
1871+ await commands . executeCommand ( "markdown.showPreviewToSide" , uri ) ;
1872+ } catch ( e ) {
1873+ const errorMessage = getErrorMessage ( e ) . includes (
1874+ "Generating qhelp in markdown" ,
1875+ )
1876+ ? redactableError `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
1877+ : redactableError `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
1878+ void showAndLogExceptionWithTelemetry ( errorMessage , {
1879+ fullMessage : `${ errorMessage } \n${ getErrorMessage ( e ) } ` ,
1880+ } ) ;
1881+ }
1882+ }
1883+ }
1884+
18781885function addUnhandledRejectionListener ( ) {
18791886 const handler = ( error : unknown ) => {
18801887 // This listener will be triggered for errors from other extensions as
0 commit comments