Skip to content

Commit 78d585b

Browse files
committed
Make temporary dir creation asynchronous
1 parent 000587c commit 78d585b

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -500,20 +500,24 @@ async function activateWithInstalledDistribution(
500500
const pathToQhelp = selectedQuery ? selectedQuery.path : window.activeTextEditor!.document.uri.fsPath;
501501
if(pathToQhelp) {
502502
// Create temporary directory
503-
const tmpDir = tmp.dirSync();
504-
const relativePathToMd = path.basename(pathToQhelp, '.qhelp') + '.md';
505-
const absolutePathToMd = path.join(tmpDir.name, 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);
515-
}
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);
515+
}
516+
// Manual cleanup
517+
void o.cleanup();
518+
});
516519
}
520+
517521
}
518522

519523
async function openReferencedFile(

0 commit comments

Comments
 (0)