diff --git a/package.json b/package.json index de75ce11..937853c1 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ }, { "command": "leetcode.submitSolution", - "title": "Submit", + "title": "Submit to LeetCode", "category": "LeetCode" } ], @@ -123,6 +123,12 @@ "command": "leetcode.showProblem", "when": "never" } + ], + "explorer/context": [ + { + "command": "leetcode.submitSolution", + "when": "explorerResourceIsFolder == false" + } ] }, "configuration": [ diff --git a/src/commands/submit.ts b/src/commands/submit.ts index cd12fd9e..d45382df 100644 --- a/src/commands/submit.ts +++ b/src/commands/submit.ts @@ -6,20 +6,27 @@ import { leetCodeBinaryPath } from "../shared"; import { executeCommand } from "../utils/cpUtils"; import { DialogType, promptForOpenOutputChannel, promptForSignIn, showResultFile } from "../utils/uiUtils"; -export async function submitSolution(channel: vscode.OutputChannel): Promise { +export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode.Uri): Promise { if (!leetCodeManager.getUser()) { promptForSignIn(); return; } - const textEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; - if (!textEditor) { - return; - } - if (!textEditor.document.save()) { - vscode.window.showWarningMessage("Please save the solution file first."); - return; + + let filePath: string; + if (uri) { + filePath = uri.fsPath; + } else { + const textEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; + if (!textEditor) { + return; + } + if (!textEditor.document.save()) { + vscode.window.showWarningMessage("Please save the solution file first."); + return; + } + filePath = textEditor.document.uri.fsPath; } - const filePath: string = textEditor.document.uri.fsPath; + try { const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", filePath]); await showResultFile(result); diff --git a/src/extension.ts b/src/extension.ts index 6a4f6b52..3157b8b4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -28,7 +28,7 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem(channel)), vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()), vscode.commands.registerCommand("leetcode.testSolution", () => test.testSolution(channel)), - vscode.commands.registerCommand("leetcode.submitSolution", () => submit.submitSolution(channel)), + vscode.commands.registerCommand("leetcode.submitSolution", (uri: vscode.Uri) => submit.submitSolution(channel, uri)), ); leetCodeManager.on("statusChanged", () => { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy