Skip to content

支持了数据库,shell,多线程,面试宝典,剑指offer #673

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

Closed
wants to merge 11 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"preLaunchTask": "npm"
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
}
}
]
}
}
6,101 changes: 4,608 additions & 1,493 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "vscode-leetcode",
"displayName": "LeetCode",
"description": "Solve LeetCode problems in VS Code",
"version": "0.18.0",
"author": "Sheng Chen",
"publisher": "LeetCode",
"version": "0.18.1",
"author": "libaoxi",
"publisher": "libaoxi",
"license": "MIT",
"icon": "resources/LeetCode.png",
"engines": {
Expand Down Expand Up @@ -694,12 +694,12 @@
"typescript": "^4.3.2"
},
"dependencies": {
"@baoxi/vsc-leetcode-cli": "^2.8.2",
"fs-extra": "^10.0.0",
"highlight.js": "^10.7.2",
"lodash": "^4.17.21",
"markdown-it": "^8.4.2",
"require-from-string": "^2.0.2",
"unescape-js": "^1.1.4",
"vsc-leetcode-cli": "2.8.0"
"unescape-js": "^1.1.4"
}
}
43 changes: 23 additions & 20 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { IProblem, ProblemState, UserStatus } from "../shared";
import { IProblem, ProblemCategory, ProblemState, UserStatus } from "../shared";
import * as settingUtils from "../utils/settingUtils";
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";

