Skip to content

Commit 37a150a

Browse files
authored
Merge pull request #81 from ccagml/main
2.9.1
2 parents 718b7a3 + 542c123 commit 37a150a

20 files changed

+584
-714
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## version 2.9.1
2+
3+
- 增加中文题解
4+
- 删除多余依赖包引用
5+
16
## version 2.8.1
27

38
- 插入头文件,解决避免都是红色波浪线语法提示

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [新增一个 remark 功能](#新增在工作目录存放数据)
2828
- [新增题目自定义分类](#新增在工作目录存放数据)
2929
- [答案不同上色,配置默认不开启](#插件配置项)
30+
- 增加获取中文站的题解
3031

3132
# 关于本项目
3233

package-lock.json

Lines changed: 141 additions & 164 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
5-
"version": "2.8.1",
5+
"version": "2.9.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -140,7 +140,7 @@
140140
"icon": "$(search)"
141141
},
142142
{
143-
"command": "lcpr.showSolution",
143+
"command": "lcpr.getHelp",
144144
"title": "获取题解",
145145
"category": "LeetCode"
146146
},
@@ -377,7 +377,7 @@
377377
"group": "leetcode@2"
378378
},
379379
{
380-
"command": "lcpr.showSolution",
380+
"command": "lcpr.getHelp",
381381
"when": "view == QuestionExplorer && viewItem =~ /problem*/",
382382
"group": "leetcode@3"
383383
},
@@ -412,7 +412,7 @@
412412
"group": "leetcode@2"
413413
},
414414
{
415-
"command": "lcpr.showSolution",
415+
"command": "lcpr.getHelp",
416416
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
417417
"group": "leetcode@3"
418418
},
@@ -443,7 +443,7 @@
443443
"when": "never"
444444
},
445445
{
446-
"command": "lcpr.showSolution",
446+
"command": "lcpr.getHelp",
447447
"when": "never"
448448
},
449449
{
@@ -486,7 +486,7 @@
486486
"group": "leetcode@2"
487487
},
488488
{
489-
"command": "lcpr.showSolution",
489+
"command": "lcpr.getHelp",
490490
"group": "leetcode@3"
491491
},
492492
{
@@ -1142,7 +1142,6 @@
11421142
"prompt": "^1.2.0",
11431143
"request": "2.88.0",
11441144
"underscore": "1.12.1",
1145-
"unescape-js": "^1.1.4",
11461145
"wordwrap": "1.0.0"
11471146
}
11481147
}

