55import { inject , injectable } from 'inversify' ;
66import {
77 ConfigurationChangeEvent , Disposable ,
8- DocumentSymbolProvider , EventEmitter ,
9- OutputChannel , TextDocument , Uri , window
8+ DocumentSymbolProvider , Event ,
9+ EventEmitter , OutputChannel , TextDocument , Uri , window
1010} from 'vscode' ;
1111import {
1212 IApplicationShell , ICommandManager , IDocumentManager , IWorkspaceService
@@ -26,15 +26,8 @@ import {
2626 CANCELLATION_REASON , CommandSource , TEST_OUTPUT_CHANNEL
2727} from './common/constants' ;
2828import { selectTestWorkspace } from './common/testUtils' ;
29- import {
30- ITestCollectionStorageService , ITestManager ,
31- IWorkspaceTestManagerService , TestFile ,
32- TestFunction , TestStatus , TestsToRun
33- } from './common/types' ;
34- import {
35- ITestDisplay , ITestResultDisplay ,
36- IUnitTestConfigurationService , IUnitTestManagementService
37- } from './types' ;
29+ import { ITestCollectionStorageService , ITestManager , IWorkspaceTestManagerService , TestFile , TestFunction , TestStatus , TestsToRun } from './common/types' ;
30+ import { ITestDisplay , ITestResultDisplay , IUnitTestConfigurationService , IUnitTestManagementService , WorkspaceTestStatus } from './types' ;
3831
3932@injectable ( )
4033export class UnitTestManagementService implements IUnitTestManagementService , Disposable {
@@ -46,7 +39,8 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
4639 private testResultDisplay ?: ITestResultDisplay ;
4740 private autoDiscoverTimer ?: NodeJS . Timer ;
4841 private configChangedTimer ?: NodeJS . Timer ;
49- private readonly onDidChange : EventEmitter < void > = new EventEmitter < void > ( ) ;
42+ private testManagers = new Set < ITestManager > ( ) ;
43+ private readonly _onDidStatusChange : EventEmitter < WorkspaceTestStatus > = new EventEmitter < WorkspaceTestStatus > ( ) ;
5044
5145 constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ) {
5246 this . disposableRegistry = serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
@@ -61,6 +55,9 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
6155 this . workspaceTestManagerService . dispose ( ) ;
6256 }
6357 }
58+ public get onDidStatusChange ( ) : Event < WorkspaceTestStatus > {
59+ return this . _onDidStatusChange . event ;
60+ }
6461 public async activate ( symbolProvider : DocumentSymbolProvider ) : Promise < void > {
6562 this . workspaceTestManagerService = this . serviceContainer . get < IWorkspaceTestManagerService > ( IWorkspaceTestManagerService ) ;
6663 const disposablesRegistry = this . serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
@@ -78,11 +75,6 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
7875 await this . registerSymbolProvider ( symbolProvider ) ;
7976 }
8077
81- public async activateCodeLenses ( symbolProvider : DocumentSymbolProvider ) : Promise < void > {
82- const testCollectionStorage = this . serviceContainer . get < ITestCollectionStorageService > ( ITestCollectionStorageService ) ;
83- this . disposableRegistry . push ( activateCodeLenses ( this . onDidChange , symbolProvider , testCollectionStorage ) ) ;
84- }
85-
8678 public async getTestManager ( displayTestNotConfiguredMessage : boolean , resource ?: Uri ) : Promise < ITestManager | undefined | void > {
8779 let wkspace : Uri | undefined ;
8880 if ( resource ) {
@@ -97,6 +89,13 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
9789 }
9890 const testManager = this . workspaceTestManagerService ! . getTestManager ( wkspace ) ;
9991 if ( testManager ) {
92+ if ( ! this . testManagers . has ( testManager ) ) {
93+ this . testManagers . add ( testManager ) ;
94+ const handler = testManager . onDidStatusChange ( e => {
95+ this . _onDidStatusChange . fire ( { workspace : testManager . workspaceFolder , status : e } ) ;
96+ } ) ;
97+ this . disposableRegistry . push ( handler ) ;
98+ }
10099 return testManager ;
101100 }
102101 if ( displayTestNotConfiguredMessage ) {
@@ -178,7 +177,6 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
178177
179178 if ( ! this . testResultDisplay ) {
180179 this . testResultDisplay = this . serviceContainer . get < ITestResultDisplay > ( ITestResultDisplay ) ;
181- this . testResultDisplay . onDidChange ( ( ) => this . onDidChange . fire ( ) ) ;
182180 }
183181 const discoveryPromise = testManager . discoverTests ( cmdSource , ignoreCache , quietMode , userInitiated ) ;
184182 this . testResultDisplay . displayDiscoverStatus ( discoveryPromise , quietMode )
@@ -296,7 +294,6 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
296294
297295 if ( ! this . testResultDisplay ) {
298296 this . testResultDisplay = this . serviceContainer . get < ITestResultDisplay > ( ITestResultDisplay ) ;
299- this . testResultDisplay . onDidChange ( ( ) => this . onDidChange . fire ( ) ) ;
300297 }
301298
302299 const promise = testManager . runTest ( cmdSource , testsToRun , runFailedTests , debug )
@@ -313,7 +310,15 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
313310
314311 private async registerSymbolProvider ( symbolProvider : DocumentSymbolProvider ) : Promise < void > {
315312 const testCollectionStorage = this . serviceContainer . get < ITestCollectionStorageService > ( ITestCollectionStorageService ) ;
316- this . disposableRegistry . push ( activateCodeLenses ( this . onDidChange , symbolProvider , testCollectionStorage ) ) ;
313+ const event = new EventEmitter < void > ( ) ;
314+ this . disposableRegistry . push ( event ) ;
315+ const handler = this . _onDidStatusChange . event ( e => {
316+ if ( e . status !== TestStatus . Discovering && e . status !== TestStatus . Running ) {
317+ event . fire ( ) ;
318+ }
319+ } ) ;
320+ this . disposableRegistry . push ( handler ) ;
321+ this . disposableRegistry . push ( activateCodeLenses ( event , symbolProvider , testCollectionStorage ) ) ;
317322 }
318323
319324 @captureTelemetry ( EventName . UNITTEST_CONFIGURE , undefined , false )
@@ -341,13 +346,13 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
341346 // Ignore the exceptions returned.
342347 // This command will be invoked from other places of the extension.
343348 this . discoverTests ( cmdSource , resource , true , true )
344- . ignoreErrors ( ) ;
349+ . ignoreErrors ( ) ;
345350 } ) ,
346351 commandManager . registerCommand ( constants . Commands . Tests_Configure , ( _ , cmdSource : CommandSource = CommandSource . commandPalette , resource ?: Uri ) => {
347352 // Ignore the exceptions returned.
348353 // This command will be invoked from other places of the extension.
349354 this . configureTests ( resource )
350- . ignoreErrors ( ) ;
355+ . ignoreErrors ( ) ;
351356 } ) ,
352357 commandManager . registerCommand ( constants . Commands . Tests_Run_Failed , ( _ , cmdSource : CommandSource = CommandSource . commandPalette , resource : Uri ) => this . runTestsImpl ( cmdSource , resource , undefined , true ) ) ,
353358 commandManager . registerCommand ( constants . Commands . Tests_Run , ( _ , cmdSource : CommandSource = CommandSource . commandPalette , file : Uri , testToRun ?: TestsToRun ) => this . runTestsImpl ( cmdSource , file , testToRun ) ) ,
0 commit comments