Merge pull request #2207 from github/robertbrignull/extension_commands
Start using app.commands.execute for all commands called from extension.ts
This commit is contained in:
@@ -32,6 +32,13 @@ export type SingleSelectionCommandFunction<Item> = (
|
|||||||
* the implementation in the corresponding `getCommands` function.
|
* the implementation in the corresponding `getCommands` function.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Builtin commands where the implementation is provided by VS Code and not by this extension.
|
||||||
|
// See https://code.visualstudio.com/api/references/commands
|
||||||
|
export type BuiltInVsCodeCommands = {
|
||||||
|
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
|
||||||
|
"workbench.action.reloadWindow": () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
// Base commands not tied directly to a module like e.g. variant analysis.
|
// Base commands not tied directly to a module like e.g. variant analysis.
|
||||||
export type BaseCommands = {
|
export type BaseCommands = {
|
||||||
"codeQL.openDocumentation": () => Promise<void>;
|
"codeQL.openDocumentation": () => Promise<void>;
|
||||||
@@ -230,7 +237,8 @@ export type MockGitHubApiServerCommands = {
|
|||||||
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
|
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AllCommands = BaseCommands &
|
// All commands where the implementation is provided by this extension.
|
||||||
|
export type AllExtensionCommands = BaseCommands &
|
||||||
QueryEditorCommands &
|
QueryEditorCommands &
|
||||||
ResultsViewCommands &
|
ResultsViewCommands &
|
||||||
QueryHistoryCommands &
|
QueryHistoryCommands &
|
||||||
@@ -245,6 +253,8 @@ export type AllCommands = BaseCommands &
|
|||||||
Partial<TestUICommands> &
|
Partial<TestUICommands> &
|
||||||
MockGitHubApiServerCommands;
|
MockGitHubApiServerCommands;
|
||||||
|
|
||||||
|
export type AllCommands = AllExtensionCommands & BuiltInVsCodeCommands;
|
||||||
|
|
||||||
export type AppCommandManager = CommandManager<AllCommands>;
|
export type AppCommandManager = CommandManager<AllCommands>;
|
||||||
|
|
||||||
// Separate command manager because it uses a different logger
|
// Separate command manager because it uses a different logger
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import "source-map-support/register";
|
import "source-map-support/register";
|
||||||
import {
|
import {
|
||||||
CancellationToken,
|
CancellationToken,
|
||||||
commands,
|
|
||||||
Disposable,
|
Disposable,
|
||||||
env,
|
env,
|
||||||
ExtensionContext,
|
ExtensionContext,
|
||||||
@@ -111,7 +110,7 @@ import { DbModule } from "./databases/db-module";
|
|||||||
import { redactableError } from "./pure/errors";
|
import { redactableError } from "./pure/errors";
|
||||||
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
|
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
|
||||||
import {
|
import {
|
||||||
AllCommands,
|
AllExtensionCommands,
|
||||||
BaseCommands,
|
BaseCommands,
|
||||||
QueryServerCommands,
|
QueryServerCommands,
|
||||||
TestUICommands,
|
TestUICommands,
|
||||||
@@ -266,6 +265,8 @@ export async function activate(
|
|||||||
addUnhandledRejectionListener();
|
addUnhandledRejectionListener();
|
||||||
install();
|
install();
|
||||||
|
|
||||||
|
const app = new ExtensionApp(ctx);
|
||||||
|
|
||||||
const codelensProvider = new QuickEvalCodeLensProvider();
|
const codelensProvider = new QuickEvalCodeLensProvider();
|
||||||
languages.registerCodeLensProvider(
|
languages.registerCodeLensProvider(
|
||||||
{ scheme: "file", language: "ql" },
|
{ scheme: "file", language: "ql" },
|
||||||
@@ -292,6 +293,7 @@ export async function activate(
|
|||||||
distributionConfigListener.onDidChangeConfiguration(() =>
|
distributionConfigListener.onDidChangeConfiguration(() =>
|
||||||
installOrUpdateThenTryActivate(
|
installOrUpdateThenTryActivate(
|
||||||
ctx,
|
ctx,
|
||||||
|
app,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
distributionConfigListener,
|
distributionConfigListener,
|
||||||
{
|
{
|
||||||
@@ -306,6 +308,7 @@ export async function activate(
|
|||||||
commandRunner(checkForUpdatesCommand, () =>
|
commandRunner(checkForUpdatesCommand, () =>
|
||||||
installOrUpdateThenTryActivate(
|
installOrUpdateThenTryActivate(
|
||||||
ctx,
|
ctx,
|
||||||
|
app,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
distributionConfigListener,
|
distributionConfigListener,
|
||||||
{
|
{
|
||||||
@@ -325,6 +328,7 @@ export async function activate(
|
|||||||
|
|
||||||
const codeQlExtension = await installOrUpdateThenTryActivate(
|
const codeQlExtension = await installOrUpdateThenTryActivate(
|
||||||
ctx,
|
ctx,
|
||||||
|
app,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
distributionConfigListener,
|
distributionConfigListener,
|
||||||
{
|
{
|
||||||
@@ -346,6 +350,7 @@ export async function activate(
|
|||||||
|
|
||||||
async function installOrUpdateDistributionWithProgressTitle(
|
async function installOrUpdateDistributionWithProgressTitle(
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
|
app: ExtensionApp,
|
||||||
distributionManager: DistributionManager,
|
distributionManager: DistributionManager,
|
||||||
progressTitle: string,
|
progressTitle: string,
|
||||||
config: DistributionUpdateConfig,
|
config: DistributionUpdateConfig,
|
||||||
@@ -390,7 +395,7 @@ async function installOrUpdateDistributionWithProgressTitle(
|
|||||||
"Restart and Upgrade",
|
"Restart and Upgrade",
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
await commands.executeCommand("workbench.action.reloadWindow");
|
await app.commands.execute("workbench.action.reloadWindow");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await withProgress(
|
await withProgress(
|
||||||
@@ -417,6 +422,7 @@ async function installOrUpdateDistributionWithProgressTitle(
|
|||||||
|
|
||||||
async function installOrUpdateDistribution(
|
async function installOrUpdateDistribution(
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
|
app: ExtensionApp,
|
||||||
distributionManager: DistributionManager,
|
distributionManager: DistributionManager,
|
||||||
config: DistributionUpdateConfig,
|
config: DistributionUpdateConfig,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@@ -437,6 +443,7 @@ async function installOrUpdateDistribution(
|
|||||||
try {
|
try {
|
||||||
await installOrUpdateDistributionWithProgressTitle(
|
await installOrUpdateDistributionWithProgressTitle(
|
||||||
ctx,
|
ctx,
|
||||||
|
app,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
messageText,
|
messageText,
|
||||||
config,
|
config,
|
||||||
@@ -522,11 +529,12 @@ async function getDistributionDisplayingDistributionWarnings(
|
|||||||
|
|
||||||
async function installOrUpdateThenTryActivate(
|
async function installOrUpdateThenTryActivate(
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
|
app: ExtensionApp,
|
||||||
distributionManager: DistributionManager,
|
distributionManager: DistributionManager,
|
||||||
distributionConfigListener: DistributionConfigListener,
|
distributionConfigListener: DistributionConfigListener,
|
||||||
config: DistributionUpdateConfig,
|
config: DistributionUpdateConfig,
|
||||||
): Promise<CodeQLExtensionInterface | Record<string, never>> {
|
): Promise<CodeQLExtensionInterface | Record<string, never>> {
|
||||||
await installOrUpdateDistribution(ctx, distributionManager, config);
|
await installOrUpdateDistribution(ctx, app, distributionManager, config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prepareCodeTour();
|
await prepareCodeTour();
|
||||||
@@ -546,6 +554,7 @@ async function installOrUpdateThenTryActivate(
|
|||||||
) {
|
) {
|
||||||
extensionInterface = await activateWithInstalledDistribution(
|
extensionInterface = await activateWithInstalledDistribution(
|
||||||
ctx,
|
ctx,
|
||||||
|
app,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
distributionConfigListener,
|
distributionConfigListener,
|
||||||
);
|
);
|
||||||
@@ -563,6 +572,7 @@ async function installOrUpdateThenTryActivate(
|
|||||||
if (chosenAction === installActionName) {
|
if (chosenAction === installActionName) {
|
||||||
await installOrUpdateThenTryActivate(
|
await installOrUpdateThenTryActivate(
|
||||||
ctx,
|
ctx,
|
||||||
|
app,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
distributionConfigListener,
|
distributionConfigListener,
|
||||||
{
|
{
|
||||||
@@ -589,6 +599,7 @@ const PACK_GLOBS = [
|
|||||||
|
|
||||||
async function activateWithInstalledDistribution(
|
async function activateWithInstalledDistribution(
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
|
app: ExtensionApp,
|
||||||
distributionManager: DistributionManager,
|
distributionManager: DistributionManager,
|
||||||
distributionConfigListener: DistributionConfigListener,
|
distributionConfigListener: DistributionConfigListener,
|
||||||
): Promise<CodeQLExtensionInterface> {
|
): Promise<CodeQLExtensionInterface> {
|
||||||
@@ -597,8 +608,6 @@ async function activateWithInstalledDistribution(
|
|||||||
// of activation.
|
// of activation.
|
||||||
errorStubs.forEach((stub) => stub.dispose());
|
errorStubs.forEach((stub) => stub.dispose());
|
||||||
|
|
||||||
const app = new ExtensionApp(ctx);
|
|
||||||
|
|
||||||
void extLogger.log("Initializing configuration listener...");
|
void extLogger.log("Initializing configuration listener...");
|
||||||
const qlConfigurationListener =
|
const qlConfigurationListener =
|
||||||
await QueryServerConfigListener.createQueryServerConfigListener(
|
await QueryServerConfigListener.createQueryServerConfigListener(
|
||||||
@@ -831,7 +840,7 @@ async function activateWithInstalledDistribution(
|
|||||||
|
|
||||||
void extLogger.log("Registering top-level command palette commands.");
|
void extLogger.log("Registering top-level command palette commands.");
|
||||||
|
|
||||||
const allCommands: AllCommands = {
|
const allCommands: AllExtensionCommands = {
|
||||||
...getCommands(cliServer, qs),
|
...getCommands(cliServer, qs),
|
||||||
...getQueryEditorCommands({
|
...getQueryEditorCommands({
|
||||||
queryRunner: qs,
|
queryRunner: qs,
|
||||||
@@ -864,7 +873,7 @@ async function activateWithInstalledDistribution(
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (const [commandName, command] of Object.entries(allCommands)) {
|
for (const [commandName, command] of Object.entries(allCommands)) {
|
||||||
app.commands.register(commandName as keyof AllCommands, command);
|
app.commands.register(commandName as keyof AllExtensionCommands, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryServerCommands: QueryServerCommands = {
|
const queryServerCommands: QueryServerCommands = {
|
||||||
@@ -955,7 +964,7 @@ async function activateWithInstalledDistribution(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
await commands.executeCommand("codeQLDatabases.removeOrphanedDatabases");
|
await app.commands.execute("codeQLDatabases.removeOrphanedDatabases");
|
||||||
|
|
||||||
void extLogger.log("Reading query history");
|
void extLogger.log("Reading query history");
|
||||||
await qhm.readQueryHistory();
|
await qhm.readQueryHistory();
|
||||||
|
|||||||
Reference in New Issue
Block a user