Skip to content

Commit

Permalink
feat: Support pick one (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Sep 1, 2019
1 parent 24f636d commit 6ae2284
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"onCommand:leetcode.signout",
"onCommand:leetcode.manageSessions",
"onCommand:leetcode.refreshExplorer",
"onCommand:leetcode.pickOne",
"onCommand:leetcode.showProblem",
"onCommand:leetcode.previewProblem",
"onCommand:leetcode.searchProblem",
Expand Down Expand Up @@ -84,6 +85,11 @@
"dark": "resources/dark/refresh.svg"
}
},
{
"command": "leetcode.pickOne",
"title": "Pick One",
"category": "LeetCode"
},
{
"command": "leetcode.showProblem",
"title": "Show Problem",
Expand Down Expand Up @@ -162,6 +168,11 @@
"command": "leetcode.refreshExplorer",
"when": "view == leetCodeExplorer",
"group": "navigation@3"
},
{
"command": "leetcode.pickOne",
"when": "view == leetCodeExplorer",
"group": "overflow@0"
}
],
"view/item/context": [
Expand Down
6 changes: 6 additions & 0 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export async function previewProblem(input: IProblem | vscode.Uri, isSideMode: b
leetCodePreviewProvider.show(descString, node, isSideMode);
}

export async function pickOne(): Promise<void> {
const problems: IProblem[] = await list.listProblems();
const randomProblem: IProblem = problems[Math.floor(Math.random() * problems.length)];
await showProblemInternal(randomProblem);
}

export async function showProblem(node?: LeetCodeNode): Promise<void> {
if (!node) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.manageSessions", () => session.manageSessions()),
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.searchProblem", () => show.searchProblem()),
vscode.commands.registerCommand("leetcode.showSolution", (input: LeetCodeNode | vscode.Uri) => show.showSolution(input)),
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
Expand All @@ -63,7 +64,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
);

await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint());
leetCodeManager.getLoginStatus();
await leetCodeManager.getLoginStatus();
} catch (error) {
leetCodeChannel.appendLine(error.toString());
promptForOpenOutputChannel("Extension initialization failed. Please open output channel for details.", DialogType.error);
Expand Down

0 comments on commit 6ae2284

Please sign in to comment.