Skip to content

2.9.1 #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## version 2.9.1

- 增加中文题解
- 删除多余依赖包引用

## version 2.8.1

- 插入头文件,解决避免都是红色波浪线语法提示
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [新增一个 remark 功能](#新增在工作目录存放数据)
- [新增题目自定义分类](#新增在工作目录存放数据)
- [答案不同上色,配置默认不开启](#插件配置项)
- 增加获取中文站的题解

# 关于本项目

Expand Down
305 changes: 141 additions & 164 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
"version": "2.8.1",
"version": "2.9.1",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -140,7 +140,7 @@
"icon": "$(search)"
},
{
"command": "lcpr.showSolution",
"command": "lcpr.getHelp",
"title": "获取题解",
"category": "LeetCode"
},
Expand Down Expand Up @@ -377,7 +377,7 @@
"group": "leetcode@2"
},
{
"command": "lcpr.showSolution",
"command": "lcpr.getHelp",
"when": "view == QuestionExplorer && viewItem =~ /problem*/",
"group": "leetcode@3"
},
Expand Down Expand Up @@ -412,7 +412,7 @@
"group": "leetcode@2"
},
{
"command": "lcpr.showSolution",
"command": "lcpr.getHelp",
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
"group": "leetcode@3"
},
Expand Down Expand Up @@ -443,7 +443,7 @@
"when": "never"
},
{
"command": "lcpr.showSolution",
"command": "lcpr.getHelp",
"when": "never"
},
{
Expand Down Expand Up @@ -486,7 +486,7 @@
"group": "leetcode@2"
},
{
"command": "lcpr.showSolution",
"command": "lcpr.getHelp",
"group": "leetcode@3"
},
{
Expand Down Expand Up @@ -1142,7 +1142,6 @@
"prompt": "^1.2.0",
"request": "2.88.0",
"underscore": "1.12.1",
"unescape-js": "^1.1.4",
"wordwrap": "1.0.0"
}
}
65 changes: 42 additions & 23 deletions src/controller/TreeViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import * as lodash from "lodash";
import * as path from "path";
import * as unescapeJS from "unescape-js";
import * as vscode from "vscode";
import { toNumber } from "lodash";
import { Disposable, Uri, window } from "vscode";
Expand Down Expand Up @@ -475,15 +474,15 @@ class TreeViewController implements Disposable {
* It returns a list of problems
* @returns An array of problems.
*/
public async listProblems(): Promise<IProblem[]> {
public async getAllProblems(): Promise<IProblem[]> {
try {
if (statusBarService.getStatus() === UserStatus.SignedOut) {
return [];
}

const showLockedFlag: boolean = isShowLocked();
const useEndpointTranslation: boolean = isUseEndpointTranslation();
const result: string = await executeService.listProblems(showLockedFlag, useEndpointTranslation);
const result: string = await executeService.getAllProblems(showLockedFlag, useEndpointTranslation);
const all_problem_info = JSON.parse(result);
const problems: IProblem[] = [];
const AllScoreData = treeDataService.getScoreData();
Expand Down Expand Up @@ -561,12 +560,12 @@ class TreeViewController implements Disposable {
label: `周赛期数查询`,
detail: `周赛期数查询`,
value: `contest`,
},
{
label: `测试api`,
detail: `测试api`,
value: `testapi`,
}
// {
// label: `测试api`,
// detail: `测试api`,
// value: `testapi`,
// }
// ,
// {
// label: `每日一题`,
Expand Down Expand Up @@ -600,7 +599,7 @@ class TreeViewController implements Disposable {
}
}

public async showSolution(input: NodeModel | vscode.Uri): Promise<void> {
public async getHelp(input: NodeModel | vscode.Uri): Promise<void> {
let problemInput: string | undefined;
if (input instanceof NodeModel) {
// Triggerred from explorer
Expand Down Expand Up @@ -629,10 +628,36 @@ class TreeViewController implements Disposable {
if (!language) {
return;
}

const picks: Array<IQuickItemEx<string>> = [];
picks.push(
{
label: "获取中文站题解",
description: "",
detail: "",
value: "cn",
},
{
label: "获取英文站题解",
description: "",
detail: "",
value: "en",
}
);
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
if (!choice) {
return;
}

try {
const needTranslation: boolean = isUseEndpointTranslation();
const solution: string = await executeService.showSolution(problemInput, language, needTranslation);
solutionService.show(unescapeJS(solution));
const solution: string = await executeService.getHelp(
problemInput,
language,
needTranslation,
choice.value == "cn"
);
solutionService.show(solution);
} catch (error) {
logOutput.appendLine(error.toString());
await promptForOpenOutputChannel("Failed to fetch the top voted solution. 请查看控制台信息~", OutPutType.error);
Expand All @@ -645,16 +670,10 @@ class TreeViewController implements Disposable {
return;
}
try {
const twoFactor: string | undefined = await vscode.window.showInputBox({
prompt: "测试数据",
ignoreFocusOut: true,
validateInput: (s: string): string | undefined => (s && s.trim() ? undefined : "The input must not be empty"),
});

let problemInput = await this.getActiveFilePath();
// vscode.window.showErrorMessage(twoFactor || "输入错误");
const solution: string = await executeService.getTestApi(twoFactor || "");
const query_result = JSON.parse(solution);
console.log(query_result);
const solution: string = await executeService.getTestApi(problemInput || "");
solutionService.show(solution);
} catch (error) {
logOutput.appendLine(error.toString());
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);
Expand All @@ -667,7 +686,7 @@ class TreeViewController implements Disposable {
return;
}
const choice: IQuickItemEx<IProblem> | undefined = await vscode.window.showQuickPick(
this.parseProblemsToPicks(this.listProblems()),
this.parseProblemsToPicks(this.getAllProblems()),
{
matchOnDetail: true,
matchOnDescription: true,
Expand All @@ -688,7 +707,7 @@ class TreeViewController implements Disposable {
}

public async pickOne(): Promise<void> {
const problems: IProblem[] = await this.listProblems();
const problems: IProblem[] = await this.getAllProblems();
let randomProblem: IProblem;

const user_score = statusBarService.getUserContestScore();
Expand Down Expand Up @@ -1053,7 +1072,7 @@ class TreeViewController implements Disposable {
const temp_waitUserContest: boolean = this.waitUserContest;
this.dispose();
let user_score = statusBarService.getUserContestScore();
for (const problem of await this.listProblems()) {
for (const problem of await this.getAllProblems()) {
this.explorerNodeMap.set(problem.id, new NodeModel(problem, true, user_score));
this.fidToQid.set(problem.id, problem.qid.toString());
this.qidToFid.set(problem.qid.toString(), problem.id);
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
commands.registerCommand("lcpr.deleteAllCache", () => loginContorller.deleteAllCache()),
commands.registerCommand("leetcode.searchScoreRange", () => treeViewController.searchScoreRange()),
commands.registerCommand("lcpr.searchProblem", () => treeViewController.searchProblem()),
commands.registerCommand("lcpr.showSolution", (input: NodeModel | Uri) => treeViewController.showSolution(input)),
commands.registerCommand("lcpr.getHelp", (input: NodeModel | Uri) => treeViewController.getHelp(input)),
commands.registerCommand("lcpr.refreshExplorer", () => treeDataService.refresh()),
commands.registerCommand("lcpr.testSolution", (uri?: Uri) => treeViewController.testSolution(uri)),
commands.registerCommand("lcpr.testCaseDef", (uri?, allCase?) => treeViewController.testCaseDef(uri, allCase)),
Expand Down
6 changes: 0 additions & 6 deletions src/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ export enum Category {
Choice = "Choice",
}

export const supportedPlugins: string[] = [
// "company",
"solution.discuss",
"leetcode.cn",
];

export enum DescriptionConfiguration {
InWebView = "In Webview",
InFileComment = "In File Comment",
Expand Down
65 changes: 34 additions & 31 deletions src/rpc/actionChain/chainNode/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { configUtils } from "../../utils/configUtils";

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

function hasTag(o, tag) {
return Array.isArray(o) && o.some((x) => x.indexOf(tag.toLowerCase()) >= 0);
}
// function hasTag(o, tag) {
// return Array.isArray(o) && o.some((x) => x.indexOf(tag.toLowerCase()) >= 0);
// }

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

for (let q of (opts.query || "").split("")) {
const f = QUERY_HANDLERS[q];
if (!f) continue;
problems = problems.filter((x) => f(x, q));
}
// for (let q of (opts.query || "").split("")) {
// const f = QUERY_HANDLERS[q];
// if (!f) continue;
// problems = problems.filter((x) => f(x, q));
// }

for (let t of opts.tag || []) {
problems = problems.filter(function (x) {
return x.category === t || hasTag(x.companies, t) || hasTag(x.tags, t);
});
}
// for (let t of opts.tag || []) {
// problems = problems.filter(function (x) {
// return x.category === t || hasTag(x.companies, t) || hasTag(x.tags, t);
// });
// }

return cb(null, problems);
});
Expand Down Expand Up @@ -139,27 +139,30 @@ class CorePlugin extends ChainNodeBase {
return cb(null, result);
});
};
getHelp = (problem, cn_flag, lang) => {
this.getHelpOnline(problem, cn_flag, lang);
};
}

const isLevel = (x, q) => x.level[0].toLowerCase() === q.toLowerCase();
const isACed = (x) => x.state === "ac";
const isLocked = (x) => x.locked;
const isStarred = (x) => x.starred;
// const isLevel = (x, q) => x.level[0].toLowerCase() === q.toLowerCase();
// const isACed = (x) => x.state === "ac";
// const isLocked = (x) => x.locked;
// const isStarred = (x) => x.starred;

/* It's a dictionary that maps the query to the function that filters the problems. */
const QUERY_HANDLERS = {
e: isLevel,
E: _.negate(isLevel),
m: isLevel,
M: _.negate(isLevel),
h: isLevel,
H: _.negate(isLevel),
l: isLocked,
L: _.negate(isLocked),
d: isACed,
D: _.negate(isACed),
s: isStarred,
S: _.negate(isStarred),
};
// const QUERY_HANDLERS = {
// e: isLevel,
// E: _.negate(isLevel),
// m: isLevel,
// M: _.negate(isLevel),
// h: isLevel,
// H: _.negate(isLevel),
// l: isLocked,
// L: _.negate(isLocked),
// d: isACed,
// D: _.negate(isACed),
// s: isStarred,
// S: _.negate(isStarred),
// };

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