Skip to content

Commit 819e596

Browse files
Merge branch 'main' into robertbrignull/extract_progress
2 parents b914b97 + 88a9ecb commit 819e596

File tree

5 files changed

+166
-214
lines changed

5 files changed

+166
-214
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Uri, window } from "vscode";
2+
import { withProgress } from "./commandRunner";
3+
import { AstViewer } from "./astViewer";
4+
import {
5+
TemplatePrintAstProvider,
6+
TemplatePrintCfgProvider,
7+
} from "./contextual/templateProvider";
8+
import { compileAndRunQuery } from "./local-queries";
9+
import { QueryRunner } from "./queryRunner";
10+
import { QueryHistoryManager } from "./query-history/query-history-manager";
11+
import { DatabaseUI } from "./local-databases-ui";
12+
import { ResultsView } from "./interface";
13+
import { AstCfgCommands } from "./common/commands";
14+
15+
type AstCfgOptions = {
16+
queryRunner: QueryRunner;
17+
queryHistoryManager: QueryHistoryManager;
18+
databaseUI: DatabaseUI;
19+
localQueryResultsView: ResultsView;
20+
queryStorageDir: string;
21+
22+
astViewer: AstViewer;
23+
astTemplateProvider: TemplatePrintAstProvider;
24+
cfgTemplateProvider: TemplatePrintCfgProvider;
25+
};
26+
27+
export function getAstCfgCommands({
28+
queryRunner,
29+
queryHistoryManager,
30+
databaseUI,
31+
localQueryResultsView,
32+
queryStorageDir,
33+
astViewer,
34+
astTemplateProvider,
35+
cfgTemplateProvider,
36+
}: AstCfgOptions): AstCfgCommands {
37+
const viewAst = async (selectedFile: Uri) =>
38+
withProgress(
39+
async (progress, token) => {
40+
const ast = await astTemplateProvider.provideAst(
41+
progress,
42+
token,
43+
selectedFile ?? window.activeTextEditor?.document.uri,
44+
);
45+
if (ast) {
46+
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
47+
}
48+
},
49+
{
50+
cancellable: true,
51+
title: "Calculate AST",
52+
},
53+
);
54+
55+
const viewCfg = async () =>
56+
withProgress(
57+
async (progress, token) => {
58+
const res = await cfgTemplateProvider.provideCfgUri(
59+
window.activeTextEditor?.document,
60+
);
61+
if (res) {
62+
await compileAndRunQuery(
63+
queryRunner,
64+
queryHistoryManager,
65+
databaseUI,
66+
localQueryResultsView,
67+
queryStorageDir,
68+
false,
69+
res[0],
70+
progress,
71+
token,
72+
undefined,
73+
);
74+
}
75+
},
76+
{
77+
title: "Calculating Control Flow Graph",
78+
cancellable: true,
79+
},
80+
);
81+
82+
return {
83+
"codeQL.viewAst": viewAst,
84+
"codeQL.viewAstContextExplorer": viewAst,
85+
"codeQL.viewAstContextEditor": viewAst,
86+
"codeQL.viewCfg": viewCfg,
87+
"codeQL.viewCfgContextExplorer": viewCfg,
88+
"codeQL.viewCfgContextEditor": viewCfg,
89+
};
90+
}

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: 23 additions & 1 deletion
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";
@@ -167,6 +168,20 @@ export type DatabasePanelCommands = {
167168
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
168169
};
169170

171+
export type AstCfgCommands = {
172+
"codeQL.viewAst": (selectedFile: Uri) => Promise<void>;
173+
"codeQL.viewAstContextExplorer": (selectedFile: Uri) => Promise<void>;
174+
"codeQL.viewAstContextEditor": (selectedFile: Uri) => Promise<void>;
175+
"codeQL.viewCfg": () => Promise<void>;
176+
"codeQL.viewCfgContextExplorer": () => Promise<void>;
177+
"codeQL.viewCfgContextEditor": () => Promise<void>;
178+
};
179+
180+
export type AstViewerCommands = {
181+
"codeQLAstViewer.clear": () => Promise<void>;
182+
"codeQLAstViewer.gotoCode": (item: AstItem) => Promise<void>;
183+
};
184+
170185
export type PackagingCommands = {
171186
"codeQL.installPackDependencies": () => Promise<void>;
172187
"codeQL.downloadPacks": () => Promise<void>;
@@ -176,13 +191,20 @@ export type EvalLogViewerCommands = {
176191
"codeQLEvalLogViewer.clear": () => Promise<void>;
177192
};
178193

194+
export type SummaryLanguageSupportCommands = {
195+
"codeQL.gotoQL": () => Promise<void>;
196+
};
197+
179198
export type AllCommands = BaseCommands &
180199
QueryHistoryCommands &
181200
LocalDatabasesCommands &
182201
VariantAnalysisCommands &
183202
DatabasePanelCommands &
203+
AstCfgCommands &
204+
AstViewerCommands &
184205
PackagingCommands &
185-
EvalLogViewerCommands;
206+
EvalLogViewerCommands &
207+
SummaryLanguageSupportCommands;
186208

187209
export type AppCommandManager = CommandManager<AllCommands>;
188210

0 commit comments

Comments
 (0)