@@ -213,6 +213,89 @@ suite('Extensions Test Suite', function () {
213213 }
214214 } ) ;
215215
216+ test ( 'Auto Reload Project On Save' , async ( ) => {
217+ if ( vscode . workspace . workspaceFolders !== undefined ) {
218+ // Get the workspace root folder
219+ const folder = vscode . workspace . workspaceFolders [ 0 ] . uri ;
220+
221+ // Set the 'Always' preference for auto-reload, just for this test
222+ const alwaysReloadKey = 'ada.autoReloadProject.alwaysReload' ;
223+ await adaExtState . context . workspaceState . update ( alwaysReloadKey , true ) ;
224+
225+ try {
226+ // Check that Exec_Dir is not initially set (should be empty or default)
227+ const initialExecDir = await adaExtState . getProjectAttributeValue ( 'Exec_Dir' ) ;
228+ assert . strictEqual ( initialExecDir , 'obj' , 'Exec_Dir should be initially "obj"' ) ;
229+
230+ // Open the GPR file
231+ const fileUri = vscode . Uri . joinPath ( folder , 'prj.gpr' ) ;
232+ const document = await vscode . workspace . openTextDocument ( fileUri ) ;
233+ const editor = await vscode . window . showTextDocument ( document ) ;
234+
235+ // Store the original content
236+ const contentBefore = document . getText ( ) ;
237+
238+ // Edit the document to add Exec_Dir attribute
239+ const text = document . getText ( ) ;
240+ const modifiedText = text . replace (
241+ ' for Object_Dir use "obj";' ,
242+ ' for Object_Dir use "obj";\n for Exec_Dir use "bin";' ,
243+ ) ;
244+
245+ await editor . edit ( ( editBuilder ) => {
246+ const fullRange = new vscode . Range (
247+ document . positionAt ( 0 ) ,
248+ document . positionAt ( text . length ) ,
249+ ) ;
250+ editBuilder . replace ( fullRange , modifiedText ) ;
251+ } ) ;
252+
253+ // Save the document to trigger the auto-reload
254+ await document . save ( ) ;
255+
256+ // Wait a bit for the auto-reload to complete
257+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
258+
259+ // Check that Exec_Dir has been set to "bin"
260+ const newExecDir = await adaExtState . getProjectAttributeValue ( 'Exec_Dir' ) ;
261+ assert . strictEqual (
262+ newExecDir ,
263+ 'bin' ,
264+ 'Exec_Dir should be set to "bin" after auto-reload' ,
265+ ) ;
266+
267+ // Restore the original content using the VS Code API
268+ const currentText = document . getText ( ) ;
269+ await editor . edit ( ( editBuilder ) => {
270+ const fullRange = new vscode . Range (
271+ document . positionAt ( 0 ) ,
272+ document . positionAt ( currentText . length ) ,
273+ ) ;
274+ editBuilder . replace ( fullRange , contentBefore ) ;
275+ } ) ;
276+
277+ // Save again to trigger another auto-reload
278+ await document . save ( ) ;
279+
280+ // Wait for the auto-reload
281+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
282+
283+ // Check that Exec_Dir is back to its initial value
284+ const restoredExecDir = await adaExtState . getProjectAttributeValue ( 'Exec_Dir' ) ;
285+ assert . strictEqual (
286+ restoredExecDir ,
287+ initialExecDir ,
288+ 'Exec_Dir should be restored to its initial value' ,
289+ ) ;
290+ } finally {
291+ // Clear the 'Always' preference
292+ await adaExtState . context . workspaceState . update ( alwaysReloadKey , undefined ) ;
293+ }
294+ } else {
295+ throw new Error ( 'No workspace folder found for the specified URI' ) ;
296+ }
297+ } ) ;
298+
216299 test ( 'Split long comments on ENTER' , async ( ) => {
217300 if ( vscode . workspace . workspaceFolders !== undefined ) {
218301 // Get a file with a long comment (>80 chars)
0 commit comments