Skip to content

Commit ac57f50

Browse files
committed
Convert results view commands to typed commands
1 parent 88a9ecb commit ac57f50

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ export type LocalQueryCommands = {
5353
"codeQL.quickQuery": () => Promise<void>;
5454
};
5555

56+
export type ResultsViewCommands = {
57+
"codeQLQueryResults.up": () => Promise<void>;
58+
"codeQLQueryResults.down": () => Promise<void>;
59+
"codeQLQueryResults.left": () => Promise<void>;
60+
"codeQLQueryResults.right": () => Promise<void>;
61+
"codeQLQueryResults.nextPathStep": () => Promise<void>;
62+
"codeQLQueryResults.previousPathStep": () => Promise<void>;
63+
};
64+
5665
// Commands used for the query history panel
5766
export type QueryHistoryCommands = {
5867
// Commands in the "navigation" group
@@ -196,6 +205,7 @@ export type SummaryLanguageSupportCommands = {
196205
};
197206

198207
export type AllCommands = BaseCommands &
208+
ResultsViewCommands &
199209
QueryHistoryCommands &
200210
LocalDatabasesCommands &
201211
VariantAnalysisCommands &

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ async function activateWithInstalledDistribution(
826826

827827
const allCommands: AllCommands = {
828828
...getCommands(cliServer, qs),
829+
...localQueryResultsView.getCommands(),
829830
...qhm.getCommands(),
830831
...variantAnalysisManager.getCommands(),
831832
...databaseUI.getCommands(),

extensions/ql-vscode/src/interface.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
ParsedResultSets,
4343
} from "./pure/interface-types";
4444
import { Logger } from "./common";
45-
import { commandRunner } from "./commandRunner";
4645
import {
4746
CompletedQueryInfo,
4847
interpretResultsSarif,
@@ -72,6 +71,7 @@ import { isCanary, PAGE_SIZE } from "./config";
7271
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
7372
import { telemetryListener } from "./telemetry";
7473
import { redactableError } from "./pure/errors";
74+
import { ResultsViewCommands } from "./common/commands";
7575

7676
/**
7777
* interface.ts
@@ -179,21 +179,6 @@ export class ResultsView extends AbstractWebview<
179179
this.handleSelectionChange.bind(this),
180180
),
181181
);
182-
const navigationCommands = {
183-
"codeQLQueryResults.up": NavigationDirection.up,
184-
"codeQLQueryResults.down": NavigationDirection.down,
185-
"codeQLQueryResults.left": NavigationDirection.left,
186-
"codeQLQueryResults.right": NavigationDirection.right,
187-
// For backwards compatibility with keybindings set using an earlier version of the extension.
188-
"codeQLQueryResults.nextPathStep": NavigationDirection.down,
189-
"codeQLQueryResults.previousPathStep": NavigationDirection.up,
190-
};
191-
void logger.log("Registering result view navigation commands.");
192-
for (const [commandId, direction] of Object.entries(navigationCommands)) {
193-
this.push(
194-
commandRunner(commandId, this.navigateResultView.bind(this, direction)),
195-
);
196-
}
197182

198183
this.push(
199184
this.databaseManager.onDidChangeDatabaseItem(({ kind }) => {
@@ -209,6 +194,36 @@ export class ResultsView extends AbstractWebview<
209194
);
210195
}
211196

197+
public getCommands(): ResultsViewCommands {
198+
return {
199+
"codeQLQueryResults.up": this.navigateResultView.bind(
200+
this,
201+
NavigationDirection.up,
202+
),
203+
"codeQLQueryResults.down": this.navigateResultView.bind(
204+
this,
205+
NavigationDirection.down,
206+
),
207+
"codeQLQueryResults.left": this.navigateResultView.bind(
208+
this,
209+
NavigationDirection.left,
210+
),
211+
"codeQLQueryResults.right": this.navigateResultView.bind(
212+
this,
213+
NavigationDirection.right,
214+
),
215+
// For backwards compatibility with keybindings set using an earlier version of the extension.
216+
"codeQLQueryResults.nextPathStep": this.navigateResultView.bind(
217+
this,
218+
NavigationDirection.down,
219+
),
220+
"codeQLQueryResults.previousPathStep": this.navigateResultView.bind(
221+
this,
222+
NavigationDirection.up,
223+
),
224+
};
225+
}
226+
212227
async navigateResultView(direction: NavigationDirection): Promise<void> {
213228
if (!this.panel?.visible) {
214229
return;

0 commit comments

Comments
 (0)