Skip to content

Commit

Permalink
Merge pull request #22 from gjsjohnmurray/fix-20
Browse files Browse the repository at this point in the history
Add manual refresh to test trees, and automatic refresh when client setting changes
  • Loading branch information
gjsjohnmurray authored Jul 26, 2023
2 parents 29279e0 + f8ae7b5 commit cf25ad8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/historyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IServerSpec | undefined> {
Expand Down
22 changes: 20 additions & 2 deletions src/localTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.Disposable> {
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);
}
});
}


Expand Down
14 changes: 12 additions & 2 deletions src/serverTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}

0 comments on commit cf25ad8

Please sign in to comment.