Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadc9f41

Browse files
authored
support trigger test command in file explorer (LeetCode-OpenSource#30)
1 parent81e9d53 commitadc9f41

File tree

5 files changed

+37
-28
lines changed

5 files changed

+37
-28
lines changed

‎package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
},
8282
{
8383
"command":"leetcode.testSolution",
84-
"title":"Test",
84+
"title":"Test in LeetCode",
8585
"category":"LeetCode"
8686
},
8787
{
@@ -115,7 +115,7 @@
115115
{
116116
"command":"leetcode.showProblem",
117117
"when":"view == leetCodeExplorer && viewItem == problem",
118-
"group":"1@1"
118+
"group":"leetcode-explorer@1"
119119
}
120120
],
121121
"commandPalette": [
@@ -125,9 +125,15 @@
125125
}
126126
],
127127
"explorer/context": [
128+
{
129+
"command":"leetcode.testSolution",
130+
"when":"explorerResourceIsFolder == false",
131+
"group":"file-explorer@1"
132+
},
128133
{
129134
"command":"leetcode.submitSolution",
130-
"when":"explorerResourceIsFolder == false"
135+
"when":"explorerResourceIsFolder == false",
136+
"group":"file-explorer@2"
131137
}
132138
]
133139
},

‎src/commands/submit.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@ import { leetCodeManager } from "../leetCodeManager";
55
import{leetCodeBinaryPath}from"../shared";
66
import{executeCommand}from"../utils/cpUtils";
77
import{DialogType,promptForOpenOutputChannel,promptForSignIn,showResultFile}from"../utils/uiUtils";
8+
import{getActivefilePath}from"../utils/workspaceUtils";
89

910
exportasyncfunctionsubmitSolution(channel:vscode.OutputChannel,uri?:vscode.Uri):Promise<void>{
1011
if(!leetCodeManager.getUser()){
1112
promptForSignIn();
1213
return;
1314
}
1415

15-
letfilePath:string;
16-
if(uri){
17-
filePath=uri.fsPath;
18-
}else{
19-
consttextEditor: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;
16+
constfilePath:string|undefined=awaitgetActivefilePath(uri);
17+
if(!filePath){
18+
return;
2819
}
2920

3021
try{

‎src/commands/test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@ import { leetCodeManager } from "../leetCodeManager";
66
import{IQuickItemEx,leetCodeBinaryPath,UserStatus}from"../shared";
77
import{executeCommand}from"../utils/cpUtils";
88
import{DialogType,promptForOpenOutputChannel,showFileSelectDialog,showResultFile}from"../utils/uiUtils";
9+
import{getActivefilePath}from"../utils/workspaceUtils";
910

10-
exportasyncfunctiontestSolution(channel:vscode.OutputChannel):Promise<void>{
11+
exportasyncfunctiontestSolution(channel:vscode.OutputChannel,uri?:vscode.Uri):Promise<void>{
1112
try{
1213
if(leetCodeManager.getStatus()===UserStatus.SignedOut){
1314
return;
1415
}
1516

16-
constactiveText:vscode.TextEditor|undefined=vscode.window.activeTextEditor;
17-
if(!activeText){
18-
vscode.window.showErrorMessage("Please open a LeetCode solution file first.");
17+
constfilePath:string|undefined=awaitgetActivefilePath(uri);
18+
if(!filePath){
1919
return;
2020
}
21-
if(!activeText.document.save()){
22-
vscode.window.showWarningMessage("Please save the solution file first.");
23-
return;
24-
}
25-
26-
constfilePath=activeText.document.uri.fsPath;
2721
constpicks:Array<IQuickItemEx<string>>=[];
2822
picks.push(
2923
{

‎src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export async function activate(context: vscode.ExtensionContext) {
2727
vscode.commands.registerCommand("leetcode.showProblem",(node:LeetCodeNode)=>show.showProblem(channel,node)),
2828
vscode.commands.registerCommand("leetcode.searchProblem",()=>show.searchProblem(channel)),
2929
vscode.commands.registerCommand("leetcode.refreshExplorer",()=>leetCodeTreeDataProvider.refresh()),
30-
vscode.commands.registerCommand("leetcode.testSolution",()=>test.testSolution(channel)),
31-
vscode.commands.registerCommand("leetcode.submitSolution",(uri:vscode.Uri)=>submit.submitSolution(channel,uri)),
30+
vscode.commands.registerCommand("leetcode.testSolution",(uri?:vscode.Uri)=>test.testSolution(channel,uri)),
31+
vscode.commands.registerCommand("leetcode.submitSolution",(uri?:vscode.Uri)=>submit.submitSolution(channel,uri)),
3232
);
3333

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

‎src/utils/workspaceUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ export async function selectWorkspaceFolder(): Promise<string> {
1717
}
1818
returnfolder ?folder.uri.fsPath :path.join(os.homedir(),".leetcode");
1919
}
20+
21+
exportasyncfunctiongetActivefilePath(uri?:vscode.Uri):Promise<string|undefined>{
22+
lettextEditor:vscode.TextEditor|undefined;
23+
if(uri){
24+
textEditor=awaitvscode.window.showTextDocument(uri,{preview:false});
25+
}else{
26+
textEditor=vscode.window.activeTextEditor;
27+
}
28+
29+
if(!textEditor){
30+
returnundefined;
31+
}
32+
if(textEditor.document.isDirty&&!awaittextEditor.document.save()){
33+
vscode.window.showWarningMessage("Please save the solution file first.");
34+
returnundefined;
35+
}
36+
returntextEditor.document.uri.fsPath;
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp