Skip to content

Commit bb1d4a1

Browse files
Merge branch 'topic/eng/ide/ada_language_server#1592' into 'master'
Clear cache on 'als-reload-project' command See merge request eng/ide/ada_language_server!1898
2 parents 2882181 + fe98efb commit bb1d4a1

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ExtensionState {
6161
private adaTaskProvider?: SimpleTaskProvider;
6262
private sparkTaskProvider?: SimpleTaskProvider;
6363

64-
public clearALSCache() {
64+
private clearALSCache() {
6565
this.cachedProjectUri = undefined;
6666
this.cachedObjectDir = undefined;
6767
this.cachedMains = undefined;
@@ -170,10 +170,9 @@ export class ExtensionState {
170170
e.affectsConfiguration('ada.scenarioVariables') ||
171171
e.affectsConfiguration('ada.projectFile')
172172
) {
173-
logger.info('project related settings have changed: clearing caches for tasks');
174-
this.clearALSCache();
175-
this.unregisterTaskDisposables();
176-
this.registerTaskDisposables();
173+
this.clearCacheAndTasks(
174+
'project related settings have changed: clearing caches and tasks',
175+
);
177176
}
178177

179178
// React to changes made in the environment variables, showing
@@ -188,6 +187,20 @@ export class ExtensionState {
188187
}
189188
};
190189

190+
/**
191+
* Clear the extension's cache and, unregister its predefined tasks and register them
192+
* again to make sure they take into account the current extension's state
193+
* (environment, loaded project...).
194+
*
195+
* @param msg - Log message explaning why the cache is being cleared.
196+
*/
197+
public clearCacheAndTasks(logMsg = ''): void {
198+
logger.info(logMsg);
199+
this.clearALSCache();
200+
this.unregisterTaskDisposables();
201+
this.registerTaskDisposables();
202+
}
203+
191204
/**
192205
* Returns the value of the given project attribute, or raises
193206
* an exception when the queried attribute is not known

integration/vscode/ada/src/alsExecuteCommand.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
alsReplaceTypeCommandExecutor,
4040
ReplaceTypeCommandArgs,
4141
} from './refactoring/alsReplaceTypeCommand';
42+
import { adaExtState } from './extension';
4243

4344
/**
4445
* Type alias for a function that intercepts a command and executes it by return a promise that
@@ -89,6 +90,10 @@ export const alsCommandExecutor = (client: LanguageClient): CommandExecutor => {
8990
args[0] as ReplaceTypeCommandArgs,
9091
);
9192
if (!proceedWithExecution) return Promise.resolve(undefined);
93+
} else if (command === 'als-reload-project') {
94+
// Clear the cache and the predefined tasks when the project
95+
// has been reloaded.
96+
adaExtState.clearCacheAndTasks('project is being reloaded: clearing caches and tasks');
9297
}
9398
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
9499
return next(command, args);

integration/vscode/ada/test/general/extension.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,38 @@ suite('Extensions Test Suite', function () {
6868
throw new Error('No workspace folder found for the specified URI');
6969
}
7070
});
71+
test('Clear Cache On Project Reload', async () => {
72+
if (vscode.workspace.workspaceFolders !== undefined) {
73+
// Get the workspace root folder
74+
const folder = vscode.workspace.workspaceFolders[0].uri;
75+
76+
// Check the object directory when 'for Object_Dir use "obj"' is present
77+
// in the GPR file
78+
const originalObjDir: string = await adaExtState.getObjectDir();
79+
assert.strictEqual(originalObjDir, vscode.Uri.joinPath(folder, 'obj').fsPath);
80+
81+
// Remove the line that specifies the object directory in the GPR file
82+
const fileUri = vscode.Uri.joinPath(folder, 'prj.gpr');
83+
const contentBefore = readFileSync(fileUri.fsPath, 'utf-8');
84+
const newContent = contentBefore.replace(' for Object_Dir use "obj";', '');
85+
writeFileSync(fileUri.fsPath, newContent, 'utf-8');
86+
87+
// Reload the project and check the object dir value: should be set
88+
// to the project's root directory (workspace directory)
89+
await vscode.commands.executeCommand('als-reload-project');
90+
try {
91+
assert.strictEqual(await adaExtState.getObjectDir(), folder.fsPath);
92+
} finally {
93+
// Restore the old GPR file contents
94+
writeFileSync(fileUri.fsPath, contentBefore);
95+
}
96+
97+
// Reload the project to its original state, and check that
98+
// the object directory is back to its original value too.
99+
await vscode.commands.executeCommand('als-reload-project');
100+
assert.strictEqual(await adaExtState.getObjectDir(), originalObjDir);
101+
} else {
102+
throw new Error('No workspace folder found for the specified URI');
103+
}
104+
});
71105
});

0 commit comments

Comments
 (0)