@@ -5,7 +5,7 @@ import { getNonce } from './utilities/getNonce';
55import { printChannelOutput } from './extension' ;
66import { newResourceInput } from './addNewResource' ;
77import { AppConstants } from './utilities/constants' ;
8- import { generateDesignerCode } from './utilities/designerGenerator ' ;
8+ import { generateAndUpdateDesignerFile } from './utilities/generateCode ' ;
99
1010export class ResxProvider implements vscode . CustomTextEditorProvider {
1111
@@ -134,32 +134,13 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
134134 resxContent
135135 ) ;
136136
137- // Check if code generation is enabled
138- const config = vscode . workspace . getConfiguration ( 'resx-editor' ) ;
139- const generateCode = config . get < boolean > ( 'generateCode' , true ) ;
140-
141- if ( generateCode ) {
142- // Generate and update the Designer.cs file
143- const designerPath = document . uri . fsPath . replace ( '.resx' , '.Designer.cs' ) ;
144- const designerUri = vscode . Uri . file ( designerPath ) ;
145- const designerCode = generateDesignerCode ( document . uri . fsPath , parsedJson ) ;
146-
147- try {
148- await vscode . workspace . fs . stat ( designerUri ) ;
149- // File exists, write contents directly
150- printChannelOutput ( `Updating existing Designer file at ${ designerPath } ` , true ) ;
151- await vscode . workspace . fs . writeFile ( designerUri , Buffer . from ( designerCode , 'utf8' ) ) ;
152- } catch {
153- // File doesn't exist, create it
154- printChannelOutput ( `Creating new Designer file at ${ designerPath } ` , true ) ;
155- await vscode . workspace . fs . writeFile ( designerUri , Buffer . from ( designerCode , 'utf8' ) ) ;
156- }
157- } else {
158- printChannelOutput ( 'Code generation is disabled, skipping Designer.cs file update' , true ) ;
159- }
137+ // Generate Designer.cs file if enabled
138+ await generateAndUpdateDesignerFile ( document , parsedJson ) ;
160139
161140 const success = await vscode . workspace . applyEdit ( edit ) ;
162141 if ( success ) {
142+ const config = vscode . workspace . getConfiguration ( 'resx-editor' ) ;
143+ const generateCode = config . get < boolean > ( 'generateCode' , true ) ;
163144 printChannelOutput ( `Successfully updated RESX${ generateCode ? ' and Designer' : '' } files` , true ) ;
164145 } else {
165146 printChannelOutput ( `Failed to apply workspace edits` , true ) ;
0 commit comments