3
3
// tslint:disable:no-duplicate-imports no-unnecessary-callback-wrapper
4
4
5
5
import { inject , injectable } from 'inversify' ;
6
- import { ConfigurationChangeEvent , Disposable , OutputChannel , TextDocument , Uri } from 'vscode' ;
7
- import * as vscode from 'vscode' ;
8
- import { ICommandManager , IDocumentManager , IWorkspaceService } from '../common/application/types' ;
6
+ import {
7
+ ConfigurationChangeEvent , Disposable ,
8
+ DocumentSymbolProvider , EventEmitter ,
9
+ OutputChannel , TextDocument , Uri , window
10
+ } from 'vscode' ;
11
+ import {
12
+ ICommandManager , IDocumentManager , IWorkspaceService
13
+ } from '../common/application/types' ;
9
14
import * as constants from '../common/constants' ;
10
15
import '../common/extensions' ;
11
- import { IConfigurationService , IDisposableRegistry , ILogger , IOutputChannel } from '../common/types' ;
16
+ import {
17
+ IConfigurationService , IDisposableRegistry ,
18
+ ILogger , IOutputChannel
19
+ } from '../common/types' ;
12
20
import { IServiceContainer } from '../ioc/types' ;
21
+ import { ITestTreeViewProvider } from '../providers/types' ;
13
22
import { EventName } from '../telemetry/constants' ;
14
23
import { sendTelemetryEvent } from '../telemetry/index' ;
15
24
import { activateCodeLenses } from './codeLenses/main' ;
16
- import { CANCELLATION_REASON , CommandSource , TEST_OUTPUT_CHANNEL } from './common/constants' ;
25
+ import {
26
+ CANCELLATION_REASON , CommandSource , TEST_OUTPUT_CHANNEL
27
+ } from './common/constants' ;
17
28
import { selectTestWorkspace } from './common/testUtils' ;
18
- import { ITestCollectionStorageService , ITestManager , IWorkspaceTestManagerService , TestFile , TestFunction , TestStatus , TestsToRun } from './common/types' ;
19
- import { ITestDisplay , ITestResultDisplay , IUnitTestConfigurationService , IUnitTestManagementService } from './types' ;
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' ;
20
38
21
39
@injectable ( )
22
40
export class UnitTestManagementService implements IUnitTestManagementService , Disposable {
23
- private readonly outputChannel : vscode . OutputChannel ;
41
+ private readonly outputChannel : OutputChannel ;
24
42
private readonly disposableRegistry : Disposable [ ] ;
25
43
private workspaceTestManagerService ?: IWorkspaceTestManagerService ;
26
44
private documentManager : IDocumentManager ;
27
45
private workspaceService : IWorkspaceService ;
28
46
private testResultDisplay ?: ITestResultDisplay ;
29
47
private autoDiscoverTimer ?: NodeJS . Timer ;
30
48
private configChangedTimer ?: NodeJS . Timer ;
31
- private readonly onDidChange : vscode . EventEmitter < void > = new vscode . EventEmitter < void > ( ) ;
49
+ private readonly onDidChange : EventEmitter < void > = new EventEmitter < void > ( ) ;
32
50
33
51
constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ) {
34
52
this . disposableRegistry = serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
@@ -43,15 +61,28 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
43
61
this . workspaceTestManagerService . dispose ( ) ;
44
62
}
45
63
}
46
- public async activate ( symboldProvider : vscode . DocumentSymbolProvider ) : Promise < void > {
64
+ public async activate ( symbolProvider : DocumentSymbolProvider ) : Promise < void > {
47
65
this . workspaceTestManagerService = this . serviceContainer . get < IWorkspaceTestManagerService > ( IWorkspaceTestManagerService ) ;
66
+ const disposablesRegistry = this . serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
48
67
49
68
this . registerHandlers ( ) ;
50
69
this . registerCommands ( ) ;
70
+
71
+ // register provider...
72
+ const testViewProvider = this . serviceContainer . get < ITestTreeViewProvider > ( ITestTreeViewProvider ) ;
73
+ const disposable = window . registerTreeDataProvider ( 'python_tests' , testViewProvider ) ;
74
+ disposablesRegistry . push ( disposable ) ;
75
+
51
76
this . autoDiscoverTests ( )
52
77
. catch ( ex => this . serviceContainer . get < ILogger > ( ILogger ) . logError ( 'Failed to auto discover tests upon activation' , ex ) ) ;
53
- await this . registerSymbolProvider ( symboldProvider ) ;
78
+ await this . registerSymbolProvider ( symbolProvider ) ;
54
79
}
80
+
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
+
55
86
public async getTestManager ( displayTestNotConfiguredMessage : boolean , resource ?: Uri ) : Promise < ITestManager | undefined | void > {
56
87
let wkspace : Uri | undefined ;
57
88
if ( resource ) {
@@ -278,9 +309,9 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
278
309
this . testResultDisplay . displayProgressStatus ( promise , debug ) ;
279
310
await promise ;
280
311
}
281
- private async registerSymbolProvider ( symboldProvider : vscode . DocumentSymbolProvider ) : Promise < void > {
312
+ private async registerSymbolProvider ( symbolProvider : DocumentSymbolProvider ) : Promise < void > {
282
313
const testCollectionStorage = this . serviceContainer . get < ITestCollectionStorageService > ( ITestCollectionStorageService ) ;
283
- this . disposableRegistry . push ( activateCodeLenses ( this . onDidChange , symboldProvider , testCollectionStorage ) ) ;
314
+ this . disposableRegistry . push ( activateCodeLenses ( this . onDidChange , symbolProvider , testCollectionStorage ) ) ;
284
315
}
285
316
private registerCommands ( ) : void {
286
317
const disposablesRegistry = this . serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
0 commit comments