@@ -37,65 +37,79 @@ async function runTestsInContext(
37
37
await runTests ( request , languageServer , dotnetTestChannel ) ;
38
38
}
39
39
40
+ let _testRunInProgress = false ;
41
+
40
42
async function runTests (
41
43
request : RunTestsParams ,
42
44
languageServer : RoslynLanguageServer ,
43
45
dotnetTestChannel : vscode . OutputChannel
44
46
) {
47
+ if ( _testRunInProgress ) {
48
+ vscode . window . showErrorMessage ( 'Test run already in progress' ) ;
49
+ return ;
50
+ }
51
+
52
+ _testRunInProgress = true ;
53
+
45
54
dotnetTestChannel . show ( true ) ;
46
- vscode . window . withProgress (
47
- {
48
- location : vscode . ProgressLocation . Notification ,
49
- title : 'Dotnet Test' ,
50
- cancellable : true ,
51
- } ,
52
- async ( progress , token ) => {
53
- let totalReportedComplete = 0 ;
54
- const writeOutput = ( output : RunTestsPartialResult ) => {
55
- if ( output . message ) {
56
- dotnetTestChannel . appendLine ( output . message ) ;
57
- }
55
+ vscode . window
56
+ . withProgress (
57
+ {
58
+ location : vscode . ProgressLocation . Notification ,
59
+ title : 'Dotnet Test' ,
60
+ cancellable : true ,
61
+ } ,
62
+ async ( progress , token ) => {
63
+ let totalReportedComplete = 0 ;
64
+ const writeOutput = ( output : RunTestsPartialResult ) => {
65
+ if ( output . message ) {
66
+ dotnetTestChannel . appendLine ( output . message ) ;
67
+ }
58
68
59
- if ( output . progress ) {
60
- const totalTests = output . progress . totalTests ;
61
- const completed =
62
- output . progress . testsPassed + output . progress . testsFailed + output . progress . testsSkipped ;
69
+ if ( output . progress ) {
70
+ const totalTests = output . progress . totalTests ;
71
+ const completed =
72
+ output . progress . testsPassed + output . progress . testsFailed + output . progress . testsSkipped ;
63
73
64
- // VSCode requires us to report the additional amount completed (in x out of 100) from this report compared to what we've previously reported.
65
- const reportIncrement = ( ( completed - totalReportedComplete ) / totalTests ) * 100 ;
66
- progress . report ( { message : output . stage , increment : reportIncrement } ) ;
67
- totalReportedComplete = completed ;
68
- } else {
69
- progress . report ( { message : output . stage } ) ;
70
- }
71
- } ;
74
+ // VSCode requires us to report the additional amount completed (in x out of 100) from this report compared to what we've previously reported.
75
+ const reportIncrement = ( ( completed - totalReportedComplete ) / totalTests ) * 100 ;
76
+ progress . report ( { message : output . stage , increment : reportIncrement } ) ;
77
+ totalReportedComplete = completed ;
78
+ } else {
79
+ progress . report ( { message : output . stage } ) ;
80
+ }
81
+ } ;
72
82
73
- progress . report ( { message : 'Saving files...' } ) ;
74
- // Ensure all files are saved before we run tests so they accurately reflect what the user has requested to run.
75
- await vscode . workspace . saveAll ( /*includeUntitled*/ false ) ;
83
+ progress . report ( { message : 'Saving files...' } ) ;
84
+ // Ensure all files are saved before we run tests so they accurately reflect what the user has requested to run.
85
+ await vscode . workspace . saveAll ( /*includeUntitled*/ false ) ;
76
86
77
- progress . report ( { message : 'Requesting server...' } ) ;
78
- const responsePromise = languageServer . sendRequestWithProgress (
79
- RunTestsRequest . type ,
80
- request ,
81
- async ( p ) => {
82
- writeOutput ( p ) ;
83
- } ,
84
- token
85
- ) ;
87
+ progress . report ( { message : 'Requesting server...' } ) ;
88
+ const responsePromise = languageServer . sendRequestWithProgress (
89
+ RunTestsRequest . type ,
90
+ request ,
91
+ async ( p ) => {
92
+ writeOutput ( p ) ;
93
+ } ,
94
+ token
95
+ ) ;
86
96
87
- await responsePromise . then (
88
- ( result ) => {
89
- result . forEach ( ( r ) => {
90
- writeOutput ( r ) ;
91
- } ) ;
92
- return ;
93
- } ,
94
- ( err ) => {
95
- dotnetTestChannel . appendLine ( err ) ;
96
- return ;
97
- }
98
- ) ;
99
- }
100
- ) ;
97
+ await responsePromise . then (
98
+ ( result ) => {
99
+ result . forEach ( ( r ) => {
100
+ writeOutput ( r ) ;
101
+ } ) ;
102
+ return ;
103
+ } ,
104
+ ( err ) => {
105
+ dotnetTestChannel . appendLine ( err ) ;
106
+ return ;
107
+ }
108
+ ) ;
109
+ }
110
+ )
111
+ . then (
112
+ ( ) => ( _testRunInProgress = false ) ,
113
+ ( ) => ( _testRunInProgress = false )
114
+ ) ;
101
115
}
0 commit comments