Skip to content

Commit 655294d

Browse files
committed
Use only one command
1 parent 5845e9e commit 655294d

File tree

10 files changed

+26
-83
lines changed

10 files changed

+26
-83
lines changed

extensions/ql-vscode/package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@
405405
"command": "codeQL.runQueryContextEditor",
406406
"title": "CodeQL: Run Query on Selected Database"
407407
},
408-
{
409-
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
410-
"title": "Run Query on Selected Database"
411-
},
412408
{
413409
"command": "codeQL.debugQuery",
414410
"title": "CodeQL: Debug Query"
@@ -506,7 +502,7 @@
506502
"title": "CodeQL: Copy Version Information"
507503
},
508504
{
509-
"command": "codeQLQueries.runLocalQueryContextInline",
505+
"command": "codeQL.runLocalQueryFromQueriesPanel",
510506
"title": "Run local query",
511507
"icon": "$(run)"
512508
},
@@ -1105,7 +1101,7 @@
11051101
"when": "viewItem == remoteResultsItem"
11061102
},
11071103
{
1108-
"command": "codeQLQueries.runLocalQueryContextInline",
1104+
"command": "codeQL.runLocalQueryFromQueriesPanel",
11091105
"group": "inline",
11101106
"when": "view == codeQLQueries && viewItem == queryFile && codeQL.currentDatabaseItem"
11111107
},
@@ -1169,7 +1165,7 @@
11691165
"when": "resourceLangId == ql && resourceExtname == .ql"
11701166
},
11711167
{
1172-
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
1168+
"command": "codeQL.runLocalQueryFromQueriesPanel",
11731169
"when": "false"
11741170
},
11751171
{
@@ -1292,10 +1288,6 @@
12921288
"command": "codeQL.openDataExtensionsEditor",
12931289
"when": "config.codeQL.canary && config.codeQL.dataExtensions.editor"
12941290
},
1295-
{
1296-
"command": "codeQLQueries.runLocalQueryContextInline",
1297-
"when": "false"
1298-
},
12991291
{
13001292
"command": "codeQLVariantAnalysisRepositories.openConfigFile",
13011293
"when": "false"

extensions/ql-vscode/src/common/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Disposable } from "./disposable-object";
33
import { AppEventEmitter } from "./events";
44
import { NotificationLogger } from "./logging";
55
import { Memento } from "./memento";
6-
import { AppCommandManager, QueryServerCommandManager } from "./commands";
6+
import { AppCommandManager } from "./commands";
77
import { AppTelemetry } from "./telemetry";
88

99
export interface App {
@@ -18,7 +18,6 @@ export interface App {
1818
readonly workspaceState: Memento;
1919
readonly credentials: Credentials;
2020
readonly commands: AppCommandManager;
21-
readonly queryServerCommands: QueryServerCommandManager;
2221
readonly environment: EnvironmentContext;
2322
}
2423

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export type LocalQueryCommands = {
130130
"codeQL.runQueryOnMultipleDatabasesContextEditor": (
131131
uri?: Uri,
132132
) => Promise<void>;
133-
"codeQLQueries.runLocalQueryFromQueriesPanel": (uri?: Uri) => Promise<void>;
133+
"codeQL.runLocalQueryFromQueriesPanel": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
134134
"codeQL.runQueries": ExplorerSelectionCommandFunction<Uri>;
135135
"codeQL.quickEval": (uri: Uri) => Promise<void>;
136136
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
@@ -266,10 +266,6 @@ export type VariantAnalysisCommands = {
266266
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
267267
};
268268

269-
export type QueriesPanelCommands = {
270-
"codeQLQueries.runLocalQueryContextInline": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
271-
};
272-
273269
export type DatabasePanelCommands = {
274270
"codeQLVariantAnalysisRepositories.openConfigFile": () => Promise<void>;
275271
"codeQLVariantAnalysisRepositories.addNewDatabase": () => Promise<void>;
@@ -339,7 +335,6 @@ export type AllExtensionCommands = BaseCommands &
339335
QueryHistoryCommands &
340336
LocalDatabasesCommands &
341337
DebuggerCommands &
342-
QueriesPanelCommands &
343338
VariantAnalysisCommands &
344339
DatabasePanelCommands &
345340
AstCfgCommands &

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ async function activateWithInstalledDistribution(
779779
);
780780
ctx.subscriptions.push(databaseUI);
781781

782-
const queriesModule = QueriesModule.initialize(app, cliServer);
782+
QueriesModule.initialize(app, cliServer);
783783

784784
void extLogger.log("Initializing evaluator log viewer.");
785785
const evalLogViewer = new EvalLogViewer();
@@ -1011,7 +1011,6 @@ async function activateWithInstalledDistribution(
10111011
}),
10121012
...localQueryResultsView.getCommands(),
10131013
...qhm.getCommands(),
1014-
...queriesModule.getCommands(),
10151014
...variantAnalysisManager.getCommands(),
10161015
...databaseUI.getCommands(),
10171016
...dbModule.getCommands(),

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { SkeletonQueryWizard } from "../skeleton-query-wizard";
4848
import { LocalQueryRun } from "./local-query-run";
4949
import { createMultiSelectionCommand } from "../common/vscode/selection-commands";
5050
import { findLanguage } from "../codeql-cli/query-language";
51+
import { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
5152

5253
interface DatabaseQuickPickItem extends QuickPickItem {
5354
databaseItem: DatabaseItem;
@@ -100,7 +101,8 @@ export class LocalQueries extends DisposableObject {
100101
this.runQueryOnMultipleDatabases.bind(this),
101102
"codeQL.runQueryOnMultipleDatabasesContextEditor":
102103
this.runQueryOnMultipleDatabases.bind(this),
103-
"codeQLQueries.runLocalQueryFromQueriesPanel": this.runQuery.bind(this),
104+
"codeQL.runLocalQueryFromQueriesPanel":
105+
this.runQueryFromQueriesPanel.bind(this),
104106
"codeQL.runQueries": createMultiSelectionCommand(
105107
this.runQueries.bind(this),
106108
),
@@ -119,6 +121,12 @@ export class LocalQueries extends DisposableObject {
119121
};
120122
}
121123

124+
private async runQueryFromQueriesPanel(
125+
queryTreeViewItem: QueryTreeViewItem,
126+
): Promise<void> {
127+
await this.runQuery(Uri.file(queryTreeViewItem.path));
128+
}
129+
122130
private async runQuery(uri: Uri | undefined): Promise<void> {
123131
await withProgress(
124132
async (progress, token) => {

extensions/ql-vscode/src/queries-panel/queries-module.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { DisposableObject } from "../common/disposable-object";
66
import { QueriesPanel } from "./queries-panel";
77
import { QueryDiscovery } from "./query-discovery";
88
import { QueryPackDiscovery } from "./query-pack-discovery";
9-
import { QueriesPanelCommands } from "../common/commands";
109

1110
export class QueriesModule extends DisposableObject {
1211
private queriesPanel: QueriesPanel | undefined;
@@ -26,24 +25,10 @@ export class QueriesModule extends DisposableObject {
2625
return queriesModule;
2726
}
2827

29-
public getCommands(): QueriesPanelCommands {
30-
if (!this.shouldInitializeQueriesPanel()) {
31-
return {
32-
"codeQLQueries.runLocalQueryContextInline": () => Promise.resolve(),
33-
};
34-
}
35-
36-
if (!this.queriesPanel) {
37-
throw new Error("Queries panel not initialized");
38-
}
39-
40-
return {
41-
...this.queriesPanel.getCommands(),
42-
};
43-
}
44-
4528
private initialize(app: App, cliServer: CodeQLCliServer): void {
46-
if (!this.shouldInitializeQueriesPanel) {
29+
// Currently, we only want to expose the new panel when we are in canary mode
30+
// and the user has enabled the "Show queries panel" flag.
31+
if (!isCanary() || !showQueriesPanel()) {
4732
return;
4833
}
4934
void extLogger.log("Initializing queries panel.");
@@ -59,13 +44,7 @@ export class QueriesModule extends DisposableObject {
5944
this.push(queryDiscovery);
6045
void queryDiscovery.initialRefresh();
6146

62-
this.queriesPanel = new QueriesPanel(app, queryDiscovery);
47+
this.queriesPanel = new QueriesPanel(queryDiscovery);
6348
this.push(this.queriesPanel);
6449
}
65-
66-
private shouldInitializeQueriesPanel(): boolean {
67-
// Currently, we only want to expose the new panel when we are in canary mode
68-
// and the user has enabled the "Show queries panel" flag.
69-
return isCanary() && showQueriesPanel();
70-
}
7150
}
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import { DisposableObject } from "../common/disposable-object";
22
import { QueryTreeDataProvider } from "./query-tree-data-provider";
33
import { QueryDiscovery } from "./query-discovery";
4-
import { QueriesPanelCommands } from "../common/commands";
5-
import { QueryTreeViewItem } from "./query-tree-view-item";
6-
import { App } from "../common/app";
7-
import { Uri, window } from "vscode";
4+
import { window } from "vscode";
85

96
export class QueriesPanel extends DisposableObject {
10-
public constructor(
11-
private readonly app: App,
12-
queryDiscovery: QueryDiscovery,
13-
) {
7+
public constructor(queryDiscovery: QueryDiscovery) {
148
super();
159

1610
const dataProvider = new QueryTreeDataProvider(queryDiscovery);
@@ -20,19 +14,4 @@ export class QueriesPanel extends DisposableObject {
2014
});
2115
this.push(treeView);
2216
}
23-
24-
public getCommands(): QueriesPanelCommands {
25-
return {
26-
"codeQLQueries.runLocalQueryContextInline": this.runLocalQuery.bind(this),
27-
};
28-
}
29-
30-
private async runLocalQuery(
31-
queryTreeViewItem: QueryTreeViewItem,
32-
): Promise<void> {
33-
await this.app.queryServerCommands.execute(
34-
"codeQLQueries.runLocalQueryFromQueriesPanel",
35-
Uri.file(queryTreeViewItem.path),
36-
);
37-
}
3817
}

extensions/ql-vscode/test/__mocks__/appMock.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { createMockLogger } from "./loggerMock";
66
import { createMockMemento } from "../mock-memento";
77
import { testCredentialsWithStub } from "../factories/authentication";
88
import { Credentials } from "../../src/common/authentication";
9-
import {
10-
AppCommandManager,
11-
QueryServerCommandManager,
12-
} from "../../src/common/commands";
9+
import { AppCommandManager } from "../../src/common/commands";
1310
import { createMockCommandManager } from "./commandsMock";
1411
import { NotificationLogger } from "../../src/common/logging";
1512
import { AppTelemetry } from "../../src/common/telemetry";
@@ -23,7 +20,6 @@ export function createMockApp({
2320
workspaceState = createMockMemento(),
2421
credentials = testCredentialsWithStub(),
2522
commands = createMockCommandManager(),
26-
queryServerCommands = createMockCommandManager(),
2723
environment = createMockEnvironmentContext(),
2824
logger = createMockLogger(),
2925
telemetry = createMockTelemetryReporter(),
@@ -35,7 +31,6 @@ export function createMockApp({
3531
workspaceState?: Memento;
3632
credentials?: Credentials;
3733
commands?: AppCommandManager;
38-
queryServerCommands?: QueryServerCommandManager;
3934
environment?: EnvironmentContext;
4035
logger?: NotificationLogger;
4136
telemetry?: AppTelemetry;
@@ -52,7 +47,6 @@ export function createMockApp({
5247
createEventEmitter,
5348
credentials,
5449
commands,
55-
queryServerCommands,
5650
environment,
5751
};
5852
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import { AppCommandManager } from "../../src/common/commands";
12
import { CommandFunction, CommandManager } from "../../src/packages/commands";
23
import { Disposable } from "../../src/packages/commands/Disposable";
34

4-
export function createMockCommandManager<
5-
Commands extends Record<string, CommandFunction>,
6-
>({
5+
export function createMockCommandManager({
76
registerCommand = jest.fn(),
87
executeCommand = jest.fn(),
98
}: {
109
registerCommand?: (commandName: string, fn: CommandFunction) => Disposable;
1110
executeCommand?: (commandName: string, ...args: any[]) => Promise<any>;
12-
} = {}): CommandManager<Commands> {
13-
return new CommandManager<Commands>(registerCommand, executeCommand);
11+
} = {}): AppCommandManager {
12+
return new CommandManager(registerCommand, executeCommand);
1413
}

extensions/ql-vscode/test/unit-tests/command-lint.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe("commands declared in package.json", () => {
4141
command.match(/^codeQLDatabases\./) ||
4242
command.match(/^codeQLVariantAnalysisRepositories\./) ||
4343
command.match(/^codeQLQueryHistory\./) ||
44-
command.match(/^codeQLQueries\./) ||
4544
command.match(/^codeQLAstViewer\./) ||
4645
command.match(/^codeQLEvalLogViewer\./) ||
4746
command.match(/^codeQLTests\./)

0 commit comments

Comments
 (0)