Skip to content

Commit 81e9d53

Browse files
authored
support submit from the file explorer (#29)
1 parent 0bf5b96 commit 81e9d53

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
},
8787
{
8888
"command": "leetcode.submitSolution",
89-
"title": "Submit",
89+
"title": "Submit to LeetCode",
9090
"category": "LeetCode"
9191
}
9292
],
@@ -123,6 +123,12 @@
123123
"command": "leetcode.showProblem",
124124
"when": "never"
125125
}
126+
],
127+
"explorer/context": [
128+
{
129+
"command": "leetcode.submitSolution",
130+
"when": "explorerResourceIsFolder == false"
131+
}
126132
]
127133
},
128134
"configuration": [

src/commands/submit.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@ import { leetCodeBinaryPath } from "../shared";
66
import { executeCommand } from "../utils/cpUtils";
77
import { DialogType, promptForOpenOutputChannel, promptForSignIn, showResultFile } from "../utils/uiUtils";
88

9-
export async function submitSolution(channel: vscode.OutputChannel): Promise<void> {
9+
export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode.Uri): Promise<void> {
1010
if (!leetCodeManager.getUser()) {
1111
promptForSignIn();
1212
return;
1313
}
14-
const textEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
15-
if (!textEditor) {
16-
return;
17-
}
18-
if (!textEditor.document.save()) {
19-
vscode.window.showWarningMessage("Please save the solution file first.");
20-
return;
14+
15+
let filePath: string;
16+
if (uri) {
17+
filePath = uri.fsPath;
18+
} else {
19+
const textEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
20+
if (!textEditor) {
21+
return;
22+
}
23+
if (!textEditor.document.save()) {
24+
vscode.window.showWarningMessage("Please save the solution file first.");
25+
return;
26+
}
27+
filePath = textEditor.document.uri.fsPath;
2128
}
22-
const filePath: string = textEditor.document.uri.fsPath;
29+
2330
try {
2431
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", filePath]);
2532
await showResultFile(result);

src/extension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function activate(context: vscode.ExtensionContext) {
2828
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem(channel)),
2929
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
3030
vscode.commands.registerCommand("leetcode.testSolution", () => test.testSolution(channel)),
31-
vscode.commands.registerCommand("leetcode.submitSolution", () => submit.submitSolution(channel)),
31+
vscode.commands.registerCommand("leetcode.submitSolution", (uri: vscode.Uri) => submit.submitSolution(channel, uri)),
3232
);
3333

3434
leetCodeManager.on("statusChanged", () => {

0 commit comments

Comments
 (0)