Skip to content
Open
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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff 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 Down Expand 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 Down Expand 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 deletions src/commands/show.ts
Original file line number Diff line number Diff 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 deletions src/extension.ts
Original file line number Diff line number Diff 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 deletions src/leetCodeExecutor.ts
Original file line number Diff line number Diff 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