@@ -10,7 +10,7 @@ import {
1010 SlotLocation ,
1111} from '@opensumi/ide-core-browser' ;
1212import { IContextKey , IContextKeyService } from '@opensumi/ide-core-browser/lib/context-key' ;
13- import { TestingServiceProviderCount } from '@opensumi/ide-core-browser/lib/contextkey/testing' ;
13+ import { TestingCanRefreshTests , TestingServiceProviderCount } from '@opensumi/ide-core-browser/lib/contextkey/testing' ;
1414import { IMainLayoutService } from '@opensumi/ide-main-layout' ;
1515
1616import { AmbiguousRunTestsRequest , ITestController , ITestService , TestId } from '../common' ;
@@ -27,6 +27,7 @@ import { TestingView } from './components/testing.view';
2727export class TestServiceImpl extends Disposable implements ITestService {
2828 private controllers = new Map < string , ITestController > ( ) ;
2929 private controllerCount : IContextKey < number > ;
30+ private canRefreshTests : IContextKey < boolean > ;
3031
3132 private readonly processDiffEmitter = new Emitter < TestsDiff > ( ) ;
3233 private viewId = '' ;
@@ -49,6 +50,24 @@ export class TestServiceImpl extends Disposable implements ITestService {
4950 constructor ( ) {
5051 super ( ) ;
5152 this . controllerCount = TestingServiceProviderCount . bind ( this . contextKeyService ) ;
53+ this . canRefreshTests = TestingCanRefreshTests . bind ( this . contextKeyService ) ;
54+ }
55+
56+ public getTestController ( controllerId : string ) : ITestController | undefined {
57+ return this . controllers . get ( controllerId ) ;
58+ }
59+
60+ public async refreshTests ( controllerId ?: string ) : Promise < void > {
61+ const cts = new CancellationTokenSource ( ) ;
62+ try {
63+ if ( controllerId ) {
64+ await this . controllers . get ( controllerId ) ?. refreshTests ( cts . token ) ;
65+ } else {
66+ await Promise . all ( [ ...this . controllers . values ( ) ] . map ( ( c ) => c . refreshTests ( cts . token ) ) ) ;
67+ }
68+ } finally {
69+ cts . dispose ( true ) ;
70+ }
5271 }
5372
5473 private registerTestingExplorerView ( ) : string {
@@ -70,27 +89,41 @@ export class TestServiceImpl extends Disposable implements ITestService {
7089 registerTestController ( id : string , testController : ITestController ) : IDisposable {
7190 this . controllers . set ( id , testController ) ;
7291 this . controllerCount . set ( this . controllers . size ) ;
92+ this . updateCanRefresh ( ) ;
7393
7494 if ( this . controllers . size > 0 && ! this . viewId ) {
7595 this . viewId = this . registerTestingExplorerView ( ) ;
7696 }
7797
78- return Disposable . create ( ( ) => {
79- const diff : TestsDiff = [ ] ;
80- for ( const root of this . collection . rootItems ) {
81- if ( root . controllerId === id ) {
82- diff . push ( [ TestDiffOpType . Remove , root . item . extId ] ) ;
83- }
84- }
85- this . publishDiff ( id , diff ) ;
98+ const disposable = new Disposable ( ) ;
8699
87- if ( this . controllers . delete ( id ) ) {
88- this . controllerCount . set ( this . controllers . size ) ;
89- if ( this . controllers . size === 0 && this . viewId ) {
90- this . mainlayoutService . disposeContainer ( this . viewId ) ;
100+ disposable . addDispose (
101+ Disposable . create ( ( ) => {
102+ const diff : TestsDiff = [ ] ;
103+ for ( const root of this . collection . rootItems ) {
104+ if ( root . controllerId === id ) {
105+ diff . push ( [ TestDiffOpType . Remove , root . item . extId ] ) ;
106+ }
91107 }
92- }
93- } ) ;
108+ this . publishDiff ( id , diff ) ;
109+
110+ if ( this . controllers . delete ( id ) ) {
111+ this . controllerCount . set ( this . controllers . size ) ;
112+ this . updateCanRefresh ( ) ;
113+ if ( this . controllers . size === 0 && this . viewId ) {
114+ this . mainlayoutService . disposeContainer ( this . viewId ) ;
115+ }
116+ }
117+ } ) ,
118+ ) ;
119+
120+ disposable . addDispose ( testController . canRefresh . onDidChange ( this . updateCanRefresh , this ) ) ;
121+
122+ return disposable ;
123+ }
124+
125+ private updateCanRefresh ( ) {
126+ this . canRefreshTests . set ( Array . from ( this . controllers . values ( ) ) . some ( ( c ) => c . canRefresh ) ) ;
94127 }
95128
96129 public async expandTest ( id : string , levels : number ) {
0 commit comments