Expand All @@ -16,26 +16,29 @@ export async function listProblems(): Promise<IProblem[]> {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
const showLocked: boolean = !!leetCodeConfig.get<boolean>("showLocked");
const useEndpointTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
const result: string = await leetCodeExecutor.listProblems(showLocked, useEndpointTranslation);
const problems: IProblem[] = [];
const lines: string[] = result.split("\n");
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
for (const line of lines) {
const match: RegExpMatchArray | null = line.match(reg);
if (match && match.length === 8) {
const id: string = match[4].trim();
problems.push({
id,
isFavorite: match[1].trim().length > 0,
locked: match[2].trim().length > 0,
state: parseProblemState(match[3]),
name: match[5].trim(),
difficulty: match[6].trim(),
passRate: match[7].trim(),
companies: companies[id] || ["Unknown"],
tags: tags[id] || ["Unknown"],
});
for (const pc in ProblemCategory) {
const result: string = await leetCodeExecutor.listProblems(showLocked, useEndpointTranslation, ProblemCategory[pc]);
const lines: string[] = result.split("\n");
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[(.*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
for (const line of lines) {
const match: RegExpMatchArray | null = line.match(reg);
if (match && match.length === 8) {
const id: string = match[4].trim();
problems.push({
id,
isFavorite: match[1].trim().length > 0,
locked: match[2].trim().length > 0,
state: parseProblemState(match[3]),
name: match[5].trim(),
difficulty: match[6].trim(),
passRate: match[7].trim(),
companies: companies[id] || ["Unknown"],
tags: tags[id] || ["Unknown"],
category: ProblemCategory[pc],
});
}
}
}
return problems.reverse();
Expand Down
1 change: 0 additions & 1 deletion src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ async function showProblemInternal(node: IProblem): Promise<void> {
}

finalPath = wsl.useWsl() ? await wsl.toWinPath(finalPath) : finalPath;

const descriptionConfig: IDescriptionConfiguration = settingUtils.getDescriptionConfiguration();
const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation();

Expand Down
4 changes: 4 additions & 0 deletions src/explorer/LeetCodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class LeetCodeNode {
return this.data.name;
}

public get category(): string {
return this.data.category;
}

public get state(): ProblemState {
return this.data.state;
}
Expand Down
85 changes: 69 additions & 16 deletions src/explorer/explorerNodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as _ from "lodash";
import { Disposable } from "vscode";
import * as list from "../commands/list";
import { Category, defaultProblem, ProblemState } from "../shared";
import { Category, defaultProblem, ProblemCategory, ProblemState } from "../shared";
import { shouldHideSolvedProblem } from "../utils/settingUtils";
import { LeetCodeNode } from "./LeetCodeNode";

Expand Down Expand Up @@ -56,7 +56,36 @@ class ExplorerNodeManager implements Disposable {
}

public getAllNodes(): LeetCodeNode[] {
return Array.from(this.explorerNodeMap.values());
// return Array.from(this.explorerNodeMap.values());
const res: LeetCodeNode[] = [];
res.push(
new LeetCodeNode(Object.assign({}, defaultProblem, {
id: `${Category.All}.${ProblemCategory.ALGORITHMS}`,
name: "算法",
}), false),
new LeetCodeNode(Object.assign({}, defaultProblem, {
id: `${Category.All}.${ProblemCategory.DATABASE}`,
name: "数据库",
}), false),
new LeetCodeNode(Object.assign({}, defaultProblem, {
id: `${Category.All}.${ProblemCategory.SHELL}`,
name: "Shell",
}), false),
new LeetCodeNode(Object.assign({}, defaultProblem, {
id: `${Category.All}.${ProblemCategory.CONCURRENCY}`,
name: "多线程",
}), false),
new LeetCodeNode(Object.assign({}, defaultProblem, {
id: `${Category.All}.${ProblemCategory.LCCI}`,
name: "程序员面试金典",
}), false),
new LeetCodeNode(Object.assign({}, defaultProblem, {
id: `${Category.All}.${ProblemCategory.LCOF}`,
name: "剑指Offer",
}), false),
);
this.sortSubCategoryNodes(res, Category.All);
return res;
}

public getAllDifficultyNodes(): LeetCodeNode[] {
Expand Down Expand Up @@ -123,6 +152,11 @@ class ExplorerNodeManager implements Disposable {
const res: LeetCodeNode[] = [];
for (const node of this.explorerNodeMap.values()) {
switch (metaInfo[0]) {
case Category.All:
if (node.category === metaInfo[1]) {
res.unshift(node);
}
break;
case Category.Company:
if (node.companies.indexOf(metaInfo[1]) >= 0) {
res.push(node);
Expand Down Expand Up @@ -153,22 +187,41 @@ class ExplorerNodeManager implements Disposable {

private sortSubCategoryNodes(subCategoryNodes: LeetCodeNode[], category: Category): void {
switch (category) {
case Category.All:
function getCategoryValue(input: LeetCodeNode): number {
switch (input.category.toLowerCase()) {
case "algorithms":
return 1;
case "database":
return 2;
case "shell":
return 3;
case "concurrency":
return 4;
case "lcci":
return 5;
case "lcof":
return 6;
default:
return Number.MAX_SAFE_INTEGER;
}
}
subCategoryNodes.sort((a: LeetCodeNode, b: LeetCodeNode): number => getCategoryValue(a) - getCategoryValue(b));
break;
case Category.Difficulty:
subCategoryNodes.sort((a: LeetCodeNode, b: LeetCodeNode): number => {
function getValue(input: LeetCodeNode): number {
switch (input.name.toLowerCase()) {
case "easy":
return 1;
case "medium":
return 2;
case "hard":
return 3;
default:
return Number.MAX_SAFE_INTEGER;
}
function getDifficultyValue(input: LeetCodeNode): number {
switch (input.name.toLowerCase()) {
case "easy":
return 1;
case "medium":
return 2;
case "hard":
return 3;
default:
return Number.MAX_SAFE_INTEGER;
}
return getValue(a) - getValue(b);
});
}
subCategoryNodes.sort((a: LeetCodeNode, b: LeetCodeNode): number => getDifficultyValue(a) - getDifficultyValue(b));
break;
case Category.Tag:
case Category.Company:
Expand Down
6 changes: 3 additions & 3 deletions src/leetCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LeetCodeExecutor implements Disposable {
private configurationChangeListener: Disposable;

constructor() {
this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli");
this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "@baoxi/vsc-leetcode-cli");
this.nodeExecutable = this.getNodePath();
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration("leetcode.nodePath")) {
Expand Down Expand Up @@ -88,8 +88,8 @@ class LeetCodeExecutor implements Disposable {
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "user", "-L"]);
}

public async listProblems(showLocked: boolean, needTranslation: boolean): Promise<string> {
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "list"];
public async listProblems(showLocked: boolean, needTranslation: boolean, category: string): Promise<string> {
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "list", "-c", category];
if (!needTranslation) {
cmd.push("-T"); // use -T to prevent translation
}
Expand Down
11 changes: 11 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface IProblem {
passRate: string;
companies: string[];
tags: string[];
category: string;
}

export const defaultProblem: IProblem = {
Expand All @@ -92,6 +93,7 @@ export const defaultProblem: IProblem = {
passRate: "",
companies: [] as string[],
tags: [] as string[],
category: "",
};

export enum Category {
Expand All @@ -102,6 +104,15 @@ export enum Category {
Favorite = "Favorite",
}

export enum ProblemCategory {
ALGORITHMS = "algorithms",
DATABASE = "database",
SHELL = "shell",
CONCURRENCY = "concurrency",
LCCI = "lcci",
LCOF = "lcof",
}

export const supportedPlugins: string[] = [
"company",
"solution.discuss",
Expand Down
1 change: 1 addition & 0 deletions target/npmlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"0.18.1","name":"vscode-leetcode","dependencies":{"@baoxi/vsc-leetcode-cli":{"version":"2.7.1"},"fs-extra":{"version":"6.0.1"},"highlight.js":{"version":"9.18.5"},"lodash":{"version":"4.17.20"},"markdown-it":{"version":"8.4.2"},"require-from-string":{"version":"2.0.2"},"unescape-js":{"version":"1.1.4"}}}