Convert AST viewer commands to typed commands

This commit is contained in:
Koen Vlaswinkel
2023-03-22 14:11:43 +01:00
parent e724577d82
commit bc29231fec
3 changed files with 18 additions and 15 deletions

View File

@@ -23,11 +23,11 @@ import {
isWholeFileLoc,
isLineColumnLoc,
} from "./pure/bqrs-utils";
import { commandRunner } from "./commandRunner";
import { DisposableObject } from "./pure/disposable-object";
import { showAndLogExceptionWithTelemetry } from "./helpers";
import { asError, getErrorMessage } from "./pure/helpers-pure";
import { redactableError } from "./pure/errors";
import { AstViewerCommands } from "./common/commands";
export interface AstItem {
id: BqrsId;
@@ -55,15 +55,6 @@ class AstViewerDataProvider
readonly onDidChangeTreeData: Event<AstItem | undefined> =
this._onDidChangeTreeData.event;
constructor() {
super();
this.push(
commandRunner("codeQLAstViewer.gotoCode", async (item: AstItem) => {
await showLocation(item.fileLocation);
}),
);
}
refresh(): void {
this._onDidChangeTreeData.fire(undefined);
}
@@ -126,16 +117,20 @@ export class AstViewer extends DisposableObject {
this.push(this.treeView);
this.push(this.treeDataProvider);
this.push(
commandRunner("codeQLAstViewer.clear", async () => {
this.clear();
}),
);
this.push(
window.onDidChangeTextEditorSelection(this.updateTreeSelection, this),
);
}
getCommands(): AstViewerCommands {
return {
"codeQLAstViewer.clear": async () => this.clear(),
"codeQLAstViewer.gotoCode": async (item: AstItem) => {
await showLocation(item.fileLocation);
},
};
}
updateRoots(roots: AstItem[], db: DatabaseItem, fileUri: Uri) {
this.treeDataProvider.roots = roots;
this.treeDataProvider.db = db;

View File

@@ -1,5 +1,6 @@
import type { CommandManager } from "../packages/commands";
import type { Uri, Range } from "vscode";
import type { AstItem } from "../astViewer";
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
import type { DatabaseItem } from "../local-databases";
import type { QueryHistoryInfo } from "../query-history/query-history-info";
@@ -176,6 +177,11 @@ export type AstCfgCommands = {
"codeQL.viewCfgContextEditor": () => Promise<void>;
};
export type AstViewerCommands = {
"codeQLAstViewer.clear": () => Promise<void>;
"codeQLAstViewer.gotoCode": (item: AstItem) => Promise<void>;
};
export type PackagingCommands = {
"codeQL.installPackDependencies": () => Promise<void>;
"codeQL.downloadPacks": () => Promise<void>;
@@ -191,6 +197,7 @@ export type AllCommands = BaseCommands &
VariantAnalysisCommands &
DatabasePanelCommands &
AstCfgCommands &
AstViewerCommands &
PackagingCommands &
EvalLogViewerCommands;

View File

@@ -837,6 +837,7 @@ async function activateWithInstalledDistribution(
astTemplateProvider,
cfgTemplateProvider,
}),
...astViewer.getCommands(),
...getPackagingCommands({
cliServer,
}),