src/controller/TreeViewController.ts

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import * as lodash from "lodash";
1111
import * as path from "path";
12-
import * as unescapeJS from "unescape-js";
1312
import * as vscode from "vscode";
1413
import { toNumber } from "lodash";
1514
import { Disposable, Uri, window } from "vscode";
@@ -475,15 +474,15 @@ class TreeViewController implements Disposable {
475474
* It returns a list of problems
476475
* @returns An array of problems.
477476
*/
478-
public async listProblems(): Promise<IProblem[]> {
477+
public async getAllProblems(): Promise<IProblem[]> {
479478
try {
480479
if (statusBarService.getStatus() === UserStatus.SignedOut) {
481480
return [];
482481
}
483482

484483
const showLockedFlag: boolean = isShowLocked();
485484
const useEndpointTranslation: boolean = isUseEndpointTranslation();
486-
const result: string = await executeService.listProblems(showLockedFlag, useEndpointTranslation);
485+
const result: string = await executeService.getAllProblems(showLockedFlag, useEndpointTranslation);
487486
const all_problem_info = JSON.parse(result);
488487
const problems: IProblem[] = [];
489488
const AllScoreData = treeDataService.getScoreData();
@@ -561,12 +560,12 @@ class TreeViewController implements Disposable {
561560
label: `周赛期数查询`,
562561
detail: `周赛期数查询`,
563562
value: `contest`,
563+
},
564+
{
565+
label: `测试api`,
566+
detail: `测试api`,
567+
value: `testapi`,
564568
}
565-
// {
566-
// label: `测试api`,
567-
// detail: `测试api`,
568-
// value: `testapi`,
569-
// }
570569
// ,
571570
// {
572571
// label: `每日一题`,
@@ -600,7 +599,7 @@ class TreeViewController implements Disposable {
600599
}
601600
}
602601

603-
public async showSolution(input: NodeModel | vscode.Uri): Promise<void> {
602+
public async getHelp(input: NodeModel | vscode.Uri): Promise<void> {
604603
let problemInput: string | undefined;
605604
if (input instanceof NodeModel) {
606605
// Triggerred from explorer
@@ -629,10 +628,36 @@ class TreeViewController implements Disposable {
629628
if (!language) {
630629
return;
631630
}
631+
632+
const picks: Array<IQuickItemEx<string>> = [];
633+
picks.push(
634+
{
635+
label: "获取中文站题解",
636+
description: "",
637+
detail: "",
638+
value: "cn",
639+
},
640+
{
641+
label: "获取英文站题解",
642+
description: "",
643+
detail: "",
644+
value: "en",
645+
}
646+
);
647+
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
648+
if (!choice) {
649+
return;
650+
}
651+
632652
try {
633653
const needTranslation: boolean = isUseEndpointTranslation();
634-
const solution: string = await executeService.showSolution(problemInput, language, needTranslation);
635-
solutionService.show(unescapeJS(solution));
654+
const solution: string = await executeService.getHelp(
655+
problemInput,
656+
language,
657+
needTranslation,
658+
choice.value == "cn"
659+
);
660+
solutionService.show(solution);
636661
} catch (error) {
637662
logOutput.appendLine(error.toString());
638663
await promptForOpenOutputChannel("Failed to fetch the top voted solution. 请查看控制台信息~", OutPutType.error);
@@ -645,16 +670,10 @@ class TreeViewController implements Disposable {
645670
return;
646671
}
647672
try {
648-
const twoFactor: string | undefined = await vscode.window.showInputBox({
649-
prompt: "测试数据",
650-
ignoreFocusOut: true,
651-
validateInput: (s: string): string | undefined => (s && s.trim() ? undefined : "The input must not be empty"),
652-
});
653-
673+
let problemInput = await this.getActiveFilePath();
654674
// vscode.window.showErrorMessage(twoFactor || "输入错误");
655-
const solution: string = await executeService.getTestApi(twoFactor || "");
656-
const query_result = JSON.parse(solution);
657-
console.log(query_result);
675+
const solution: string = await executeService.getTestApi(problemInput || "");
676+
solutionService.show(solution);
658677
} catch (error) {
659678
logOutput.appendLine(error.toString());
660679
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);
@@ -667,7 +686,7 @@ class TreeViewController implements Disposable {
667686
return;
668687
}
669688
const choice: IQuickItemEx<IProblem> | undefined = await vscode.window.showQuickPick(
670-
this.parseProblemsToPicks(this.listProblems()),
689+
this.parseProblemsToPicks(this.getAllProblems()),
671690
{
672691
matchOnDetail: true,
673692
matchOnDescription: true,
@@ -688,7 +707,7 @@ class TreeViewController implements Disposable {
688707
}
689708

690709
public async pickOne(): Promise<void> {
691-
const problems: IProblem[] = await this.listProblems();
710+
const problems: IProblem[] = await this.getAllProblems();
692711
let randomProblem: IProblem;
693712

694713
const user_score = statusBarService.getUserContestScore();
@@ -1053,7 +1072,7 @@ class TreeViewController implements Disposable {
10531072
const temp_waitUserContest: boolean = this.waitUserContest;
10541073
this.dispose();
10551074
let user_score = statusBarService.getUserContestScore();
1056-
for (const problem of await this.listProblems()) {
1075+
for (const problem of await this.getAllProblems()) {
10571076
this.explorerNodeMap.set(problem.id, new NodeModel(problem, true, user_score));
10581077
this.fidToQid.set(problem.id, problem.qid.toString());
10591078
this.qidToFid.set(problem.qid.toString(), problem.id);

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
7171
commands.registerCommand("lcpr.deleteAllCache", () => loginContorller.deleteAllCache()),
7272
commands.registerCommand("leetcode.searchScoreRange", () => treeViewController.searchScoreRange()),
7373
commands.registerCommand("lcpr.searchProblem", () => treeViewController.searchProblem()),
74-
commands.registerCommand("lcpr.showSolution", (input: NodeModel | Uri) => treeViewController.showSolution(input)),
74+
commands.registerCommand("lcpr.getHelp", (input: NodeModel | Uri) => treeViewController.getHelp(input)),
7575
commands.registerCommand("lcpr.refreshExplorer", () => treeDataService.refresh()),
7676
commands.registerCommand("lcpr.testSolution", (uri?: Uri) => treeViewController.testSolution(uri)),
7777
commands.registerCommand("lcpr.testCaseDef", (uri?, allCase?) => treeViewController.testCaseDef(uri, allCase)),

src/model/Model.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ export enum Category {
180180
Choice = "Choice",
181181
}
182182

183-
export const supportedPlugins: string[] = [
184-
// "company",
185-
"solution.discuss",
186-
"leetcode.cn",
187-
];
188-
189183
export enum DescriptionConfiguration {
190184
InWebView = "In Webview",
191185
InFileComment = "In File Comment",

src/rpc/actionChain/chainNode/core.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { configUtils } from "../../utils/configUtils";
1717

1818
import { ChainNodeBase } from "../chainNodeBase";
1919

20-
function hasTag(o, tag) {
21-
return Array.isArray(o) && o.some((x) => x.indexOf(tag.toLowerCase()) >= 0);
22-
}
20+
// function hasTag(o, tag) {
21+
// return Array.isArray(o) && o.some((x) => x.indexOf(tag.toLowerCase()) >= 0);
22+
// }
2323

2424
/* It's a class that extends the ChainNodeBase class, and it has a bunch of methods that are called by
2525
the LeetCode CLI */
@@ -36,17 +36,17 @@ class CorePlugin extends ChainNodeBase {
3636
this.getProblems(!opts.dontTranslate, function (e, problems) {
3737
if (e) return cb(e);
3838

39-
for (let q of (opts.query || "").split("")) {
40-
const f = QUERY_HANDLERS[q];
41-
if (!f) continue;
42-
problems = problems.filter((x) => f(x, q));
43-
}
39+
// for (let q of (opts.query || "").split("")) {
40+
// const f = QUERY_HANDLERS[q];
41+
// if (!f) continue;
42+
// problems = problems.filter((x) => f(x, q));
43+
// }
4444

45-
for (let t of opts.tag || []) {
46-
problems = problems.filter(function (x) {
47-
return x.category === t || hasTag(x.companies, t) || hasTag(x.tags, t);
48-
});
49-
}
45+
// for (let t of opts.tag || []) {
46+
// problems = problems.filter(function (x) {
47+
// return x.category === t || hasTag(x.companies, t) || hasTag(x.tags, t);
48+
// });
49+
// }
5050

5151
return cb(null, problems);
5252
});
@@ -139,27 +139,30 @@ class CorePlugin extends ChainNodeBase {
139139
return cb(null, result);
140140
});
141141
};
142+
getHelp = (problem, cn_flag, lang) => {
143+
this.getHelpOnline(problem, cn_flag, lang);
144+
};
142145
}
143146

144-
const isLevel = (x, q) => x.level[0].toLowerCase() === q.toLowerCase();
145-
const isACed = (x) => x.state === "ac";
146-
const isLocked = (x) => x.locked;
147-
const isStarred = (x) => x.starred;
147+
// const isLevel = (x, q) => x.level[0].toLowerCase() === q.toLowerCase();
148+
// const isACed = (x) => x.state === "ac";
149+
// const isLocked = (x) => x.locked;
150+
// const isStarred = (x) => x.starred;
148151

149152
/* It's a dictionary that maps the query to the function that filters the problems. */
150-
const QUERY_HANDLERS = {
151-
e: isLevel,
152-
E: _.negate(isLevel),
153-
m: isLevel,
154-
M: _.negate(isLevel),
155-
h: isLevel,
156-
H: _.negate(isLevel),
157-
l: isLocked,
158-
L: _.negate(isLocked),
159-
d: isACed,
160-
D: _.negate(isACed),
161-
s: isStarred,
162-
S: _.negate(isStarred),
163-
};
153+
// const QUERY_HANDLERS = {
154+
// e: isLevel,
155+
// E: _.negate(isLevel),
156+
// m: isLevel,
157+
// M: _.negate(isLevel),
158+
// h: isLevel,
159+
// H: _.negate(isLevel),
160+
// l: isLocked,
161+
// L: _.negate(isLocked),
162+
// d: isACed,
163+
// D: _.negate(isACed),
164+
// s: isStarred,
165+
// S: _.negate(isStarred),
166+
// };
164167

165168
export const corePlugin: CorePlugin = new CorePlugin();

0 commit comments

Comments
 (0)