Skip to content

Commit 9d59abd

Browse files
Move openReferencedFile to top level
1 parent 165542d commit 9d59abd

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,6 @@ async function activateWithInstalledDistribution(
745745
});
746746
ctx.subscriptions.push({ dispose: qhelpTmpDir.removeCallback });
747747

748-
async function openReferencedFile(selectedQuery: Uri): Promise<void> {
749-
// If no file is selected, the path of the file in the editor is selected
750-
const path =
751-
selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath;
752-
if (qs !== undefined && path) {
753-
const resolved = await cliServer.resolveQlref(path);
754-
const uri = Uri.file(resolved.resolvedPath);
755-
await window.showTextDocument(uri, { preview: false });
756-
}
757-
}
758-
759748
ctx.subscriptions.push(tmpDirDisposal);
760749

761750
void extLogger.log("Initializing CodeQL language server.");
@@ -1274,19 +1263,28 @@ async function activateWithInstalledDistribution(
12741263
);
12751264

12761265
ctx.subscriptions.push(
1277-
commandRunner("codeQL.openReferencedFile", openReferencedFile),
1266+
commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => {
1267+
await openReferencedFile(qs, cliServer, selectedQuery);
1268+
}),
12781269
);
12791270

12801271
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
12811272
ctx.subscriptions.push(
1282-
commandRunner("codeQL.openReferencedFileContextEditor", openReferencedFile),
1273+
commandRunner(
1274+
"codeQL.openReferencedFileContextEditor",
1275+
async (selectedQuery: Uri) => {
1276+
await openReferencedFile(qs, cliServer, selectedQuery);
1277+
},
1278+
),
12831279
);
12841280

12851281
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
12861282
ctx.subscriptions.push(
12871283
commandRunner(
12881284
"codeQL.openReferencedFileContextExplorer",
1289-
openReferencedFile,
1285+
async (selectedQuery: Uri) => {
1286+
await openReferencedFile(qs, cliServer, selectedQuery);
1287+
},
12901288
),
12911289
);
12921290

@@ -1882,6 +1880,21 @@ async function previewQueryHelp(
18821880
}
18831881
}
18841882

1883+
async function openReferencedFile(
1884+
qs: QueryRunner,
1885+
cliServer: CodeQLCliServer,
1886+
selectedQuery: Uri,
1887+
): Promise<void> {
1888+
// If no file is selected, the path of the file in the editor is selected
1889+
const path =
1890+
selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath;
1891+
if (qs !== undefined && path) {
1892+
const resolved = await cliServer.resolveQlref(path);
1893+
const uri = Uri.file(resolved.resolvedPath);
1894+
await window.showTextDocument(uri, { preview: false });
1895+
}
1896+
}
1897+
18851898
function addUnhandledRejectionListener() {
18861899
const handler = (error: unknown) => {
18871900
// This listener will be triggered for errors from other extensions as

0 commit comments

Comments
 (0)