Skip to content

Commit 569b91a

Browse files
committed
update
1 parent 1b3444a commit 569b91a

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

src/controller/LoginController.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import { treeDataService } from "../service/TreeDataService";
2121
import { getLeetCodeEndpoint } from "../utils/ConfigUtils";
2222

2323

24-
// 登录
24+
// 登录控制器
2525
class LoginContorller {
2626
constructor() { }
2727

28+
// 登录操作
2829
public async signIn(): Promise<void> {
2930
const picks: Array<IQuickItemEx<string>> = [];
3031
picks.push(
@@ -56,10 +57,10 @@ class LoginContorller {
5657
const loginMethod: string = choice.value;
5758
const commandArg: string | undefined = loginArgsMapping.get(loginMethod);
5859
if (!commandArg) {
59-
throw new Error(`The login method "${loginMethod}" is not supported.`);
60+
throw new Error(`不支持 "${loginMethod}" 方式登录`);
6061
}
6162
const isByCookie: boolean = loginMethod === "Cookie";
62-
const inMessage: string = isByCookie ? "sign in by cookie" : "sign in";
63+
const inMessage: string = isByCookie ? " 通过cookie登录" : "登录";
6364
try {
6465
const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise<void> => {
6566

@@ -142,29 +143,32 @@ class LoginContorller {
142143
childProc.stdin?.write(`${pwd}\n`);
143144
});
144145
if (userName) {
145-
window.showInformationMessage(`Successfully ${inMessage}.`);
146+
window.showInformationMessage(`${inMessage} 成功`);
146147
eventService.emit("statusChanged", UserStatus.SignedIn, userName);
147148
}
148149
} catch (error) {
149-
promptForOpenOutputChannel(`Failed to ${inMessage}. Please open the output channel for details`, DialogType.error);
150+
promptForOpenOutputChannel(`${inMessage}失败. 请看看控制台输出信息`, DialogType.error);
150151
}
151152

152153
}
153154

155+
// 登出
154156
public async signOut(): Promise<void> {
155157
try {
156158
await executeService.signOut();
157-
window.showInformationMessage("Successfully signed out.");
159+
window.showInformationMessage("成功登出");
158160
eventService.emit("statusChanged", UserStatus.SignedOut, undefined);
159161
} catch (error) {
160162
// promptForOpenOutputChannel(`Failed to signOut. Please open the output channel for details`, DialogType.error);
161163
}
162164
}
163165

166+
// 获取登录状态
164167
public async getLoginStatus() {
165168
return await statusBarService.getLoginStatus();
166169
}
167170

171+
// 删除所有缓存
168172
public async deleteAllCache(): Promise<void> {
169173
await this.signOut();
170174
await executeService.removeOldCache();

src/controller/TreeViewController.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
*/
99

1010

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";
1215
import { toNumber } from "lodash";
1316
import { Disposable, Uri, window, QuickPickItem, workspace, WorkspaceConfiguration } from "vscode";
1417
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";
1922
import { previewService } from "../service/PreviewService";
2023
import { executeService } from "../service/ExecuteService";
2124
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";
2625
import { logOutput, promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/OutputUtils";
2726
import { treeDataService } from "../service/TreeDataService";
2827
import { genFileExt, genFileName } from "../utils/SystemUtils";
@@ -40,7 +39,7 @@ import * as os from "os";
4039
import { getVsCodeConfig, getWorkspaceFolder } from "../utils/ConfigUtils";
4140

4241

43-
42+
// 视图控制器
4443
class TreeViewController implements Disposable {
4544
private explorerNodeMap: Map<string, NodeModel> = new Map<string, NodeModel>();
4645
private companySet: Set<string> = new Set<string>();
@@ -49,8 +48,7 @@ class TreeViewController implements Disposable {
4948
private waitTodayQuestion: boolean;
5049
private waitUserContest: boolean;
5150

52-
53-
51+
// 获取当前文件的路径
5452
public async getActiveFilePath(uri?: vscode.Uri): Promise<string | undefined> {
5553
let textEditor: vscode.TextEditor | undefined;
5654
if (uri) {
@@ -63,12 +61,13 @@ class TreeViewController implements Disposable {
6361
return undefined;
6462
}
6563
if (textEditor.document.isDirty && !await textEditor.document.save()) {
66-
vscode.window.showWarningMessage("Please save the solution file first.");
64+
vscode.window.showWarningMessage("请先保存当前文件");
6765
return undefined;
6866
}
6967
return systemUtils.useWsl() ? systemUtils.toWslPath(textEditor.document.uri.fsPath) : textEditor.document.uri.fsPath;
7068
}
7169

70+
// 提交问题
7271
public async submitSolution(uri?: vscode.Uri): Promise<void> {
7372
if (!statusBarService.getUser()) {
7473
promptForSignIn();
@@ -85,14 +84,15 @@ class TreeViewController implements Disposable {
8584
submissionService.show(result);
8685
eventService.emit("submit", submissionService.getSubmitEvent());
8786
} catch (error) {
88-
await promptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.", DialogType.error);
87+
await promptForOpenOutputChannel("提交出错了. 请查看控制台信息~", DialogType.error);
8988
return;
9089
}
9190

9291
treeDataService.refresh();
9392
}
9493

9594

95+
// 提交测试用例
9696
public async testSolution(uri?: vscode.Uri): Promise<void> {
9797
try {
9898
if (statusBarService.getStatus() === UserStatus.SignedOut) {
@@ -108,25 +108,25 @@ class TreeViewController implements Disposable {
108108
{
109109
label: "$(three-bars) Default test cases",
110110
description: "",
111-
detail: "Test with the default cases",
111+
detail: "默认用例",
112112
value: ":default",
113113
},
114114
{
115115
label: "$(pencil) Write directly...",
116116
description: "",
117-
detail: "Write test cases in input box",
117+
detail: "输入框的测试用例",
118118
value: ":direct",
119119
},
120120
{
121121
label: "$(file-text) Browse...",
122122
description: "",
123-
detail: "Test with the written cases in file",
123+
detail: "文件中的测试用例",
124124
value: ":file",
125125
},
126126
{
127127
label: "All Default test cases...",
128128
description: "",
129-
detail: "Test with the all default cases",
129+
detail: "所有的测试用例",
130130
value: ":alldefault",
131131
},
132132
);
@@ -176,7 +176,7 @@ class TreeViewController implements Disposable {
176176
submissionService.show(result);
177177
eventService.emit("submit", submissionService.getSubmitEvent());
178178
} catch (error) {
179-
await promptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.", DialogType.error);
179+
await promptForOpenOutputChannel("提交测试出错了. 请查看控制台信息~", DialogType.error);
180180
}
181181
}
182182
public async showFileSelectDialog(fsPath?: string): Promise<vscode.Uri[] | undefined> {
@@ -210,7 +210,7 @@ class TreeViewController implements Disposable {
210210
submissionService.show(result);
211211
eventService.emit("submit", submissionService.getSubmitEvent());
212212
} catch (error) {
213-
await promptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.", DialogType.error);
213+
await promptForOpenOutputChannel("提交测试出错了. 请查看控制台信息~", DialogType.error);
214214
}
215215
}
216216

@@ -259,13 +259,13 @@ class TreeViewController implements Disposable {
259259
{
260260
label: `${isCnEnabled ? "" : "$(check) "}LeetCode`,
261261
description: "leetcode.com",
262-
detail: `Enable LeetCode US`,
262+
detail: `Enable LeetCode.com US`,
263263
value: Endpoint.LeetCode,
264264
},
265265
{
266266
label: `${isCnEnabled ? "$(check) " : ""}力扣`,
267267
description: "leetcode.cn",
268-
detail: `启用中国版 LeetCode`,
268+
detail: `启用中国版 LeetCode.cn`,
269269
value: Endpoint.LeetCodeCN,
270270
},
271271
);
@@ -280,15 +280,15 @@ class TreeViewController implements Disposable {
280280
await leetCodeConfig.update("endpoint", endpoint, true /* UserSetting */);
281281
vscode.window.showInformationMessage(`Switched the endpoint to ${endpoint}`);
282282
} catch (error) {
283-
await promptForOpenOutputChannel("Failed to switch endpoint. Please open the output channel for details.", DialogType.error);
283+
await promptForOpenOutputChannel("切换站点出错. 请查看控制台信息~", DialogType.error);
284284
}
285285

286286
try {
287287
await vscode.commands.executeCommand("leetcode.signout");
288288
await executeService.deleteCache();
289289
await promptForSignIn();
290290
} catch (error) {
291-
await promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details.", DialogType.error);
291+
await promptForOpenOutputChannel("登录失败. 请查看控制台信息~", DialogType.error);
292292
}
293293
}
294294

@@ -323,7 +323,7 @@ class TreeViewController implements Disposable {
323323
fileButtonService.refresh();
324324
}
325325
} 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);
327327
}
328328
}
329329

@@ -335,7 +335,7 @@ class TreeViewController implements Disposable {
335335
fileButtonService.refresh();
336336
}
337337
} 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);
339339
}
340340
}
341341

@@ -372,7 +372,7 @@ class TreeViewController implements Disposable {
372372
}
373373
return problems.reverse();
374374
} catch (error) {
375-
await promptForOpenOutputChannel("Failed to list problems. Please open the output channel for details.", DialogType.error);
375+
await promptForOpenOutputChannel("获取题目失败. 请查看控制台信息~", DialogType.error);
376376
return [];
377377
}
378378
}
@@ -419,7 +419,7 @@ class TreeViewController implements Disposable {
419419
});
420420

