Movatterモバイル変換


[0]ホーム

URL:


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

feature: Add support for selecting problem of today.#729

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jtchen2k wants to merge2 commits intoLeetCode-OpenSource:master
base:master
Choose a base branch
Loading
fromjtchen2k:feature/problem_of_today
Open
Show file tree
Hide file tree
Changes fromall 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
12 changes: 12 additions & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@
"onCommand:leetcode.manageSessions",
"onCommand:leetcode.refreshExplorer",
"onCommand:leetcode.pickOne",
"onCommand:leetcode.problemOfToday",
"onCommand:leetcode.showProblem",
"onCommand:leetcode.previewProblem",
"onCommand:leetcode.searchProblem",
Expand DownExpand Up@@ -81,6 +82,12 @@
"title": "Pick One",
"category": "LeetCode"
},
{
"command": "leetcode.problemOfToday",
"title": "Problem Of Today",
"category": "LeetCode",
"icon": "$(calendar)"
},
{
"command": "leetcode.showProblem",
"title": "Show Problem",
Expand DownExpand Up@@ -175,6 +182,11 @@
"when": "view == leetCodeExplorer",
"group": "navigation@3"
},
{
"command": "leetcode.problemOfToday",
"when": "view == leetCodeExplorer",
"group": "navigation@4"
},
{
"command": "leetcode.pickOne",
"when": "view == leetCodeExplorer",
Expand Down
27 changes: 27 additions & 0 deletionssrc/commands/show.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,6 +52,33 @@ export async function pickOne(): Promise<void> {
await showProblemInternal(randomProblem);
}

export async function problemOfToday(): Promise<void> {
if (!leetCodeManager.getUser()) {
promptForSignIn();
return;
}
try {
const nodes: LeetCodeNode[] = explorerNodeManager.getAllNodes()
const problemOfTodayStr: string = await leetCodeExecutor.problemOfToday();
const lines: string[] = problemOfTodayStr.split("\n");
const reg: RegExp = /^\[(.+)\]\s.*/
const match: RegExpMatchArray | null = lines[0].match(reg);
if (match != null) {
const id = match[1]
const problemOfToday: IProblem[] = nodes.filter(one => one.id === id);
if (problemOfToday.length != 1) {
await promptForOpenOutputChannel("Fail to load problem of today. You may need to refresh the problem list.", DialogType.error);
}
else {
await showProblemInternal(problemOfToday[0]);
}
}
}
catch {
await promptForOpenOutputChannel("Fail to load problem of today. Open the output channel for details.", DialogType.error);
}
}

export async function showProblem(node?: LeetCodeNode): Promise<void> {
if (!node) {
return;
Expand Down
1 change: 1 addition & 0 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)),
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
vscode.commands.registerCommand("leetcode.pickOne", () => show.pickOne()),
vscode.commands.registerCommand("leetcode.problemOfToday", () => show.problemOfToday()),
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
vscode.commands.registerCommand("leetcode.showSolution", (input: LeetCodeNode | vscode.Uri) => show.showSolution(input)),
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
Expand Down
5 changes: 5 additions & 0 deletionssrc/leetCodeExecutor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,6 +100,11 @@ class LeetCodeExecutor implements Disposable {
return await this.executeCommandEx(this.nodeExecutable, cmd);
}

public async problemOfToday(): Promise<string> {
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", "-d"];
return await this.executeCommandWithProgressEx("Loading problem of today...", this.nodeExecutable, cmd);
}

public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false, needTranslation: boolean): Promise<void> {
const templateType: string = showDescriptionInComment ? "-cx" : "-c";
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", problemNode.id, templateType, "-l", language];
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp