From f8ae7b55c7f20421cfb1b7a74c3e5abc044ac410 Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Fri, 21 Jul 2023 17:11:22 +0100 Subject: [PATCH] Add manual refresh to test trees, and automatic refresh when client setting changes (fix #20) --- src/extension.ts | 2 +- src/historyExplorer.ts | 3 +-- src/localTests.ts | 22 ++++++++++++++++++++-- src/serverTests.ts | 14 ++++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index e87c1c2..0007b90 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -81,7 +81,7 @@ export async function activate(context: vscode.ExtensionContext) { // Other parts of this extension will use the test controllers localTestController = vscode.tests.createTestController(`${extensionId}-Local`, '$(folder-library) Local Tests'); context.subscriptions.push(localTestController); - await setupLocalTestsController(); + context.subscriptions.push(await setupLocalTestsController()); loadedTestController = vscode.tests.createTestController(`${extensionId}-Loaded`, '$(server-environment) Server Tests'); context.subscriptions.push(loadedTestController); diff --git a/src/historyExplorer.ts b/src/historyExplorer.ts index fb5b62a..589b581 100644 --- a/src/historyExplorer.ts +++ b/src/historyExplorer.ts @@ -42,8 +42,7 @@ export async function setupHistoryExplorerController() { historyBrowserController.refreshHandler = (token?: vscode.CancellationToken) => { historyBrowserController.items.replace([historyBrowserController.createTestItem('-', 'loading...')]); replaceRootItems(historyBrowserController); - } - + } } export async function serverSpec(item: vscode.TestItem): Promise { diff --git a/src/localTests.ts b/src/localTests.ts index 9cb523a..43d01e1 100644 --- a/src/localTests.ts +++ b/src/localTests.ts @@ -79,11 +79,29 @@ async function runTestsHandler(request: vscode.TestRunRequest, cancellation: vsc await commonRunTestsHandler(localTestController, resolveItemChildren, request, cancellation); } -export async function setupLocalTestsController() { +export async function setupLocalTestsController(): Promise { logger.info('setupLocalTestsController invoked'); + function showLoadingMessage() { + localTestController.items.replace([localTestController.createTestItem('-', 'loading...')]); + } + localTestController.resolveHandler = resolveItemChildren; - localTestController.items.replace([localTestController.createTestItem('-', 'loading...')]); + showLoadingMessage(); + + // Add a manual Refresh button + localTestController.refreshHandler = (token?: vscode.CancellationToken) => { + showLoadingMessage(); + replaceLocalRootItems(localTestController); + } + + // Arrange for automatic refresh if config changes + return vscode.workspace.onDidChangeConfiguration(async ({ affectsConfiguration }) => { + if (affectsConfiguration("intersystems.testingManager.client.relativeTestRoot")) { + showLoadingMessage(); + replaceLocalRootItems(localTestController); + } + }); } diff --git a/src/serverTests.ts b/src/serverTests.ts index fa7e6ea..e5d47af 100644 --- a/src/serverTests.ts +++ b/src/serverTests.ts @@ -5,7 +5,7 @@ import logger from './logger'; import { makeRESTRequest } from './makeRESTRequest'; import { commonRunTestsHandler } from './commonRunTestsHandler'; -async function resolveItemChildren(item: vscode.TestItem) { +async function resolveItemChildren(item?: vscode.TestItem) { if (item) { item.busy = true; const spec = await serverSpec(item); @@ -77,7 +77,17 @@ async function runTestsHandler(request: vscode.TestRunRequest, cancellation: vsc export async function setupServerTestsController() { logger.info('setupServerTestsController invoked'); + function showLoadingMessage() { + loadedTestController.items.replace([loadedTestController.createTestItem('-', 'loading...')]); + } + loadedTestController.resolveHandler = resolveItemChildren; - loadedTestController.items.replace([loadedTestController.createTestItem('-', 'loading...')]); + showLoadingMessage(); + + // Add a manual Refresh button + loadedTestController.refreshHandler = (token?: vscode.CancellationToken) => { + showLoadingMessage(); + resolveItemChildren(); + } }