Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

支持了数据库,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
libaoxi wants to merge 11 commits into LeetCode-OpenSource:master from libaoxi:master
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
master
  • Loading branch information
libaoxi committed Feb 3, 2021
commit 32c79bda60915d72e3141efeed8d0b8cf2bc19e3
457 changes: 168 additions & 289 deletions package-lock.json
View file Open in desktop

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode",
"displayName": "LeetCode",
"description": "Solve LeetCode problems in VS Code",
"version": "0.17.0",
"version": "0.18.0",
"author": "Sheng Chen",
"publisher": "LeetCode",
"license": "MIT",
Expand Down Expand Up @@ -671,11 +671,11 @@
"@types/lodash": "^4.14.123",
"@types/markdown-it": "0.0.7",
"@types/mocha": "^2.2.42",
"@types/node": "^7.0.43",
"@types/node": "14.14.22",
"@types/vscode": "1.42.0",
"@types/require-from-string": "^1.2.0",
"tslint": "^5.9.1",
"typescript": "^2.6.1"
"typescript": "4.1.3"
},
"dependencies": {
"fs-extra": "^6.0.1",
Expand Down
43 changes: 23 additions & 20 deletions src/commands/list.ts
View file Open in desktop
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 { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";

export async function listProblems(): Promise<IProblem[]> {
Expand All @@ -14,26 +14,29 @@ export async function listProblems(): Promise<IProblem[]> {
}
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
const showLocked: boolean = !!leetCodeConfig.get<boolean>("showLocked");
const result: string = await leetCodeExecutor.listProblems(showLocked);
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 (let pc in ProblemCategory) {
const result: string = await leetCodeExecutor.listProblems(showLocked, 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: pc,
});
}
}
}
return problems.reverse();
Expand Down
4 changes: 4 additions & 0 deletions src/explorer/LeetCodeNode.ts
View file Open in desktop
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
76 changes: 62 additions & 14 deletions src/explorer/explorerNodeManager.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ class ExplorerNodeManager implements Disposable {

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

public getAllDifficultyNodes(): LeetCodeNode[] {
Expand Down Expand Up @@ -153,22 +182,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 4;
case "lcof":
return 4;
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
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class LeetCodeExecutor implements Disposable {
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "user", "-L"]);
}

public async listProblems(showLocked: boolean): Promise<string> {
public async listProblems(showLocked: boolean, category: string): Promise<string> {
return await this.executeCommandEx(this.nodeExecutable, showLocked ?
[await this.getLeetCodeBinaryPath(), "list"] :
[await this.getLeetCodeBinaryPath(), "list", "-q", "L"],
[await this.getLeetCodeBinaryPath(), "list", "-t", category] :
[await this.getLeetCodeBinaryPath(), "list", "-t", category, "-q", "L"],
);
}

Expand Down
14 changes: 7 additions & 7 deletions src/leetCodeManager.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LeetCodeManager extends EventEmitter {
env: createEnvOption(),
});

childProc.stdout.on("data", async (data: string | Buffer) => {
childProc.stdout?.on("data", async (data: string | Buffer) => {
data = data.toString();
leetCodeChannel.append(data);
if (data.includes("twoFactorCode")) {
Expand All @@ -96,19 +96,19 @@ class LeetCodeManager extends EventEmitter {
childProc.kill();
return resolve(undefined);
}
childProc.stdin.write(`${twoFactor}\n`);
childProc.stdin?.write(`${twoFactor}\n`);
}
const successMatch: RegExpMatchArray | null = data.match(this.successRegex);
if (successMatch && successMatch[1]) {
childProc.stdin.end();
childProc.stdin?.end();
return resolve(successMatch[1]);
} else if (data.match(this.failRegex)) {
childProc.stdin.end();
childProc.stdin?.end();
return reject(new Error("Faile to login"));
}
});

childProc.stderr.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));
childProc.stderr?.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));

childProc.on("error", reject);
const name: string | undefined = await vscode.window.showInputBox({
Expand All @@ -120,7 +120,7 @@ class LeetCodeManager extends EventEmitter {
childProc.kill();
return resolve(undefined);
}
childProc.stdin.write(`${name}\n`);
childProc.stdin?.write(`${name}\n`);
const pwd: string | undefined = await vscode.window.showInputBox({
prompt: isByCookie ? "Enter cookie" : "Enter password.",
password: true,
Expand All @@ -131,7 +131,7 @@ class LeetCodeManager extends EventEmitter {
childProc.kill();
return resolve(undefined);
}
childProc.stdin.write(`${pwd}\n`);
childProc.stdin?.write(`${pwd}\n`);
});
if (userName) {
vscode.window.showInformationMessage(`Successfully ${inMessage}.`);
Expand Down
11 changes: 11 additions & 0 deletions src/shared.ts
View file Open in desktop
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
8 changes: 4 additions & 4 deletions src/utils/cpUtils.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export async function executeCommand(command: string, args: string[], options: c

const childProc: cp.ChildProcess = cp.spawn(command, args, { ...options, env: createEnvOption() });

childProc.stdout.on("data", (data: string | Buffer) => {
childProc.stdout?.on("data", (data: string | Buffer) => {
data = data.toString();
result = result.concat(data);
leetCodeChannel.append(data);
});

childProc.stderr.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));
childProc.stderr?.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));

childProc.on("error", reject);

Expand All @@ -42,11 +42,11 @@ export async function executeCommand(command: string, args: string[], options: c
export async function executeCommandWithProgress(message: string, command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
let result: string = "";
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (p: vscode.Progress<{}>) => {
return new Promise(async (resolve: () => void, reject: (e: Error) => void): Promise<void> => {
return new Promise(async (resolve, reject): Promise<void> => {
p.report({ message });
try {
result = await executeCommand(command, args, options);
resolve();
resolve(undefined);
} catch (e) {
reject(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/webview/leetCodePreviewProvider.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview {

protected onDidDisposeWebview(): void {
super.onDidDisposeWebview();
delete this.node;
delete this.description;
// delete this.node;
// delete this.description;
this.sideMode = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/webview/leetCodeSolutionProvider.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LeetCodeSolutionProvider extends LeetCodeWebview {

protected onDidDisposeWebview(): void {
super.onDidDisposeWebview();
delete this.solution;
// delete this.solution;
}

private parseSolution(raw: string): Solution {
Expand Down
2 changes: 1 addition & 1 deletion src/webview/leetCodeSubmissionProvider.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {

protected onDidDisposeWebview(): void {
super.onDidDisposeWebview();
delete this.result;
// delete this.result;
}

private async showKeybindingsHint(): Promise<void> {
Expand Down

AltStyle によって変換されたページ (->オリジナル) /