Merge pull request #2534 from github/nora/run-local-query-panel
Queries Panel: run local query from panel
This commit is contained in:
@@ -501,6 +501,11 @@
|
||||
"command": "codeQL.copyVersion",
|
||||
"title": "CodeQL: Copy Version Information"
|
||||
},
|
||||
{
|
||||
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
|
||||
"title": "Run local query",
|
||||
"icon": "$(run)"
|
||||
},
|
||||
{
|
||||
"command": "codeQLVariantAnalysisRepositories.openConfigFile",
|
||||
"title": "Open database configuration file",
|
||||
@@ -1095,6 +1100,11 @@
|
||||
"group": "1_queryHistory@1",
|
||||
"when": "viewItem == remoteResultsItem"
|
||||
},
|
||||
{
|
||||
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
|
||||
"group": "inline",
|
||||
"when": "view == codeQLQueries && viewItem == queryFile && codeQL.currentDatabaseItem"
|
||||
},
|
||||
{
|
||||
"command": "codeQLTests.showOutputDifferences",
|
||||
"group": "qltest@1",
|
||||
@@ -1154,6 +1164,10 @@
|
||||
"command": "codeQL.runQuery",
|
||||
"when": "resourceLangId == ql && resourceExtname == .ql"
|
||||
},
|
||||
{
|
||||
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "codeQL.runQueryContextEditor",
|
||||
"when": "false"
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
VariantAnalysisScannedRepositoryResult,
|
||||
} from "../variant-analysis/shared/variant-analysis";
|
||||
import type { QLDebugConfiguration } from "../debugger/debug-configuration";
|
||||
import type { 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
|
||||
@@ -129,6 +130,7 @@ export type LocalQueryCommands = {
|
||||
"codeQL.runQueryOnMultipleDatabasesContextEditor": (
|
||||
uri?: Uri,
|
||||
) => Promise<void>;
|
||||
"codeQLQueries.runLocalQueryFromQueriesPanel": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
|
||||
"codeQL.runQueries": ExplorerSelectionCommandFunction<Uri>;
|
||||
"codeQL.quickEval": (uri: Uri) => Promise<void>;
|
||||
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
|
||||
|
||||
@@ -48,6 +48,7 @@ import { SkeletonQueryWizard } from "../skeleton-query-wizard";
|
||||
import { LocalQueryRun } from "./local-query-run";
|
||||
import { createMultiSelectionCommand } from "../common/vscode/selection-commands";
|
||||
import { findLanguage } from "../codeql-cli/query-language";
|
||||
import { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
|
||||
|
||||
interface DatabaseQuickPickItem extends QuickPickItem {
|
||||
databaseItem: DatabaseItem;
|
||||
@@ -100,6 +101,8 @@ export class LocalQueries extends DisposableObject {
|
||||
this.runQueryOnMultipleDatabases.bind(this),
|
||||
"codeQL.runQueryOnMultipleDatabasesContextEditor":
|
||||
this.runQueryOnMultipleDatabases.bind(this),
|
||||
"codeQLQueries.runLocalQueryFromQueriesPanel":
|
||||
this.runQueryFromQueriesPanel.bind(this),
|
||||
"codeQL.runQueries": createMultiSelectionCommand(
|
||||
this.runQueries.bind(this),
|
||||
),
|
||||
@@ -118,6 +121,12 @@ export class LocalQueries extends DisposableObject {
|
||||
};
|
||||
}
|
||||
|
||||
private async runQueryFromQueriesPanel(
|
||||
queryTreeViewItem: QueryTreeViewItem,
|
||||
): Promise<void> {
|
||||
await this.runQuery(Uri.file(queryTreeViewItem.path));
|
||||
}
|
||||
|
||||
private async runQuery(uri: Uri | undefined): Promise<void> {
|
||||
await withProgress(
|
||||
async (progress, token) => {
|
||||
|
||||
@@ -8,14 +8,27 @@ import { QueryDiscovery } from "./query-discovery";
|
||||
import { QueryPackDiscovery } from "./query-pack-discovery";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private initialize(app: App, cliServer: CodeQLCliServer): void {
|
||||
// Currently, we only want to expose the new panel when we are in canary mode
|
||||
// and the user has enabled the "Show queries panel" flag.
|
||||
if (!isCanary() || !showQueriesPanel()) {
|
||||
// Currently, we only want to expose the new panel when we are in canary mode
|
||||
// and the user has enabled the "Show queries panel" flag.
|
||||
return;
|
||||
}
|
||||
void extLogger.log("Initializing queries panel.");
|
||||
@@ -31,18 +44,7 @@ export class QueriesModule extends DisposableObject {
|
||||
this.push(queryDiscovery);
|
||||
void queryDiscovery.initialRefresh();
|
||||
|
||||
const queriesPanel = new QueriesPanel(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;
|
||||
this.queriesPanel = new QueriesPanel(queryDiscovery);
|
||||
this.push(this.queriesPanel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as vscode from "vscode";
|
||||
import { DisposableObject } from "../common/disposable-object";
|
||||
import { QueryTreeDataProvider } from "./query-tree-data-provider";
|
||||
import { QueryDiscovery } from "./query-discovery";
|
||||
import { window } from "vscode";
|
||||
|
||||
export class QueriesPanel extends DisposableObject {
|
||||
public constructor(queryDiscovery: QueryDiscovery) {
|
||||
@@ -9,7 +9,7 @@ export class QueriesPanel extends DisposableObject {
|
||||
|
||||
const dataProvider = new QueryTreeDataProvider(queryDiscovery);
|
||||
|
||||
const treeView = vscode.window.createTreeView("codeQLQueries", {
|
||||
const treeView = window.createTreeView("codeQLQueries", {
|
||||
treeDataProvider: dataProvider,
|
||||
});
|
||||
this.push(treeView);
|
||||
|
||||
@@ -3,22 +3,23 @@ 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[],
|
||||
) {
|
||||
super(name);
|
||||
this.tooltip = path;
|
||||
this.description = language;
|
||||
this.collapsibleState = this.children.length
|
||||
? vscode.TreeItemCollapsibleState.Collapsed
|
||||
: vscode.TreeItemCollapsibleState.None;
|
||||
if (this.children.length === 0) {
|
||||
this.description = language;
|
||||
this.collapsibleState = vscode.TreeItemCollapsibleState.None;
|
||||
this.contextValue = "queryFile";
|
||||
this.command = {
|
||||
title: "Open",
|
||||
command: "vscode.open",
|
||||
arguments: [vscode.Uri.file(path)],
|
||||
};
|
||||
} else {
|
||||
this.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ describe("commands declared in package.json", () => {
|
||||
commandTitles[command] = title!;
|
||||
} else if (
|
||||
command.match(/^codeQLDatabases\./) ||
|
||||
command.match(/^codeQLQueries\./) ||
|
||||
command.match(/^codeQLVariantAnalysisRepositories\./) ||
|
||||
command.match(/^codeQLQueryHistory\./) ||
|
||||
command.match(/^codeQLAstViewer\./) ||
|
||||
|
||||
Reference in New Issue
Block a user