Skip to content

Commit 9f7c7b2

Browse files
authored
Merge pull request #2203 from github/koesie10/ast-viewer-typed-commands
Convert AST viewer commands to typed commands
2 parents e724577 + bc29231 commit 9f7c7b2

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

extensions/ql-vscode/src/astViewer.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import {
2323
isWholeFileLoc,
2424
isLineColumnLoc,
2525
} from "./pure/bqrs-utils";
26-
import { commandRunner } from "./commandRunner";
2726
import { DisposableObject } from "./pure/disposable-object";
2827
import { showAndLogExceptionWithTelemetry } from "./helpers";
2928
import { asError, getErrorMessage } from "./pure/helpers-pure";
3029
import { redactableError } from "./pure/errors";
30+
import { AstViewerCommands } from "./common/commands";
3131

3232
export interface AstItem {
3333
id: BqrsId;
@@ -55,15 +55,6 @@ class AstViewerDataProvider
5555
readonly onDidChangeTreeData: Event<AstItem | undefined> =
5656
this._onDidChangeTreeData.event;
5757

58-
constructor() {
59-
super();
60-
this.push(
61-
commandRunner("codeQLAstViewer.gotoCode", async (item: AstItem) => {
62-
await showLocation(item.fileLocation);
63-
}),
64-
);
65-
}
66-
6758
refresh(): void {
6859
this._onDidChangeTreeData.fire(undefined);
6960
}
@@ -126,16 +117,20 @@ export class AstViewer extends DisposableObject {
126117

127118
this.push(this.treeView);
128119
this.push(this.treeDataProvider);
129-
this.push(
130-
commandRunner("codeQLAstViewer.clear", async () => {
131-
this.clear();
132-
}),
133-
);
134120
this.push(
135121
window.onDidChangeTextEditorSelection(this.updateTreeSelection, this),
136122
);
137123
}
138124

125+
getCommands(): AstViewerCommands {
126+
return {
127+
"codeQLAstViewer.clear": async () => this.clear(),
128+
"codeQLAstViewer.gotoCode": async (item: AstItem) => {
129+
await showLocation(item.fileLocation);
130+
},
131+
};
132+
}
133+
139134
updateRoots(roots: AstItem[], db: DatabaseItem, fileUri: Uri) {
140135
this.treeDataProvider.roots = roots;
141136
this.treeDataProvider.db = db;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CommandManager } from "../packages/commands";
22
import type { Uri, Range } from "vscode";
3+
import type { AstItem } from "../astViewer";
34
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
45
import type { DatabaseItem } from "../local-databases";
56
import type { QueryHistoryInfo } from "../query-history/query-history-info";
@@ -176,6 +177,11 @@ export type AstCfgCommands = {
176177
"codeQL.viewCfgContextEditor": () => Promise<void>;
177178
};
178179

180+
export type AstViewerCommands = {
181+
"codeQLAstViewer.clear": () => Promise<void>;
182+
"codeQLAstViewer.gotoCode": (item: AstItem) => Promise<void>;
183+
};
184+
179185
export type PackagingCommands = {
180186
"codeQL.installPackDependencies": () => Promise<void>;
181187
"codeQL.downloadPacks": () => Promise<void>;
@@ -191,6 +197,7 @@ export type AllCommands = BaseCommands &
191197
VariantAnalysisCommands &
192198
DatabasePanelCommands &
193199
AstCfgCommands &
200+
AstViewerCommands &
194201
PackagingCommands &
195202
EvalLogViewerCommands;
196203

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ async function activateWithInstalledDistribution(
837837
astTemplateProvider,
838838
cfgTemplateProvider,
839839
}),
840+
...astViewer.getCommands(),
840841
...getPackagingCommands({
841842
cliServer,
842843
}),

0 commit comments

Comments
 (0)