@@ -10,7 +10,17 @@ interface WebviewState {
1010 currentView : 'form' | 'text' | 'flags'
1111 commitData : any
1212 textContent : string
13- flags ?: Record < string , Record < string , { deadline ?: string ; docUrl ?: string } > >
13+ }
14+
15+ interface FlagConfig {
16+ [ theme : string ] : {
17+ deadline ?: string
18+ docUrl ?: string
19+ }
20+ }
21+
22+ interface FlagsConfig {
23+ [ flag : string ] : FlagConfig
1424}
1525
1626// New interfaces for our settings structure
@@ -47,6 +57,17 @@ export function activate(context: vscode.ExtensionContext) {
4757 SettingsPanel . createOrShow ( context )
4858 } )
4959 )
60+
61+ // Listen for configuration changes
62+ context . subscriptions . push (
63+ vscode . workspace . onDidChangeConfiguration ( ( e ) => {
64+ if ( e . affectsConfiguration ( 'commitAssistant.flags' ) ) {
65+ if ( CommitEditorPanel . currentPanel ) {
66+ CommitEditorPanel . currentPanel . refreshConfig ( )
67+ }
68+ }
69+ } )
70+ )
5071}
5172
5273class CommitEditorPanel {
@@ -95,9 +116,15 @@ class CommitEditorPanel {
95116 vscode . window . showErrorMessage ( message . text )
96117 return
97118 case 'saveState' :
98- // Save all state to workspace state
99- this . _context . workspaceState . update ( 'state' , message . state )
100- console . log ( 'State saved to workspaceState:' , message . state ) ;
119+ // Save UI state to workspace state
120+ this . _context . workspaceState . update ( 'state' , {
121+ currentView : message . state . currentView ,
122+ commitData : message . state . commitData ,
123+ textContent : message . state . textContent
124+ } )
125+ return
126+ case 'updateFlags' :
127+ this . _updateFlags ( message . globalFlags , message . workspaceFlags )
101128 return
102129 case 'openSettings' :
103130 vscode . commands . executeCommand ( 'commitAssistant.openSettings' )
@@ -128,6 +155,20 @@ class CommitEditorPanel {
128155 )
129156 }
130157
158+ private async _updateFlags ( globalFlags : FlagsConfig , workspaceFlags : FlagsConfig ) {
159+ const config = vscode . workspace . getConfiguration ( 'commitAssistant' )
160+ try {
161+ await config . update ( 'flags' , globalFlags , vscode . ConfigurationTarget . Global )
162+ await config . update ( 'flags' , workspaceFlags , vscode . ConfigurationTarget . Workspace )
163+ } catch ( error : any ) {
164+ vscode . window . showErrorMessage ( `Failed to save flags: ${ error . message } ` )
165+ }
166+ }
167+
168+ public refreshConfig ( ) {
169+ this . _sendConfig ( )
170+ }
171+
131172 private _saveCommitMessage ( commitMessage : string ) {
132173 const gitExtension = vscode . extensions . getExtension ( 'vscode.git' ) ?. exports
133174 const git = gitExtension ?. getAPI ( 1 )
@@ -267,24 +308,20 @@ class CommitEditorPanel {
267308
268309 this . _sendConfig ( )
269310
270- // Load state from workspace and global storage
311+ // Load UI state from workspace state
271312 const storedState = this . _context . workspaceState . get < WebviewState > ( 'state' )
272313
273- // Merge workspace state with global flags
274314 const mergedState = storedState
275315 ? {
276316 ...storedState ,
277- flags : storedState . flags || { } ,
278317 }
279318 : {
280319 currentView : 'form' ,
281320 commitData : { } ,
282321 textContent : '' ,
283- flags : { } ,
284322 }
285323
286324 // Send merged state to the webview
287- console . log ( 'State sent to webview:' , mergedState ) ;
288325 this . _panel . webview . postMessage ( { command : 'loadState' , state : mergedState } )
289326 }
290327
@@ -301,14 +338,36 @@ class CommitEditorPanel {
301338 ...commitTypesFromConfig
302339 ] ;
303340
304- // We could also get flags from config in the future
341+ const inspect = config . inspect < FlagsConfig > ( 'flags' )
342+ const globalFlags = inspect ?. globalValue || { }
343+ const workspaceFlags = inspect ?. workspaceValue || { }
344+
345+ // Merge flags for the webview UI, adding scope info to each theme
346+ const mergedFlags : Record < string , Record < string , any > > = { }
347+
348+ // Add global flags
349+ for ( const [ flag , themes ] of Object . entries ( globalFlags ) ) {
350+ if ( ! mergedFlags [ flag ] ) mergedFlags [ flag ] = { }
351+ for ( const [ theme , data ] of Object . entries ( themes ) ) {
352+ mergedFlags [ flag ] [ theme ] = { ...data , scope : 'global' }
353+ }
354+ }
355+
356+ // Add workspace flags (overwrites or adds to global)
357+ for ( const [ flag , themes ] of Object . entries ( workspaceFlags ) ) {
358+ if ( ! mergedFlags [ flag ] ) mergedFlags [ flag ] = { }
359+ for ( const [ theme , data ] of Object . entries ( themes ) ) {
360+ mergedFlags [ flag ] [ theme ] = { ...data , scope : 'workspace' }
361+ }
362+ }
363+
305364 this . _panel . webview . postMessage ( {
306365 command : 'loadConfig' ,
307366 config : {
308367 commitTypes,
309368 themeDeadline,
310369 preference,
311- flags : { } , // Placeholder for future flag configuration
370+ flags : mergedFlags ,
312371 } ,
313372 } )
314373 }
0 commit comments