8
8
*/
9
9
10
10
11
- import * as _ from "lodash" ;
11
+ import * as lodash from "lodash" ;
12
+ import * as path from "path" ;
13
+ import * as unescapeJS from "unescape-js" ;
14
+ import * as vscode from "vscode" ;
12
15
import { toNumber } from "lodash" ;
13
16
import { Disposable , Uri , window , QuickPickItem , workspace , WorkspaceConfiguration } from "vscode" ;
14
17
import { SearchNode , userContestRankingObj , userContestRanKingBase , UserStatus , IProblem , IQuickItemEx , languages , Category , defaultProblem , ProblemState , SortingStrategy , SearchSetTypeName , RootNodeSort , SearchSetType , ISubmitEvent , SORT_ORDER , Endpoint , OpenOption , DialogType , DialogOptions } from "../model/Model" ;
@@ -19,10 +22,6 @@ import { statusBarService } from "../service/StatusBarService";
19
22
import { previewService } from "../service/PreviewService" ;
20
23
import { executeService } from "../service/ExecuteService" ;
21
24
import { getNodeIdFromFile } from "../utils/SystemUtils" ;
22
-
23
- import * as path from "path" ;
24
- import * as unescapeJS from "unescape-js" ;
25
- import * as vscode from "vscode" ;
26
25
import { logOutput , promptForOpenOutputChannel , promptForSignIn , promptHintMessage } from "../utils/OutputUtils" ;
27
26
import { treeDataService } from "../service/TreeDataService" ;
28
27
import { genFileExt , genFileName } from "../utils/SystemUtils" ;
@@ -40,7 +39,7 @@ import * as os from "os";
40
39
import { getVsCodeConfig , getWorkspaceFolder } from "../utils/ConfigUtils" ;
41
40
42
41
43
-
42
+ // 视图控制器
44
43
class TreeViewController implements Disposable {
45
44
private explorerNodeMap : Map < string , NodeModel > = new Map < string , NodeModel > ( ) ;
46
45
private companySet : Set < string > = new Set < string > ( ) ;
@@ -49,8 +48,7 @@ class TreeViewController implements Disposable {
49
48
private waitTodayQuestion : boolean ;
50
49
private waitUserContest : boolean ;
51
50
52
-
53
-
51
+ // 获取当前文件的路径
54
52
public async getActiveFilePath ( uri ?: vscode . Uri ) : Promise < string | undefined > {
55
53
let textEditor : vscode . TextEditor | undefined ;
56
54
if ( uri ) {
@@ -63,12 +61,13 @@ class TreeViewController implements Disposable {
63
61
return undefined ;
64
62
}
65
63
if ( textEditor . document . isDirty && ! await textEditor . document . save ( ) ) {
66
- vscode . window . showWarningMessage ( "Please save the solution file first. " ) ;
64
+ vscode . window . showWarningMessage ( "请先保存当前文件 " ) ;
67
65
return undefined ;
68
66
}
69
67
return systemUtils . useWsl ( ) ? systemUtils . toWslPath ( textEditor . document . uri . fsPath ) : textEditor . document . uri . fsPath ;
70
68
}
71
69
70
+ // 提交问题
72
71
public async submitSolution ( uri ?: vscode . Uri ) : Promise < void > {
73
72
if ( ! statusBarService . getUser ( ) ) {
74
73
promptForSignIn ( ) ;
@@ -85,14 +84,15 @@ class TreeViewController implements Disposable {
85
84
submissionService . show ( result ) ;
86
85
eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
87
86
} catch ( error ) {
88
- await promptForOpenOutputChannel ( "Failed to submit the solution. Please open the output channel for details. " , DialogType . error ) ;
87
+ await promptForOpenOutputChannel ( "提交出错了. 请查看控制台信息~ " , DialogType . error ) ;
89
88
return ;
90
89
}
91
90
92
91
treeDataService . refresh ( ) ;
93
92
}
94
93
95
94
95
+ // 提交测试用例
96
96
public async testSolution ( uri ?: vscode . Uri ) : Promise < void > {
97
97
try {
98
98
if ( statusBarService . getStatus ( ) === UserStatus . SignedOut ) {
@@ -108,25 +108,25 @@ class TreeViewController implements Disposable {
108
108
{
109
109
label : "$(three-bars) Default test cases" ,
110
110
description : "" ,
111
- detail : "Test with the default cases " ,
111
+ detail : "默认用例 " ,
112
112
value : ":default" ,
113
113
} ,
114
114
{
115
115
label : "$(pencil) Write directly..." ,
116
116
description : "" ,
117
- detail : "Write test cases in input box " ,
117
+ detail : "输入框的测试用例 " ,
118
118
value : ":direct" ,
119
119
} ,
120
120
{
121
121
label : "$(file-text) Browse..." ,
122
122
description : "" ,
123
- detail : "Test with the written cases in file " ,
123
+ detail : "文件中的测试用例 " ,
124
124
value : ":file" ,
125
125
} ,
126
126
{
127
127
label : "All Default test cases..." ,
128
128
description : "" ,
129
- detail : "Test with the all default cases " ,
129
+ detail : "所有的测试用例 " ,
130
130
value : ":alldefault" ,
131
131
} ,
132
132
) ;
@@ -176,7 +176,7 @@ class TreeViewController implements Disposable {
176
176
submissionService . show ( result ) ;
177
177
eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
178
178
} catch ( error ) {
179
- await promptForOpenOutputChannel ( "Failed to test the solution. Please open the output channel for details. " , DialogType . error ) ;
179
+ await promptForOpenOutputChannel ( "提交测试出错了. 请查看控制台信息~ " , DialogType . error ) ;
180
180
}
181
181
}
182
182
public async showFileSelectDialog ( fsPath ?: string ) : Promise < vscode . Uri [ ] | undefined > {
@@ -210,7 +210,7 @@ class TreeViewController implements Disposable {
210
210
submissionService . show ( result ) ;
211
211
eventService . emit ( "submit" , submissionService . getSubmitEvent ( ) ) ;
212
212
} catch ( error ) {
213
- await promptForOpenOutputChannel ( "Failed to test the solution. Please open the output channel for details. " , DialogType . error ) ;
213
+ await promptForOpenOutputChannel ( "提交测试出错了. 请查看控制台信息~ " , DialogType . error ) ;
214
214
}
215
215
}
216
216
@@ -259,13 +259,13 @@ class TreeViewController implements Disposable {
259
259
{
260
260
label : `${ isCnEnabled ? "" : "$(check) " } LeetCode` ,
261
261
description : "leetcode.com" ,
262
- detail : `Enable LeetCode US` ,
262
+ detail : `Enable LeetCode.com US` ,
263
263
value : Endpoint . LeetCode ,
264
264
} ,
265
265
{
266
266
label : `${ isCnEnabled ? "$(check) " : "" } 力扣` ,
267
267
description : "leetcode.cn" ,
268
- detail : `启用中国版 LeetCode` ,
268
+ detail : `启用中国版 LeetCode.cn ` ,
269
269
value : Endpoint . LeetCodeCN ,
270
270
} ,
271
271
) ;
@@ -280,15 +280,15 @@ class TreeViewController implements Disposable {
280
280
await leetCodeConfig . update ( "endpoint" , endpoint , true /* UserSetting */ ) ;
281
281
vscode . window . showInformationMessage ( `Switched the endpoint to ${ endpoint } ` ) ;
282
282
} catch ( error ) {
283
- await promptForOpenOutputChannel ( "Failed to switch endpoint. Please open the output channel for details. " , DialogType . error ) ;
283
+ await promptForOpenOutputChannel ( "切换站点出错. 请查看控制台信息~ " , DialogType . error ) ;
284
284
}
285
285
286
286
try {
287
287
await vscode . commands . executeCommand ( "leetcode.signout" ) ;
288
288
await executeService . deleteCache ( ) ;
289
289
await promptForSignIn ( ) ;
290
290
} catch ( error ) {
291
- await promptForOpenOutputChannel ( "Failed to sign in. Please open the output channel for details. " , DialogType . error ) ;
291
+ await promptForOpenOutputChannel ( "登录失败. 请查看控制台信息~ " , DialogType . error ) ;
292
292
}
293
293
}
294
294
@@ -323,7 +323,7 @@ class TreeViewController implements Disposable {
323
323
fileButtonService . refresh ( ) ;
324
324
}
325
325
} catch ( error ) {
326
- await promptForOpenOutputChannel ( "Failed to add the problem to favorite. Please open the output channel for details. " , DialogType . error ) ;
326
+ await promptForOpenOutputChannel ( "添加喜欢题目失败. 请查看控制台信息~ " , DialogType . error ) ;
327
327
}
328
328
}
329
329
@@ -335,7 +335,7 @@ class TreeViewController implements Disposable {
335
335
fileButtonService . refresh ( ) ;
336
336
}
337
337
} catch ( error ) {
338
- await promptForOpenOutputChannel ( "Failed to remove the problem from favorite. Please open the output channel for details. " , DialogType . error ) ;
338
+ await promptForOpenOutputChannel ( "移除喜欢题目失败. 请查看控制台信息~ " , DialogType . error ) ;
339
339
}
340
340
}
341
341
@@ -372,7 +372,7 @@ class TreeViewController implements Disposable {
372
372
}
373
373
return problems . reverse ( ) ;
374
374
} catch ( error ) {
375
- await promptForOpenOutputChannel ( "Failed to list problems. Please open the output channel for details. " , DialogType . error ) ;
375
+ await promptForOpenOutputChannel ( "获取题目失败. 请查看控制台信息~ " , DialogType . error ) ;
376
376
return [ ] ;
377
377
}
378
378
}
@@ -419,7 +419,7 @@ class TreeViewController implements Disposable {
419
419
} ) ;
420
420
421
421
const selectedItem : QuickPickItem | undefined = await window . showQuickPick ( languageItems , {
422
- placeHolder : "Please the default language " ,
422
+ placeHolder : "请设置默认语言 " ,
423
423
ignoreFocusOut : true ,
424
424
} ) ;
425
425
@@ -428,7 +428,7 @@ class TreeViewController implements Disposable {
428
428
}
429
429
430
430
leetCodeConfig . update ( "defaultLanguage" , selectedItem . label , true /* Global */ ) ;
431
- window . showInformationMessage ( `Successfully set the default language to ${ selectedItem . label } ` ) ;
431
+ window . showInformationMessage ( `设置默认语言 ${ selectedItem . label } 成功 ` ) ;
432
432
}
433
433
434
434
@@ -595,7 +595,7 @@ class TreeViewController implements Disposable {
595
595
solutionService . show ( unescapeJS ( solution ) ) ;
596
596
} catch ( error ) {
597
597
logOutput . appendLine ( error . toString ( ) ) ;
598
- await promptForOpenOutputChannel ( "Failed to fetch the top voted solution. Please open the output channel for details. " , DialogType . error ) ;
598
+ await promptForOpenOutputChannel ( "Failed to fetch the top voted solution. 请查看控制台信息~ " , DialogType . error ) ;
599
599
}
600
600
}
601
601
@@ -619,7 +619,7 @@ class TreeViewController implements Disposable {
619
619
console . log ( query_result ) ;
620
620
} catch ( error ) {
621
621
logOutput . appendLine ( error . toString ( ) ) ;
622
- await promptForOpenOutputChannel ( "Failed to fetch today question. Please open the output channel for details. " , DialogType . error ) ;
622
+ await promptForOpenOutputChannel ( "Failed to fetch today question. 请查看控制台信息~ " , DialogType . error ) ;
623
623
}
624
624
}
625
625
@@ -809,7 +809,7 @@ class TreeViewController implements Disposable {
809
809
810
810
await Promise . all ( promises ) ;
811
811
} catch ( error ) {
812
- await promptForOpenOutputChannel ( `${ error } Please open the output channel for details. ` , DialogType . error ) ;
812
+ await promptForOpenOutputChannel ( `${ error } 请查看控制台信息~ ` , DialogType . error ) ;
813
813
}
814
814
}
815
815
@@ -892,7 +892,7 @@ class TreeViewController implements Disposable {
892
892
eventService . emit ( "searchUserContest" , tt ) ;
893
893
} catch ( error ) {
894
894
logOutput . appendLine ( error . toString ( ) ) ;
895
- await promptForOpenOutputChannel ( "Failed to fetch today question. Please open the output channel for details. " , DialogType . error ) ;
895
+ await promptForOpenOutputChannel ( "Failed to fetch today question. 请查看控制台信息~ " , DialogType . error ) ;
896
896
}
897
897
}
898
898
public async searchToday ( ) : Promise < void > {
@@ -920,7 +920,7 @@ class TreeViewController implements Disposable {
920
920
921
921
} catch ( error ) {
922
922
logOutput . appendLine ( error . toString ( ) ) ;
923
- await promptForOpenOutputChannel ( "Failed to fetch today question. Please open the output channel for details. " , DialogType . error ) ;
923
+ await promptForOpenOutputChannel ( "Failed to fetch today question. 请查看控制台信息~ " , DialogType . error ) ;
924
924
}
925
925
}
926
926
@@ -970,15 +970,15 @@ class TreeViewController implements Disposable {
970
970
case "name" :
971
971
return node . name ;
972
972
case "camelcasename" :
973
- return _ . camelCase ( node . name ) ;
973
+ return lodash . camelCase ( node . name ) ;
974
974
case "pascalcasename" :
975
- return _ . upperFirst ( _ . camelCase ( node . name ) ) ;
975
+ return lodash . upperFirst ( lodash . camelCase ( node . name ) ) ;
976
976
case "kebabcasename" :
977
977
case "kebab-case-name" :
978
- return _ . kebabCase ( node . name ) ;
978
+ return lodash . kebabCase ( node . name ) ;
979
979
case "snakecasename" :
980
980
case "snake_case_name" :
981
- return _ . snakeCase ( node . name ) ;
981
+ return lodash . snakeCase ( node . name ) ;
982
982
case "ext" :
983
983
return genFileExt ( selectedLanguage ) ;
984
984
case "language" :
@@ -1303,7 +1303,7 @@ class TreeViewController implements Disposable {
1303
1303
for ( const company of this . companySet . values ( ) ) {
1304
1304
res . push ( new NodeModel ( Object . assign ( { } , defaultProblem , {
1305
1305
id : `${ Category . Company } .${ company } ` ,
1306
- name : _ . startCase ( company ) ,
1306
+ name : lodash . startCase ( company ) ,
1307
1307
} ) , false ) ) ;
1308
1308
}
1309
1309
this . sortSubCategoryNodes ( res , Category . Company ) ;
@@ -1315,7 +1315,7 @@ class TreeViewController implements Disposable {
1315
1315
for ( const tag of this . tagSet . values ( ) ) {
1316
1316
res . push ( new NodeModel ( Object . assign ( { } , defaultProblem , {
1317
1317
id : `${ Category . Tag } .${ tag } ` ,
1318
- name : _ . startCase ( tag ) ,
1318
+ name : lodash . startCase ( tag ) ,
1319
1319
} ) , false ) ) ;
1320
1320
}
1321
1321
this . sortSubCategoryNodes ( res , Category . Tag ) ;
0 commit comments