hook up new command and make runQuery executable
This commit is contained in:
@@ -12,6 +12,7 @@ import type {
|
||||
VariantAnalysisScannedRepositoryResult,
|
||||
} from "../variant-analysis/shared/variant-analysis";
|
||||
import type { QLDebugConfiguration } from "../debugger/debug-configuration";
|
||||
import { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
|
||||
|
||||
// A command function matching the signature that VS Code calls when
|
||||
// a command is invoked from a context menu on a TreeView with
|
||||
@@ -264,6 +265,10 @@ export type VariantAnalysisCommands = {
|
||||
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
|
||||
};
|
||||
|
||||
export type QueriesPanelCommands = {
|
||||
"codeQLQueries.runLocalQueryContextInline": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
|
||||
};
|
||||
|
||||
export type DatabasePanelCommands = {
|
||||
"codeQLVariantAnalysisRepositories.openConfigFile": () => Promise<void>;
|
||||
"codeQLVariantAnalysisRepositories.addNewDatabase": () => Promise<void>;
|
||||
@@ -333,6 +338,7 @@ export type AllExtensionCommands = BaseCommands &
|
||||
QueryHistoryCommands &
|
||||
LocalDatabasesCommands &
|
||||
DebuggerCommands &
|
||||
QueriesPanelCommands &
|
||||
VariantAnalysisCommands &
|
||||
DatabasePanelCommands &
|
||||
AstCfgCommands &
|
||||
@@ -346,7 +352,8 @@ export type AllExtensionCommands = BaseCommands &
|
||||
|
||||
export type AllCommands = AllExtensionCommands &
|
||||
PreActivationCommands &
|
||||
BuiltInVsCodeCommands;
|
||||
BuiltInVsCodeCommands &
|
||||
QueryServerCommands;
|
||||
|
||||
export type AppCommandManager = CommandManager<AllCommands>;
|
||||
|
||||
|
||||
@@ -779,7 +779,7 @@ async function activateWithInstalledDistribution(
|
||||
);
|
||||
ctx.subscriptions.push(databaseUI);
|
||||
|
||||
QueriesModule.initialize(app, cliServer);
|
||||
const queriesModule = QueriesModule.initialize(app, cliServer);
|
||||
|
||||
void extLogger.log("Initializing evaluator log viewer.");
|
||||
const evalLogViewer = new EvalLogViewer();
|
||||
@@ -1011,6 +1011,7 @@ async function activateWithInstalledDistribution(
|
||||
}),
|
||||
...localQueryResultsView.getCommands(),
|
||||
...qhm.getCommands(),
|
||||
...queriesModule.getCommands(),
|
||||
...variantAnalysisManager.getCommands(),
|
||||
...databaseUI.getCommands(),
|
||||
...dbModule.getCommands(),
|
||||
|
||||
@@ -6,12 +6,36 @@ import { DisposableObject } from "../common/disposable-object";
|
||||
import { QueriesPanel } from "./queries-panel";
|
||||
import { QueryDiscovery } from "./query-discovery";
|
||||
import { QueryPackDiscovery } from "./query-pack-discovery";
|
||||
import { QueriesPanelCommands } from "../common/commands";
|
||||
|
||||
export class QueriesModule extends DisposableObject {
|
||||
private queriesPanel: QueriesPanel | undefined;
|
||||
|
||||
private constructor(readonly app: App) {
|
||||
super();
|
||||
}
|
||||
|
||||
public static initialize(
|
||||
app: App,
|
||||
cliServer: CodeQLCliServer,
|
||||
): QueriesModule {
|
||||
const queriesModule = new QueriesModule(app);
|
||||
app.subscriptions.push(queriesModule);
|
||||
|
||||
queriesModule.initialize(app, cliServer);
|
||||
return queriesModule;
|
||||
}
|
||||
|
||||
public getCommands(): QueriesPanelCommands {
|
||||
if (!this.queriesPanel) {
|
||||
throw new Error("Queries panel not initialized");
|
||||
}
|
||||
|
||||
return {
|
||||
...this.queriesPanel.getCommands(),
|
||||
};
|
||||
}
|
||||
|
||||
private initialize(app: App, cliServer: CodeQLCliServer): void {
|
||||
if (!isCanary() || !showQueriesPanel()) {
|
||||
// Currently, we only want to expose the new panel when we are in canary mode
|
||||
@@ -31,18 +55,7 @@ export class QueriesModule extends DisposableObject {
|
||||
this.push(queryDiscovery);
|
||||
void queryDiscovery.initialRefresh();
|
||||
|
||||
const queriesPanel = new QueriesPanel(queryDiscovery);
|
||||
const queriesPanel = new QueriesPanel(app, queryDiscovery);
|
||||
this.push(queriesPanel);
|
||||
}
|
||||
|
||||
public static initialize(
|
||||
app: App,
|
||||
cliServer: CodeQLCliServer,
|
||||
): QueriesModule {
|
||||
const queriesModule = new QueriesModule(app);
|
||||
app.subscriptions.push(queriesModule);
|
||||
|
||||
queriesModule.initialize(app, cliServer);
|
||||
return queriesModule;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,15 @@ import * as vscode from "vscode";
|
||||
import { DisposableObject } from "../common/disposable-object";
|
||||
import { QueryTreeDataProvider } from "./query-tree-data-provider";
|
||||
import { QueryDiscovery } from "./query-discovery";
|
||||
import { QueriesPanelCommands } from "../common/commands";
|
||||
import { QueryTreeViewItem } from "./query-tree-view-item";
|
||||
import { App } from "../common/app";
|
||||
|
||||
export class QueriesPanel extends DisposableObject {
|
||||
public constructor(queryDiscovery: QueryDiscovery) {
|
||||
public constructor(
|
||||
private readonly app: App,
|
||||
queryDiscovery: QueryDiscovery,
|
||||
) {
|
||||
super();
|
||||
|
||||
const dataProvider = new QueryTreeDataProvider(queryDiscovery);
|
||||
@@ -14,4 +20,19 @@ export class QueriesPanel extends DisposableObject {
|
||||
});
|
||||
this.push(treeView);
|
||||
}
|
||||
|
||||
public getCommands(): QueriesPanelCommands {
|
||||
return {
|
||||
"codeQLQueries.runLocalQueryContextInline": this.runLocalQuery.bind(this),
|
||||
};
|
||||
}
|
||||
|
||||
private async runLocalQuery(
|
||||
queryTreeViewItem: QueryTreeViewItem,
|
||||
): Promise<void> {
|
||||
await this.app.commands.execute(
|
||||
"codeQL.runQuery",
|
||||
vscode.Uri.parse(queryTreeViewItem.path),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as vscode from "vscode";
|
||||
export class QueryTreeViewItem extends vscode.TreeItem {
|
||||
constructor(
|
||||
name: string,
|
||||
path: string,
|
||||
public readonly path: string,
|
||||
language: string | undefined,
|
||||
public readonly children: QueryTreeViewItem[],
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user