Merge pull request #2203 from github/koesie10/ast-viewer-typed-commands

Convert AST viewer commands to typed commands
This commit is contained in:
Koen Vlaswinkel 2023-03-22 14:44:04 +01:00 коммит произвёл GitHub
Родитель e724577d82 bc29231fec
Коммит 9f7c7b2ed8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

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