421421
const selectedItem: QuickPickItem | undefined = await window.showQuickPick(languageItems, {
422-
placeHolder: "Please the default language",
422+
placeHolder: "请设置默认语言",
423423
ignoreFocusOut: true,
424424
});
425425

@@ -428,7 +428,7 @@ class TreeViewController implements Disposable {
428428
}
429429

430430
leetCodeConfig.update("defaultLanguage", selectedItem.label, true /* Global */);
431-
window.showInformationMessage(`Successfully set the default language to ${selectedItem.label}`);
431+
window.showInformationMessage(`设置默认语言 ${selectedItem.label} 成功`);
432432
}
433433

434434

@@ -595,7 +595,7 @@ class TreeViewController implements Disposable {
595595
solutionService.show(unescapeJS(solution));
596596
} catch (error) {
597597
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);
599599
}
600600
}
601601

@@ -619,7 +619,7 @@ class TreeViewController implements Disposable {
619619
console.log(query_result);
620620
} catch (error) {
621621
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);
623623
}
624624
}
625625

@@ -809,7 +809,7 @@ class TreeViewController implements Disposable {
809809

810810
await Promise.all(promises);
811811
} catch (error) {
812-
await promptForOpenOutputChannel(`${error} Please open the output channel for details.`, DialogType.error);
812+
await promptForOpenOutputChannel(`${error} 请查看控制台信息~`, DialogType.error);
813813
}
814814
}
815815

@@ -892,7 +892,7 @@ class TreeViewController implements Disposable {
892892
eventService.emit("searchUserContest", tt);
893893
} catch (error) {
894894
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);
896896
}
897897
}
898898
public async searchToday(): Promise<void> {
@@ -920,7 +920,7 @@ class TreeViewController implements Disposable {
920920

921921
} catch (error) {
922922
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);
924924
}
925925
}
926926

@@ -970,15 +970,15 @@ class TreeViewController implements Disposable {
970970
case "name":
971971
return node.name;
972972
case "camelcasename":
973-
return _.camelCase(node.name);
973+
return lodash.camelCase(node.name);
974974
case "pascalcasename":
975-
return _.upperFirst(_.camelCase(node.name));
975+
return lodash.upperFirst(lodash.camelCase(node.name));
976976
case "kebabcasename":
977977
case "kebab-case-name":
978-
return _.kebabCase(node.name);
978+
return lodash.kebabCase(node.name);
979979
case "snakecasename":
980980
case "snake_case_name":
981-
return _.snakeCase(node.name);
981+
return lodash.snakeCase(node.name);
982982
case "ext":
983983
return genFileExt(selectedLanguage);
984984
case "language":
@@ -1303,7 +1303,7 @@ class TreeViewController implements Disposable {
13031303
for (const company of this.companySet.values()) {
13041304
res.push(new NodeModel(Object.assign({}, defaultProblem, {
13051305
id: `${Category.Company}.${company}`,
1306-
name: _.startCase(company),
1306+
name: lodash.startCase(company),
13071307
}), false));
13081308
}
13091309
this.sortSubCategoryNodes(res, Category.Company);
@@ -1315,7 +1315,7 @@ class TreeViewController implements Disposable {
13151315
for (const tag of this.tagSet.values()) {
13161316
res.push(new NodeModel(Object.assign({}, defaultProblem, {
13171317
id: `${Category.Tag}.${tag}`,
1318-
name: _.startCase(tag),
1318+
name: lodash.startCase(tag),
13191319
}), false));
13201320
}
13211321
this.sortSubCategoryNodes(res, Category.Tag);

src/service/ExecuteService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ExecuteService implements Disposable {
9696
try {
9797
await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "cache", "-d"]);
9898
} catch (error) {
99-
await promptForOpenOutputChannel("Failed to delete cache. Please open the output channel for details.", DialogType.error);
99+
await promptForOpenOutputChannel("Failed to delete cache. 请查看控制台信息~", DialogType.error);
100100
}
101101
}
102102

0 commit comments

Comments
 (0)