|
| 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 | +} |
0 commit comments