Merge pull request #2190 from github/koesie10/typed-new-database-panel-commands
Convert new database panel to typed commands
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import type { CommandManager } from "../packages/commands";
|
import type { CommandManager } from "../packages/commands";
|
||||||
import type { Uri } from "vscode";
|
import type { Uri } from "vscode";
|
||||||
|
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
|
||||||
import type { QueryHistoryInfo } from "../query-history/query-history-info";
|
import type { QueryHistoryInfo } from "../query-history/query-history-info";
|
||||||
|
|
||||||
// A command function matching the signature that VS Code calls when
|
// A command function matching the signature that VS Code calls when
|
||||||
@@ -9,6 +10,12 @@ export type SelectionCommandFunction<Item> = (
|
|||||||
multiSelect: Item[],
|
multiSelect: Item[],
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
|
||||||
|
// A command function matching the signature that VS Code calls when
|
||||||
|
// a command on a selection is invoked when canSelectMany is false.
|
||||||
|
export type SingleSelectionCommandFunction<Item> = (
|
||||||
|
singleItem: Item,
|
||||||
|
) => Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains type definitions for all commands used by the extension.
|
* Contains type definitions for all commands used by the extension.
|
||||||
*
|
*
|
||||||
@@ -62,8 +69,22 @@ export type VariantAnalysisCommands = {
|
|||||||
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
|
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DatabasePanelCommands = {
|
||||||
|
"codeQLVariantAnalysisRepositories.openConfigFile": () => Promise<void>;
|
||||||
|
"codeQLVariantAnalysisRepositories.addNewDatabase": () => Promise<void>;
|
||||||
|
"codeQLVariantAnalysisRepositories.addNewList": () => Promise<void>;
|
||||||
|
"codeQLVariantAnalysisRepositories.setupControllerRepository": () => Promise<void>;
|
||||||
|
|
||||||
|
"codeQLVariantAnalysisRepositories.setSelectedItem": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||||
|
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||||
|
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||||
|
"codeQLVariantAnalysisRepositories.renameItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||||
|
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
|
||||||
|
};
|
||||||
|
|
||||||
export type AllCommands = BaseCommands &
|
export type AllCommands = BaseCommands &
|
||||||
QueryHistoryCommands &
|
QueryHistoryCommands &
|
||||||
VariantAnalysisCommands;
|
VariantAnalysisCommands &
|
||||||
|
DatabasePanelCommands;
|
||||||
|
|
||||||
export type AppCommandManager = CommandManager<AllCommands>;
|
export type AppCommandManager = CommandManager<AllCommands>;
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import { DbConfigStore } from "./config/db-config-store";
|
|||||||
import { DbManager } from "./db-manager";
|
import { DbManager } from "./db-manager";
|
||||||
import { DbPanel } from "./ui/db-panel";
|
import { DbPanel } from "./ui/db-panel";
|
||||||
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
|
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
|
||||||
|
import { DatabasePanelCommands } from "../common/commands";
|
||||||
|
|
||||||
export class DbModule extends DisposableObject {
|
export class DbModule extends DisposableObject {
|
||||||
public readonly dbManager: DbManager;
|
public readonly dbManager: DbManager;
|
||||||
private readonly dbConfigStore: DbConfigStore;
|
private readonly dbConfigStore: DbConfigStore;
|
||||||
|
private dbPanel: DbPanel | undefined;
|
||||||
|
|
||||||
private constructor(app: App) {
|
private constructor(app: App) {
|
||||||
super();
|
super();
|
||||||
@@ -26,15 +28,24 @@ export class DbModule extends DisposableObject {
|
|||||||
return dbModule;
|
return dbModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getCommands(): DatabasePanelCommands {
|
||||||
|
if (!this.dbPanel) {
|
||||||
|
throw new Error("Database panel not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...this.dbPanel.getCommands(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private async initialize(app: App): Promise<void> {
|
private async initialize(app: App): Promise<void> {
|
||||||
void extLogger.log("Initializing database module");
|
void extLogger.log("Initializing database module");
|
||||||
|
|
||||||
await this.dbConfigStore.initialize();
|
await this.dbConfigStore.initialize();
|
||||||
|
|
||||||
const dbPanel = new DbPanel(this.dbManager, app.credentials);
|
this.dbPanel = new DbPanel(this.dbManager, app.credentials);
|
||||||
await dbPanel.initialize();
|
|
||||||
|
|
||||||
this.push(dbPanel);
|
this.push(this.dbPanel);
|
||||||
this.push(this.dbConfigStore);
|
this.push(this.dbConfigStore);
|
||||||
|
|
||||||
const dbSelectionDecorationProvider = new DbSelectionDecorationProvider();
|
const dbSelectionDecorationProvider = new DbSelectionDecorationProvider();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
window,
|
window,
|
||||||
workspace,
|
workspace,
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
import { commandRunner, UserCancellationException } from "../../commandRunner";
|
import { UserCancellationException } from "../../commandRunner";
|
||||||
import {
|
import {
|
||||||
getNwoFromGitHubUrl,
|
getNwoFromGitHubUrl,
|
||||||
isValidGitHubNwo,
|
isValidGitHubNwo,
|
||||||
@@ -32,6 +32,7 @@ import { getGitHubUrl } from "./db-tree-view-item-action";
|
|||||||
import { getControllerRepo } from "../../variant-analysis/run-remote-query";
|
import { getControllerRepo } from "../../variant-analysis/run-remote-query";
|
||||||
import { getErrorMessage } from "../../pure/helpers-pure";
|
import { getErrorMessage } from "../../pure/helpers-pure";
|
||||||
import { Credentials } from "../../common/authentication";
|
import { Credentials } from "../../common/authentication";
|
||||||
|
import { DatabasePanelCommands } from "../../common/commands";
|
||||||
|
|
||||||
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
|
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
|
||||||
kind: string;
|
kind: string;
|
||||||
@@ -72,58 +73,28 @@ export class DbPanel extends DisposableObject {
|
|||||||
this.push(this.treeView);
|
this.push(this.treeView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initialize(): Promise<void> {
|
public getCommands(): DatabasePanelCommands {
|
||||||
this.push(
|
return {
|
||||||
commandRunner("codeQLVariantAnalysisRepositories.openConfigFile", () =>
|
"codeQLVariantAnalysisRepositories.openConfigFile":
|
||||||
this.openConfigFile(),
|
this.openConfigFile.bind(this),
|
||||||
),
|
"codeQLVariantAnalysisRepositories.addNewDatabase":
|
||||||
);
|
this.addNewRemoteDatabase.bind(this),
|
||||||
this.push(
|
"codeQLVariantAnalysisRepositories.addNewList":
|
||||||
commandRunner("codeQLVariantAnalysisRepositories.addNewDatabase", () =>
|
this.addNewList.bind(this),
|
||||||
this.addNewRemoteDatabase(),
|
"codeQLVariantAnalysisRepositories.setupControllerRepository":
|
||||||
),
|
this.setupControllerRepository.bind(this),
|
||||||
);
|
|
||||||
this.push(
|
"codeQLVariantAnalysisRepositories.setSelectedItem":
|
||||||
commandRunner("codeQLVariantAnalysisRepositories.addNewList", () =>
|
this.setSelectedItem.bind(this),
|
||||||
this.addNewList(),
|
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu":
|
||||||
),
|
this.setSelectedItem.bind(this),
|
||||||
);
|
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu":
|
||||||
this.push(
|
this.openOnGitHub.bind(this),
|
||||||
commandRunner(
|
"codeQLVariantAnalysisRepositories.renameItemContextMenu":
|
||||||
"codeQLVariantAnalysisRepositories.setSelectedItem",
|
this.renameItem.bind(this),
|
||||||
(treeViewItem: DbTreeViewItem) => this.setSelectedItem(treeViewItem),
|
"codeQLVariantAnalysisRepositories.removeItemContextMenu":
|
||||||
),
|
this.removeItem.bind(this),
|
||||||
);
|
};
|
||||||
this.push(
|
|
||||||
commandRunner(
|
|
||||||
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
|
|
||||||
(treeViewItem: DbTreeViewItem) => this.setSelectedItem(treeViewItem),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
this.push(
|
|
||||||
commandRunner(
|
|
||||||
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu",
|
|
||||||
(treeViewItem: DbTreeViewItem) => this.openOnGitHub(treeViewItem),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
this.push(
|
|
||||||
commandRunner(
|
|
||||||
"codeQLVariantAnalysisRepositories.renameItemContextMenu",
|
|
||||||
(treeViewItem: DbTreeViewItem) => this.renameItem(treeViewItem),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
this.push(
|
|
||||||
commandRunner(
|
|
||||||
"codeQLVariantAnalysisRepositories.removeItemContextMenu",
|
|
||||||
(treeViewItem: DbTreeViewItem) => this.removeItem(treeViewItem),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
this.push(
|
|
||||||
commandRunner(
|
|
||||||
"codeQLVariantAnalysisRepositories.setupControllerRepository",
|
|
||||||
() => this.setupControllerRepository(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async openConfigFile(): Promise<void> {
|
private async openConfigFile(): Promise<void> {
|
||||||
|
|||||||
@@ -1096,6 +1096,7 @@ async function activateWithInstalledDistribution(
|
|||||||
...getCommands(),
|
...getCommands(),
|
||||||
...qhm.getCommands(),
|
...qhm.getCommands(),
|
||||||
...variantAnalysisManager.getCommands(),
|
...variantAnalysisManager.getCommands(),
|
||||||
|
...dbModule.getCommands(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [commandName, command] of Object.entries(allCommands)) {
|
for (const [commandName, command] of Object.entries(allCommands)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user