diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 759d40be9..db117e8ed 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -745,17 +745,6 @@ async function activateWithInstalledDistribution( }); ctx.subscriptions.push({ dispose: qhelpTmpDir.removeCallback }); - async function openReferencedFile(selectedQuery: Uri): Promise { - // If no file is selected, the path of the file in the editor is selected - const path = - selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath; - if (qs !== undefined && path) { - const resolved = await cliServer.resolveQlref(path); - const uri = Uri.file(resolved.resolvedPath); - await window.showTextDocument(uri, { preview: false }); - } - } - ctx.subscriptions.push(tmpDirDisposal); void extLogger.log("Initializing CodeQL language server."); @@ -1274,19 +1263,28 @@ async function activateWithInstalledDistribution( ); ctx.subscriptions.push( - commandRunner("codeQL.openReferencedFile", openReferencedFile), + commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => { + await openReferencedFile(qs, cliServer, selectedQuery); + }), ); // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command ctx.subscriptions.push( - commandRunner("codeQL.openReferencedFileContextEditor", openReferencedFile), + commandRunner( + "codeQL.openReferencedFileContextEditor", + async (selectedQuery: Uri) => { + await openReferencedFile(qs, cliServer, selectedQuery); + }, + ), ); // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command ctx.subscriptions.push( commandRunner( "codeQL.openReferencedFileContextExplorer", - openReferencedFile, + async (selectedQuery: Uri) => { + await openReferencedFile(qs, cliServer, selectedQuery); + }, ), ); @@ -1882,6 +1880,21 @@ async function previewQueryHelp( } } +async function openReferencedFile( + qs: QueryRunner, + cliServer: CodeQLCliServer, + selectedQuery: Uri, +): Promise { + // If no file is selected, the path of the file in the editor is selected + const path = + selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath; + if (qs !== undefined && path) { + const resolved = await cliServer.resolveQlref(path); + const uri = Uri.file(resolved.resolvedPath); + await window.showTextDocument(uri, { preview: false }); + } +} + function addUnhandledRejectionListener() { const handler = (error: unknown) => { // This listener will be triggered for errors from other extensions as