55
66'use strict' ;
77
8- import { CancellationToken , CodeLens , Range , Uri , TextDocument , CodeLensProvider } from 'vscode' ;
9- import { toRange , toLocation } from '../omnisharp/typeConvertion' ;
10- import AbstractSupport from './abstractProvider' ;
11- import { updateCodeLensForTest } from './dotnetTest' ;
8+ import { OmniSharpServer } from '../omnisharp/server' ;
9+ import TelemetryReporter from 'vscode-extension-telemetry' ;
10+ import TestManager from './dotnetTest' ;
11+ import * as vscode from 'vscode' ;
12+ import { toRange , toLocation } from '../omnisharp/typeConvertion' ;
13+ import AbstractProvider from './abstractProvider' ;
1214import * as protocol from '../omnisharp/protocol' ;
1315import * as serverUtils from '../omnisharp/utils' ;
1416
15- class OmniSharpCodeLens extends CodeLens {
17+ class OmniSharpCodeLens extends vscode . CodeLens {
1618
1719 fileName : string ;
1820
19- constructor ( fileName : string , range : Range ) {
21+ constructor ( fileName : string , range : vscode . Range ) {
2022 super ( range ) ;
2123 this . fileName = fileName ;
2224 }
2325}
2426
25- export default class OmniSharpCodeLensProvider extends AbstractSupport implements CodeLensProvider {
27+ export default class OmniSharpCodeLensProvider extends AbstractProvider implements vscode . CodeLensProvider {
28+
29+ private _testManager : TestManager ;
30+
31+ constructor ( server : OmniSharpServer , reporter : TelemetryReporter , testManager : TestManager )
32+ {
33+ super ( server , reporter ) ;
34+
35+ this . _testManager = testManager ;
36+ }
2637
2738 private static filteredSymbolNames : { [ name : string ] : boolean } = {
2839 'Equals' : true ,
@@ -31,15 +42,15 @@ export default class OmniSharpCodeLensProvider extends AbstractSupport implement
3142 'ToString' : true
3243 } ;
3344
34- provideCodeLenses ( document : TextDocument , token : CancellationToken ) : CodeLens [ ] | Thenable < CodeLens [ ] > {
45+ provideCodeLenses ( document : vscode . TextDocument , token : vscode . CancellationToken ) : vscode . CodeLens [ ] | Thenable < vscode . CodeLens [ ] > {
3546 return serverUtils . currentFileMembersAsTree ( this . _server , { FileName : document . fileName } , token ) . then ( tree => {
36- let ret : CodeLens [ ] = [ ] ;
47+ let ret : vscode . CodeLens [ ] = [ ] ;
3748 tree . TopLevelTypeDefinitions . forEach ( node => this . _convertQuickFix ( ret , document . fileName , node ) ) ;
3849 return ret ;
3950 } ) ;
4051 }
4152
42- private _convertQuickFix ( bucket : CodeLens [ ] , fileName : string , node : protocol . Node ) : void {
53+ private _convertQuickFix ( bucket : vscode . CodeLens [ ] , fileName : string , node : protocol . Node ) : void {
4354
4455 if ( node . Kind === 'MethodDeclaration' && OmniSharpCodeLensProvider . filteredSymbolNames [ node . Location . Text ] ) {
4556 return ;
@@ -52,10 +63,10 @@ export default class OmniSharpCodeLensProvider extends AbstractSupport implement
5263 this . _convertQuickFix ( bucket , fileName , child ) ;
5364 }
5465
55- updateCodeLensForTest ( bucket , fileName , node , this . _server . isDebugEnable ( ) ) ;
66+ this . _updateCodeLensForTest ( bucket , fileName , node ) ;
5667 }
5768
58- resolveCodeLens ( codeLens : CodeLens , token : CancellationToken ) : Thenable < CodeLens > {
69+ resolveCodeLens ( codeLens : vscode . CodeLens , token : vscode . CancellationToken ) : Thenable < vscode . CodeLens > {
5970 if ( codeLens instanceof OmniSharpCodeLens ) {
6071
6172 let req = < protocol . FindUsagesRequest > {
@@ -75,11 +86,40 @@ export default class OmniSharpCodeLensProvider extends AbstractSupport implement
7586 codeLens . command = {
7687 title : len === 1 ? '1 reference' : `${ len } references` ,
7788 command : 'editor.action.showReferences' ,
78- arguments : [ Uri . file ( req . FileName ) , codeLens . range . start , res . QuickFixes . map ( toLocation ) ]
89+ arguments : [ vscode . Uri . file ( req . FileName ) , codeLens . range . start , res . QuickFixes . map ( toLocation ) ]
7990 } ;
8091
8192 return codeLens ;
8293 } ) ;
8394 }
8495 }
96+
97+ private _updateCodeLensForTest ( bucket : vscode . CodeLens [ ] , fileName : string , node : protocol . Node ) {
98+ // backward compatible check: Features property doesn't present on older version OmniSharp
99+ if ( node . Features === undefined ) {
100+ return ;
101+ }
102+
103+ let testFeature = node . Features . find ( value => ( value . Name == 'XunitTestMethod' || value . Name == 'NUnitTestMethod' || value . Name == 'MSTestMethod' ) ) ;
104+ if ( testFeature ) {
105+ // this test method has a test feature
106+ let testFrameworkName = 'xunit' ;
107+ if ( testFeature . Name == 'NunitTestMethod' ) {
108+ testFrameworkName = 'nunit' ;
109+ }
110+ else if ( testFeature . Name == 'MSTestMethod' ) {
111+ testFrameworkName = 'mstest' ;
112+ }
113+
114+ bucket . push ( new vscode . CodeLens (
115+ toRange ( node . Location ) ,
116+ { title : "run test" , command : 'dotnet.test.run' , arguments : [ testFeature . Data , fileName , testFrameworkName ] } ) ) ;
117+
118+ if ( this . _server . isDebugEnable ( ) ) {
119+ bucket . push ( new vscode . CodeLens (
120+ toRange ( node . Location ) ,
121+ { title : "debug test" , command : 'dotnet.test.debug' , arguments : [ testFeature . Data , fileName , testFrameworkName ] } ) ) ;
122+ }
123+ }
124+ }
85125}
0 commit comments