Merge pull request #2210 from github/koesie10/base-typed-commands

Convert some base commands to typed commands
This commit is contained in:
Koen Vlaswinkel 2023-03-23 10:03:53 +01:00 коммит произвёл GitHub
Родитель 297fa2ebd3 a27ca2e177
Коммит 20f85f2b81
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 35 добавлений и 39 удалений

Просмотреть файл

@ -42,7 +42,10 @@ export type BuiltInVsCodeCommands = {
// Base commands not tied directly to a module like e.g. variant analysis.
export type BaseCommands = {
"codeQL.openDocumentation": () => Promise<void>;
"codeQL.showLogs": () => Promise<void>;
"codeQL.authenticateToGitHub": () => Promise<void>;
"codeQL.copyVersion": () => Promise<void>;
"codeQL.restartQueryServer": () => Promise<void>;
};

Просмотреть файл

@ -121,6 +121,7 @@ import {
} from "./local-queries";
import { getAstCfgCommands } from "./ast-cfg-commands";
import { getQueryEditorCommands } from "./query-editor";
import { App } from "./common/app";
/**
* extension.ts
@ -156,9 +157,18 @@ const extension = extensions.getExtension(extensionId);
* Return all commands that are not tied to the more specific managers.
*/
function getCommands(
app: App,
cliServer: CodeQLCliServer,
queryRunner: QueryRunner,
): BaseCommands {
const getCliVersion = async () => {
try {
return await cliServer.getVersion();
} catch {
return "<missing>";
}
};
return {
"codeQL.openDocumentation": async () => {
await env.openExternal(Uri.parse("https://codeql.github.com/docs/"));
@ -177,6 +187,27 @@ function getCommands(
title: "Restarting Query Server",
},
),
"codeQL.copyVersion": async () => {
const text = `CodeQL extension version: ${
extension?.packageJSON.version
} \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`;
await env.clipboard.writeText(text);
void showAndLogInformationMessage(text);
},
"codeQL.authenticateToGitHub": async () => {
/**
* Credentials for authenticating to GitHub.
* These are used when making API calls.
*/
const octokit = await app.credentials.getOctokit();
const userInfo = await octokit.users.getAuthenticated();
void showAndLogInformationMessage(
`Authenticated to GitHub as user: ${userInfo.data.login}`,
);
},
"codeQL.showLogs": async () => {
extLogger.show();
},
};
}
@ -841,7 +872,7 @@ async function activateWithInstalledDistribution(
void extLogger.log("Registering top-level command palette commands.");
const allCommands: AllExtensionCommands = {
...getCommands(cliServer, qs),
...getCommands(app, cliServer, qs),
...getQueryEditorCommands({
queryRunner: qs,
cliServer,
@ -896,44 +927,6 @@ async function activateWithInstalledDistribution(
);
}
ctx.subscriptions.push(
commandRunner("codeQL.copyVersion", async () => {
const text = `CodeQL extension version: ${
extension?.packageJSON.version
} \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`;
await env.clipboard.writeText(text);
void showAndLogInformationMessage(text);
}),
);
const getCliVersion = async () => {
try {
return await cliServer.getVersion();
} catch {
return "<missing>";
}
};
ctx.subscriptions.push(
commandRunner("codeQL.authenticateToGitHub", async () => {
/**
* Credentials for authenticating to GitHub.
* These are used when making API calls.
*/
const octokit = await app.credentials.getOctokit();
const userInfo = await octokit.users.getAuthenticated();
void showAndLogInformationMessage(
`Authenticated to GitHub as user: ${userInfo.data.login}`,
);
}),
);
ctx.subscriptions.push(
commandRunner("codeQL.showLogs", async () => {
extLogger.show();
}),
);
void extLogger.log("Starting language server.");
await client.start();
ctx.subscriptions.push({