@@ -2,12 +2,11 @@ import * as vscode from 'vscode';
22import { getFlowrSession , registerCommand } from './extension' ;
33import { DiagramSettingsKeys , DiagramSettingsPrefix , getConfig } from './settings' ;
44import path from 'path' ;
5- import assert from 'assert' ;
65import type { DiagramOption , DiagramOptions , DiagramOptionsCheckbox , DiagramOptionsDropdown } from './diagram-generator' ;
76import { createDiagramWebview } from './diagram-generator' ;
8- import { assertUnreachable } from '@eagleoutice/flowr/util/assert' ;
97import type { CfgSimplificationPassName } from '@eagleoutice/flowr/control-flow/cfg-simplification' ;
108import { CfgSimplificationPasses } from '@eagleoutice/flowr/control-flow/cfg-simplification' ;
9+ import { assertUnreachable } from '@eagleoutice/flowr/util/assert' ;
1110
1211export function registerDiagramCommands ( context : vscode . ExtensionContext , output : vscode . OutputChannel ) {
1312 const coordinator = new DiagramUpdateCoordinator ( output ) ;
@@ -30,12 +29,17 @@ export function registerDiagramCommands(context: vscode.ExtensionContext, output
3029 const activeEditor = vscode . window . activeTextEditor ;
3130 return await coordinator . createDiagramPanel ( FlowrDiagramType . Controlflow , activeEditor ) ;
3231 } ) ;
32+ registerCommand ( context , 'vscode-flowr.call-graph' , async ( ) => {
33+ const activeEditor = vscode . window . activeTextEditor ;
34+ return await coordinator . createDiagramPanel ( FlowrDiagramType . CallGraph , activeEditor ) ;
35+ } ) ;
3336}
3437
3538enum FlowrDiagramType {
3639 Dataflow = 'flowr-dataflow' ,
3740 Controlflow = 'flowr-cfg' ,
38- Ast = 'flowr-ast'
41+ Ast = 'flowr-ast' ,
42+ CallGraph = 'flowr-call-graph' ,
3943}
4044
4145interface DiagramPanelInformation {
@@ -78,7 +82,7 @@ class DiagramUpdateCoordinator {
7882 return ;
7983 }
8084
81- const title = `${ nameFromDiagramType ( type ) } (${ path . basename ( editor . document . fileName ) } )` ;
85+ const title = `${ DiagramTitleMap [ type ] } (${ path . basename ( editor . document . fileName ) } )` ;
8286 const options = optionsFromDiagramType ( type ) ;
8387 const mermaid = await diagramFromTypeAndEditor ( type , editor , options ) ;
8488 const panel = createDiagramWebview ( type as string , title , mermaid , this . output , options ) ;
@@ -158,15 +162,6 @@ class DiagramUpdateCoordinator {
158162 }
159163}
160164
161- function nameFromDiagramType ( type : FlowrDiagramType ) : string {
162- switch ( type ) {
163- case FlowrDiagramType . Dataflow : return 'Dataflow Graph' ;
164- case FlowrDiagramType . Controlflow : return 'Control Flow Graph' ;
165- case FlowrDiagramType . Ast : return 'AST' ;
166- default : return 'Flowr' ;
167- }
168- }
169-
170165const DefaultDiagramOptions = {
171166 mode : {
172167 type : 'dropdown' ,
@@ -220,21 +215,22 @@ const CFGDiagramOptions = {
220215 } ] ) ) as { [ K in CfgSimplificationPassName ] : DiagramOptionsCheckbox < CfgSimplificationPassName > } )
221216} satisfies DiagramOptions ;
222217
218+ const DiagramOptionsMap = {
219+ 'flowr-dataflow' : DFGDiagramOptions ,
220+ 'flowr-cfg' : CFGDiagramOptions ,
221+ 'flowr-ast' : DefaultDiagramOptions ,
222+ 'flowr-call-graph' : DefaultDiagramOptions
223+ } as const satisfies Record < FlowrDiagramType , DiagramOptions > ;
224+
225+ const DiagramTitleMap = {
226+ 'flowr-dataflow' : 'Dataflow Graph' ,
227+ 'flowr-cfg' : 'Control Flow Graph' ,
228+ 'flowr-ast' : 'AST' ,
229+ 'flowr-call-graph' : 'Call Graph'
230+ } as const satisfies Record < FlowrDiagramType , string > ;
231+
223232function optionsFromDiagramType ( type : FlowrDiagramType ) {
224- let options ;
225-
226- switch ( type ) {
227- case FlowrDiagramType . Dataflow :
228- options = DFGDiagramOptions ;
229- break ;
230- case FlowrDiagramType . Controlflow :
231- options = CFGDiagramOptions ;
232- break ;
233- case FlowrDiagramType . Ast :
234- options = DefaultDiagramOptions ;
235- break ;
236- default : assertUnreachable ( type ) ;
237- }
233+ const options = DiagramOptionsMap [ type ] ;
238234
239235 for ( const option of Object . values ( options ) ) {
240236 if ( 'keyInSet' in option && option . keyInSet ) { // option is encoded in a set
@@ -276,6 +272,7 @@ async function diagramFromTypeAndEditor(type: FlowrDiagramType, editor: vscode.T
276272 return await session . retrieveCfgMermaid ( editor . document , editor . selections , opts . mode . currentValue , opts . simplifyCfg . currentValue , simplificationPassesFromOptions ( opts ) ) ;
277273 }
278274 case FlowrDiagramType . Ast : return await session . retrieveAstMermaid ( editor . document , editor . selections , options . mode . currentValue ) ;
279- default : assert ( false ) ;
275+ case FlowrDiagramType . CallGraph : return await session . retrieveCallgraphMermaid ( editor . document , editor . selections , options . mode . currentValue ) ;
276+ default : assertUnreachable ( type ) ;
280277 }
281278}
0 commit comments