diff --git a/package.json b/package.json index 722a0916..fb8ff548 100644 --- a/package.json +++ b/package.json @@ -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", @@ -84,6 +85,11 @@ "dark": "resources/dark/refresh.svg" } }, + { + "command": "leetcode.pickOne", + "title": "Pick One", + "category": "LeetCode" + }, { "command": "leetcode.showProblem", "title": "Show Problem", @@ -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": [ diff --git a/src/commands/show.ts b/src/commands/show.ts index 1846fe9f..b946c298 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -44,6 +44,12 @@ export async function previewProblem(input: IProblem | vscode.Uri, isSideMode: b leetCodePreviewProvider.show(descString, node, isSideMode); } +export async function pickOne(): Promise { + 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 { if (!node) { return; diff --git a/src/extension.ts b/src/extension.ts index 4d33d803..d1997945 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -54,6 +54,7 @@ export async function activate(context: vscode.ExtensionContext): Promise 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()), @@ -63,7 +64,7 @@ export async function activate(context: vscode.ExtensionContext): Promise ); 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);