Skip to content

Commit b66fd44

Browse files
committed
Only load support classes if missing or wrong version
1 parent 717d2b4 commit b66fd44

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

serverSide/src/vscode/dc/testingmanager/BaseManager.cls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/// Helper superclass for the testing managers we use.
2+
/// Must collate ahead of its subclasses, so it is already available on the server
3+
/// when they are copied there by a directory copy.
24
Class vscode.dc.testingmanager.BaseManager [ Abstract ]
35
{
46

7+
/// Keep this in sync with the version property in package.json
58
Parameter VERSION As STRING = "2.0.3";
69

710
Property tmMethodMap As %String [ MultiDimensional, Private ];

src/commonRunTestsHandler.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,32 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
173173
authority = authority.split(":")[0];
174174
}
175175

176-
// Load our support classes
177-
// TODO - as an optimization, check if they already exist and with the correct #VERSION parameter
178-
try {
179-
const extensionUri = vscode.extensions.getExtension(extensionId)?.extensionUri;
180-
if (extensionUri) {
181-
const sourceDir = extensionUri.with({ path: extensionUri.path + '/serverSide/src' + '/vscode/dc/testingmanager'});
182-
const destinationDir = vscode.Uri.from({ scheme: 'isfs', authority: `${authority}:${namespace}`, path: '/vscode/dc/testingmanager'})
183-
await vscode.workspace.fs.copy(sourceDir, destinationDir, { overwrite: true });
176+
// Load our support classes if they are not already there and the correct version.
177+
const thisExtension = vscode.extensions.getExtension(extensionId);
178+
if (!thisExtension) {
179+
// Never happens, but needed to satisfy typechecking below
180+
return;
181+
}
182+
const extensionUri = thisExtension.extensionUri;
183+
const supportClassesDir = extensionUri.with({ path: extensionUri.path + '/serverSide/src' + '/vscode/dc/testingmanager'});
184+
const expectedVersion = thisExtension.packageJSON.version;
185+
const expectedCount = (await vscode.workspace.fs.readDirectory(supportClassesDir)).length;
186+
const response = await makeRESTRequest(
187+
"POST",
188+
serverSpec,
189+
{ apiVersion: 1, namespace, path: "/action/query" },
190+
{
191+
query: `SELECT parent, _Default FROM %Dictionary.CompiledParameter WHERE Name='VERSION' AND parent %STARTSWITH 'vscode.dc.testingmanager.' AND _Default=?`,
192+
parameters: [expectedVersion],
193+
},
194+
);
195+
if (response?.status !== 200 || response?.data?.result?.content?.length !== expectedCount) {
196+
const destinationDir = vscode.Uri.from({ scheme: 'isfs', authority: `${authority}:${namespace}`, path: '/vscode/dc/testingmanager'})
197+
try {
198+
await vscode.workspace.fs.copy(supportClassesDir, destinationDir, { overwrite: true });
199+
} catch (error) {
200+
await vscode.window.showErrorMessage(`Failed to copy support classes from ${supportClassesDir.path.slice(1)} to ${destinationDir.toString()}\n\n${JSON.stringify(error)}`, {modal: true});
184201
}
185-
} catch (error) {
186-
console.log(error);
187202
}
188203

189204
// No longer rely on ISFS redirection of /.vscode because since ObjectScript v3.0 it no longer works for client-only workspaces.

0 commit comments

Comments
 (0)