|
1 | | -import { CancellationToken, Uri, window } from "vscode"; |
2 | | -import { ProgressCallback, withProgress } from "./commandRunner"; |
| 1 | +import { Uri, window } from "vscode"; |
| 2 | +import { withProgress } from "./commandRunner"; |
3 | 3 | import { AstViewer } from "./astViewer"; |
4 | 4 | import { |
5 | 5 | TemplatePrintAstProvider, |
@@ -34,23 +34,25 @@ export function getAstCfgCommands({ |
34 | 34 | astTemplateProvider, |
35 | 35 | cfgTemplateProvider, |
36 | 36 | }: AstCfgOptions): AstCfgCommands { |
37 | | - const viewAstCommand = async (selectedFile: Uri) => |
| 37 | + const viewAst = async (selectedFile: Uri) => |
38 | 38 | withProgress( |
39 | | - async (progress, token) => |
40 | | - await viewAst( |
41 | | - astViewer, |
42 | | - astTemplateProvider, |
| 39 | + async (progress, token) => { |
| 40 | + const ast = await astTemplateProvider.provideAst( |
43 | 41 | progress, |
44 | 42 | token, |
45 | | - selectedFile, |
46 | | - ), |
| 43 | + selectedFile ?? window.activeTextEditor?.document.uri, |
| 44 | + ); |
| 45 | + if (ast) { |
| 46 | + astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName); |
| 47 | + } |
| 48 | + }, |
47 | 49 | { |
48 | 50 | cancellable: true, |
49 | 51 | title: "Calculate AST", |
50 | 52 | }, |
51 | 53 | ); |
52 | 54 |
|
53 | | - const viewCfgCommand = async () => |
| 55 | + const viewCfg = async () => |
54 | 56 | withProgress( |
55 | 57 | async (progress, token) => { |
56 | 58 | const res = await cfgTemplateProvider.provideCfgUri( |
@@ -78,28 +80,11 @@ export function getAstCfgCommands({ |
78 | 80 | ); |
79 | 81 |
|
80 | 82 | return { |
81 | | - "codeQL.viewAst": viewAstCommand, |
82 | | - "codeQL.viewAstContextExplorer": viewAstCommand, |
83 | | - "codeQL.viewAstContextEditor": viewAstCommand, |
84 | | - "codeQL.viewCfg": viewCfgCommand, |
85 | | - "codeQL.viewCfgContextExplorer": viewCfgCommand, |
86 | | - "codeQL.viewCfgContextEditor": viewCfgCommand, |
| 83 | + "codeQL.viewAst": viewAst, |
| 84 | + "codeQL.viewAstContextExplorer": viewAst, |
| 85 | + "codeQL.viewAstContextEditor": viewAst, |
| 86 | + "codeQL.viewCfg": viewCfg, |
| 87 | + "codeQL.viewCfgContextExplorer": viewCfg, |
| 88 | + "codeQL.viewCfgContextEditor": viewCfg, |
87 | 89 | }; |
88 | 90 | } |
89 | | - |
90 | | -async function viewAst( |
91 | | - astViewer: AstViewer, |
92 | | - printAstTemplateProvider: TemplatePrintAstProvider, |
93 | | - progress: ProgressCallback, |
94 | | - token: CancellationToken, |
95 | | - selectedFile: Uri, |
96 | | -): Promise<void> { |
97 | | - const ast = await printAstTemplateProvider.provideAst( |
98 | | - progress, |
99 | | - token, |
100 | | - selectedFile ?? window.activeTextEditor?.document.uri, |
101 | | - ); |
102 | | - if (ast) { |
103 | | - astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName); |
104 | | - } |
105 | | -} |
0 commit comments