11'use strict' ;
22
33import * as vscode from 'vscode' ;
4- import { CodeLensProvider , TextDocument , CancellationToken , CodeLens , SymbolInformation } from 'vscode' ;
5- import { TestFile , TestsToRun , TestSuite , TestFunction } from '../common/contracts' ;
4+ import { CodeLensProvider , TextDocument , CancellationToken , CodeLens , SymbolInformation } from 'vscode' ;
5+ import { TestFile , TestsToRun , TestSuite , TestFunction } from '../common/contracts' ;
66import * as constants from '../../common/constants' ;
7- import { getDiscoveredTests } from '../common/testUtils' ;
7+ import { getDiscoveredTests } from '../common/testUtils' ;
88
99interface CodeLensData {
1010 symbolKind : vscode . SymbolKind ;
@@ -69,7 +69,7 @@ function getCodeLenses(documentUri: vscode.Uri, token: vscode.CancellationToken)
6969
7070 return getCodeLens ( documentUri . fsPath , allFuncsAndSuites ,
7171 range , symbol . name , symbol . kind ) ;
72- } ) . filter ( codeLens => codeLens !== null ) ;
72+ } ) . reduce ( ( previous , current ) => previous . concat ( current ) , [ ] ) . filter ( codeLens => codeLens !== null ) ;
7373 } , reason => {
7474 if ( token . isCancellationRequested ) {
7575 return [ ] ;
@@ -82,7 +82,7 @@ function getCodeLenses(documentUri: vscode.Uri, token: vscode.CancellationToken)
8282const testParametirizedFunction = / .* \[ .* \] / g;
8383
8484function getCodeLens ( fileName : string , allFuncsAndSuites : FunctionsAndSuites ,
85- range : vscode . Range , symbolName : string , symbolKind : vscode . SymbolKind ) : vscode . CodeLens {
85+ range : vscode . Range , symbolName : string , symbolKind : vscode . SymbolKind ) : vscode . CodeLens [ ] {
8686
8787 switch ( symbolKind ) {
8888 case vscode . SymbolKind . Function :
@@ -94,27 +94,41 @@ function getCodeLens(fileName: string, allFuncsAndSuites: FunctionsAndSuites,
9494 if ( ! cls ) {
9595 return null ;
9696 }
97- return new CodeLens ( range , {
98- title : constants . Text . CodeLensUnitTest ,
99- command : constants . Commands . Tests_Run ,
100- arguments : [ < TestsToRun > { testSuite : [ cls ] } ]
101- } ) ;
97+ return [
98+ new CodeLens ( range , {
99+ title : constants . Text . CodeLensRunUnitTest ,
100+ command : constants . Commands . Tests_Run ,
101+ arguments : [ < TestsToRun > { testSuite : [ cls ] } ]
102+ } ) ,
103+ new CodeLens ( range , {
104+ title : constants . Text . CodeLensDebugUnitTest ,
105+ command : constants . Commands . Tests_Debug ,
106+ arguments : [ < TestsToRun > { testSuite : [ cls ] } ]
107+ } )
108+ ] ;
102109 }
103110 }
104111
105112 return null ;
106113}
107114
108115function getFunctionCodeLens ( filePath : string , functionsAndSuites : FunctionsAndSuites ,
109- symbolName : string , range : vscode . Range ) : vscode . CodeLens {
116+ symbolName : string , range : vscode . Range ) : vscode . CodeLens [ ] {
110117
111118 const fn = functionsAndSuites . functions . find ( fn => fn . name === symbolName ) ;
112119 if ( fn ) {
113- return new CodeLens ( range , {
114- title : constants . Text . CodeLensUnitTest ,
115- command : constants . Commands . Tests_Run ,
116- arguments : [ < TestsToRun > { testFunction : [ fn ] } ]
117- } ) ;
120+ return [
121+ new CodeLens ( range , {
122+ title : constants . Text . CodeLensRunUnitTest ,
123+ command : constants . Commands . Tests_Run ,
124+ arguments : [ < TestsToRun > { testFunction : [ fn ] } ]
125+ } ) ,
126+ new CodeLens ( range , {
127+ title : constants . Text . CodeLensDebugUnitTest ,
128+ command : constants . Commands . Tests_Debug ,
129+ arguments : [ < TestsToRun > { testFunction : [ fn ] } ]
130+ } )
131+ ] ;
118132 }
119133
120134 // Ok, possible we're dealing with parameterized unit tests
@@ -124,19 +138,33 @@ function getFunctionCodeLens(filePath: string, functionsAndSuites: FunctionsAndS
124138 return null ;
125139 }
126140 if ( functions . length === 0 ) {
127- return new CodeLens ( range , {
128- title : constants . Text . CodeLensUnitTest ,
129- command : constants . Commands . Tests_Run ,
130- arguments : [ < TestsToRun > { testFunction : functions } ]
131- } ) ;
141+ return [
142+ new CodeLens ( range , {
143+ title : constants . Text . CodeLensRunUnitTest ,
144+ command : constants . Commands . Tests_Run ,
145+ arguments : [ < TestsToRun > { testFunction : functions } ]
146+ } ) ,
147+ new CodeLens ( range , {
148+ title : constants . Text . CodeLensDebugUnitTest ,
149+ command : constants . Commands . Tests_Debug ,
150+ arguments : [ < TestsToRun > { testFunction : functions } ]
151+ } )
152+ ] ;
132153 }
133154
134155 // Find all flattened functions
135- return new CodeLens ( range , {
136- title : constants . Text . CodeLensUnitTest + ' (Multiple)' ,
137- command : constants . Commands . Tests_Picker_UI ,
138- arguments : [ filePath , functions ]
139- } ) ;
156+ return [
157+ new CodeLens ( range , {
158+ title : constants . Text . CodeLensRunUnitTest + ' (Multiple)' ,
159+ command : constants . Commands . Tests_Picker_UI ,
160+ arguments : [ filePath , functions ]
161+ } ) ,
162+ new CodeLens ( range , {
163+ title : constants . Text . CodeLensDebugUnitTest + ' (Multiple)' ,
164+ command : constants . Commands . Tests_Picker_UI_Debug ,
165+ arguments : [ filePath , functions ]
166+ } )
167+ ] ;
140168}
141169
142170function getAllTestSuitesAndFunctionsPerFile ( testFile : TestFile ) : FunctionsAndSuites {
0 commit comments