@@ -11,6 +11,7 @@ import * as lodash from "lodash";
11
11
import * as path from "path" ;
12
12
import * as vscode from "vscode" ;
13
13
import { toNumber } from "lodash" ;
14
+ import * as fs from "fs" ;
14
15
import { Disposable , Uri , window , workspace , ConfigurationChangeEvent } from "vscode" ;
15
16
import {
16
17
SearchNode ,
@@ -30,6 +31,9 @@ import {
30
31
SORT_ORDER ,
31
32
Endpoint ,
32
33
OutPutType ,
34
+ TestSolutionType ,
35
+ ITestSolutionData ,
36
+ defaultTestSolutionData ,
33
37
} from "../model/Model" ;
34
38
import {
35
39
isHideSolvedProblem ,
@@ -75,6 +79,7 @@ import * as fse from "fs-extra";
75
79
import { submissionService } from "../service/SubmissionService" ;
76
80
import { bricksDataService } from "../service/BricksDataService" ;
77
81
import { groupDao } from "../dao/groupDao" ;
82
+ import { fileMeta , ProblemMeta } from "../utils/problemUtils" ;
78
83
79
84
// 视图控制器
80
85
class TreeViewController implements Disposable {
@@ -118,8 +123,10 @@ class TreeViewController implements Disposable {
118
123
119
124
try {
120
125
const result : string = await executeService . submitSolution ( filePath ) ;
121
- submissionService . show ( result ) ;
122
- eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
126
+
127
+ eventService . emit ( "submitSolutionResult" , result ) ;
128
+ // submissionService.show(result);
129
+ // eventService.emit("submit", submissionService.getSubmitEvent());
123
130
} catch ( error ) {
124
131
await promptForOpenOutputChannel ( "提交出错了. 请查看控制台信息~" , OutPutType . error ) ;
125
132
return ;
@@ -147,12 +154,6 @@ class TreeViewController implements Disposable {
147
154
}
148
155
const picks : Array < IQuickItemEx < string > > = [ ] ;
149
156
picks . push (
150
- // {
151
- // label: "$(three-bars) Default test cases",
152
- // description: "",
153
- // detail: "默认用例",
154
- // value: ":default",
155
- // },
156
157
{
157
158
label : "$(pencil) Write directly..." ,
158
159
description : "" ,
@@ -165,12 +166,6 @@ class TreeViewController implements Disposable {
165
166
detail : "文件中的测试用例" ,
166
167
value : ":file" ,
167
168
}
168
- // {
169
- // label: "All Default test cases...",
170
- // description: "",
171
- // detail: "所有的测试用例",
172
- // value: ":alldefault",
173
- // },
174
169
) ;
175
170
const choice : IQuickItemEx < string > | undefined = await vscode . window . showQuickPick ( picks ) ;
176
171
if ( ! choice ) {
@@ -180,10 +175,10 @@ class TreeViewController implements Disposable {
180
175
let result : string | undefined ;
181
176
let testString : string | undefined ;
182
177
let testFile : vscode . Uri [ ] | undefined ;
178
+
179
+ let tsd : ITestSolutionData = Object . assign ( { } , defaultTestSolutionData , { } ) ;
180
+
183
181
switch ( choice . value ) {
184
- case ":default" :
185
- result = await executeService . testSolution ( filePath ) ;
186
- break ;
187
182
case ":direct" :
188
183
testString = await vscode . window . showInputBox ( {
189
184
prompt : "Enter the test cases." ,
@@ -193,34 +188,39 @@ class TreeViewController implements Disposable {
193
188
ignoreFocusOut : true ,
194
189
} ) ;
195
190
if ( testString ) {
196
- result = await executeService . testSolution ( filePath , this . parseTestString ( testString ) ) ;
191
+ tsd . filePath = filePath ;
192
+ tsd . testString = this . parseTestString ( testString ) ;
193
+ tsd . allCase = false ;
194
+ tsd . type = TestSolutionType . Type_1 ;
195
+ result = await executeService . testSolution ( tsd . filePath , tsd . testString , tsd . allCase ) ;
196
+ tsd . result = result ;
197
197
}
198
198
break ;
199
199
case ":file" :
200
200
testFile = await this . showFileSelectDialog ( filePath ) ;
201
201
if ( testFile && testFile . length ) {
202
202
const input : string = ( await fse . readFile ( testFile [ 0 ] . fsPath , "utf-8" ) ) . trim ( ) ;
203
203
if ( input ) {
204
- result = await executeService . testSolution (
205
- filePath ,
206
- this . parseTestString ( input . replace ( / \r ? \n / g, "\\n" ) )
207
- ) ;
204
+ tsd . filePath = filePath ;
205
+ tsd . testString = this . parseTestString ( input . replace ( / \r ? \n / g, "\\n" ) ) ;
206
+ tsd . allCase = false ;
207
+ result = await executeService . testSolution ( tsd . filePath , tsd . testString , tsd . allCase ) ;
208
+ tsd . result = result ;
209
+ tsd . type = TestSolutionType . Type_2 ;
208
210
} else {
209
211
vscode . window . showErrorMessage ( "The selected test file must not be empty." ) ;
210
212
}
211
213
}
212
214
break ;
213
- case ":alldefault" :
214
- result = await executeService . testSolution ( filePath , undefined , true ) ;
215
- break ;
216
215
default :
217
216
break ;
218
217
}
219
218
if ( ! result ) {
220
219
return ;
221
220
}
222
- submissionService . show ( result ) ;
223
- eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
221
+ // submissionService.show(result);
222
+ // eventService.emit("submit", submissionService.getSubmitEvent());
223
+ eventService . emit ( "testSolutionResult" , result , tsd ) ;
224
224
} catch ( error ) {
225
225
await promptForOpenOutputChannel ( "提交测试出错了. 请查看控制台信息~" , OutPutType . error ) ;
226
226
}
@@ -263,12 +263,64 @@ class TreeViewController implements Disposable {
263
263
return ;
264
264
}
265
265
266
- let result : string | undefined = await executeService . testSolution ( filePath , undefined , allCase || false ) ;
266
+ let tsd : ITestSolutionData = Object . assign ( { } , defaultTestSolutionData , { } ) ;
267
+ tsd . filePath = filePath ;
268
+ tsd . testString = undefined ;
269
+ tsd . allCase = allCase || false ;
270
+ tsd . type = TestSolutionType . Type_3 ;
271
+ let result : string | undefined = await executeService . testSolution ( tsd . filePath , tsd . testString , tsd . allCase ) ;
272
+ tsd . result = result ;
273
+ if ( ! result ) {
274
+ return ;
275
+ }
276
+ // submissionService.show(result);
277
+ // eventService.emit("submit", submissionService.getSubmitEvent());
278
+ eventService . emit ( "testSolutionResult" , result , tsd ) ;
279
+ } catch ( error ) {
280
+ await promptForOpenOutputChannel ( "提交测试出错了. 请查看控制台信息~" , OutPutType . error ) ;
281
+ }
282
+ }
283
+
284
+ // 提交测试用例
285
+ /**
286
+ * It takes the current file, and sends it to the server to be tested
287
+ * @param [uri] - The file path of the file to be submitted. If it is not passed, the currently active
288
+ * file is submitted.
289
+ */
290
+ public async reTestSolution ( uri ?: vscode . Uri ) : Promise < void > {
291
+ try {
292
+ if ( statusBarService . getStatus ( ) === UserStatus . SignedOut ) {
293
+ return ;
294
+ }
295
+
296
+ const filePath : string | undefined = await getTextEditorFilePathByUri ( uri ) ;
297
+ if ( ! filePath ) {
298
+ return ;
299
+ }
300
+ const fileContent : Buffer = fs . readFileSync ( filePath ) ;
301
+ const meta : ProblemMeta | null = fileMeta ( fileContent . toString ( ) ) ;
302
+
303
+ let qid : string | undefined = undefined ;
304
+ if ( meta ?. id != undefined ) {
305
+ qid = this . getQidByFid ( meta ?. id ) ;
306
+ }
307
+
308
+ if ( qid == undefined ) {
309
+ return ;
310
+ }
311
+
312
+ let tsd : ITestSolutionData | undefined = submissionService . getTSDByQid ( qid ) ;
313
+ if ( tsd == undefined ) {
314
+ return ;
315
+ }
316
+
317
+ let result : string | undefined = await executeService . testSolution ( tsd . filePath , tsd . testString , tsd . allCase ) ;
267
318
if ( ! result ) {
268
319
return ;
269
320
}
270
- submissionService . show ( result ) ;
271
- eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
321
+ // submissionService.show(result);
322
+ // eventService.emit("submit", submissionService.getSubmitEvent());
323
+ eventService . emit ( "testSolutionResult" , result , tsd ) ;
272
324
} catch ( error ) {
273
325
await promptForOpenOutputChannel ( "提交测试出错了. 请查看控制台信息~" , OutPutType . error ) ;
274
326
}
@@ -294,12 +346,19 @@ class TreeViewController implements Disposable {
294
346
return ;
295
347
}
296
348
297
- let result : string | undefined = await executeService . testSolution ( filePath , testcase , false ) ;
349
+ let tsd : ITestSolutionData = Object . assign ( { } , defaultTestSolutionData , { } ) ;
350
+ tsd . filePath = filePath ;
351
+ tsd . testString = testcase ;
352
+ tsd . allCase = false ;
353
+ tsd . type = TestSolutionType . Type_4 ;
354
+ let result : string | undefined = await executeService . testSolution ( tsd . filePath , tsd . testString , tsd . allCase ) ;
355
+ tsd . result = result ;
298
356
if ( ! result ) {
299
357
return ;
300
358
}
301
- submissionService . show ( result ) ;
302
- eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
359
+ // submissionService.show(result);
360
+ // eventService.emit("submit", submissionService.getSubmitEvent());
361
+ eventService . emit ( "testSolutionResult" , result , tsd ) ;
303
362
} catch ( error ) {
304
363
await promptForOpenOutputChannel ( "提交测试出错了. 请查看控制台信息~" , OutPutType . error ) ;
305
364
}
0 commit comments