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

Commit1004e1d

Browse files
authored
feat: Support delete a session (LeetCode-OpenSource#358)
1 parent19af64f commit1004e1d

File tree

8 files changed

+91
-37
lines changed

8 files changed

+91
-37
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<imgsrc="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/session.png"alt="Manage Session" />
111111
</p>
112112

113-
- To manage your LeetCode sessions, just clicking the`LeetCode: ***` at the bottom of the status bar. You can**switch** between sessions or**create** a new session.
113+
- To manage your LeetCode sessions, just clicking the`LeetCode: ***` at the bottom of the status bar. You can**switch** between sessions or**create**,**delete** a session.
114114

115115

116116
##Settings

‎docs/README_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<imgsrc="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/session.png"alt="管理存档" />
111111
</p>
112112

113-
- 点击位于 VS Code 底部状态栏的`LeetCode: ***` 管理`LeetCode 存档`。你可以**切换**存档或者**创建**新的存档
113+
- 点击位于 VS Code 底部状态栏的`LeetCode: ***` 管理`LeetCode 存档`。你可以**切换**存档或者**创建****删除**存档
114114

115115

116116
##插件配置项

‎package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"onCommand:leetcode.toggleLeetCodeCn",
3030
"onCommand:leetcode.signin",
3131
"onCommand:leetcode.signout",
32-
"onCommand:leetcode.selectSessions",
33-
"onCommand:leetcode.createSession",
32+
"onCommand:leetcode.manageSessions",
3433
"onCommand:leetcode.refreshExplorer",
3534
"onCommand:leetcode.showProblem",
3635
"onCommand:leetcode.previewProblem",
@@ -72,13 +71,8 @@
7271
"category":"LeetCode"
7372
},
7473
{
75-
"command":"leetcode.selectSessions",
76-
"title":"Select Session",
77-
"category":"LeetCode"
78-
},
79-
{
80-
"command":"leetcode.createSession",
81-
"title":"Create New Session",
74+
"command":"leetcode.manageSessions",
75+
"title":"Manage Sessions",
8276
"category":"LeetCode"
8377
},
8478
{
@@ -394,6 +388,6 @@
394388
"markdown-it":"^8.4.2",
395389
"require-from-string":"^2.0.2",
396390
"unescape-js":"^1.1.1",
397-
"vsc-leetcode-cli":"2.6.7"
391+
"vsc-leetcode-cli":"2.6.8"
398392
}
399393
}

‎src/commands/session.ts

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as vscode from "vscode";
55
import{leetCodeExecutor}from"../leetCodeExecutor";
66
import{leetCodeManager}from"../leetCodeManager";
77
import{IQuickItemEx}from"../shared";
8-
import{DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
8+
import{DialogOptions,DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
99

1010
exportasyncfunctiongetSessionList():Promise<ISession[]>{
1111
constsignInStatus:string|undefined=leetCodeManager.getUser();
@@ -32,48 +32,64 @@ export async function getSessionList(): Promise<ISession[]> {
3232
returnsessions;
3333
}
3434

35-
exportasyncfunctionselectSession():Promise<void>{
36-
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(parseSessionsToPicks());
35+
exportasyncfunctionmanageSessions():Promise<void>{
36+
constchoice:IQuickItemEx<ISession|string>|undefined=awaitvscode.window.showQuickPick(parseSessionsToPicks(true/* includeOperation */));
3737
if(!choice||choice.description==="Active"){
3838
return;
3939
}
40-
if(choice.value===":createNewSession"){
41-
awaitvscode.commands.executeCommand("leetcode.createSession");
40+
if(choice.value===":createSession"){
41+
awaitcreateSession();
42+
return;
43+
}
44+
if(choice.value===":deleteSession"){
45+
awaitdeleteSession();
4246
return;
4347
}
4448
try{
45-
awaitleetCodeExecutor.enableSession(choice.value);
49+
awaitleetCodeExecutor.enableSession((choice.valueasISession).id);
4650
vscode.window.showInformationMessage(`Successfully switched to session '${choice.label}'.`);
4751
awaitvscode.commands.executeCommand("leetcode.refreshExplorer");
4852
}catch(error){
4953
awaitpromptForOpenOutputChannel("Failed to switch session. Please open the output channel for details.",DialogType.error);
5054
}
5155
}
5256

53-
asyncfunctionparseSessionsToPicks():Promise<Array<IQuickItemEx<string>>>{
54-
returnnewPromise(async(resolve:(res:Array<IQuickItemEx<string>>)=>void):Promise<void>=>{
57+
asyncfunctionparseSessionsToPicks(includeOperations:boolean=false):Promise<Array<IQuickItemEx<ISession|string>>>{
58+
returnnewPromise(async(resolve:(res:Array<IQuickItemEx<ISession|string>>)=>void):Promise<void>=>{
5559
try{
5660
constsessions:ISession[]=awaitgetSessionList();
57-
constpicks:Array<IQuickItemEx<string>>=sessions.map((s:ISession)=>Object.assign({},{
61+
constpicks:Array<IQuickItemEx<ISession|string>>=sessions.map((s:ISession)=>Object.assign({},{
5862
label:`${s.active ?"$(check) " :""}${s.name}`,
5963
description:s.active ?"Active" :"",
6064
detail:`AC Questions:${s.acQuestions}, AC Submits:${s.acSubmits}`,
61-
value:s.id,
65+
value:s,
6266
}));
63-
picks.push({
64-
label:"$(plus) Create a new session",
65-
description:"",
66-
detail:"Click this item to create a new session",
67-
value:":createNewSession",
68-
});
67+
68+
if(includeOperations){
69+
picks.push(...parseSessionManagementOperations());
70+
}
6971
resolve(picks);
7072
}catch(error){
7173
returnawaitpromptForOpenOutputChannel("Failed to list sessions. Please open the output channel for details.",DialogType.error);
7274
}
7375
});
7476
}
7577

76-
exportasyncfunctioncreateSession():Promise<void>{
78+
functionparseSessionManagementOperations():Array<IQuickItemEx<string>>{
79+
return[{
80+
label:"$(plus) Create a session",
81+
description:"",
82+
detail:"Click this item to create a session",
83+
value:":createSession",
84+
},{
85+
label:"$(trashcan) Delete a session",
86+
description:"",
87+
detail:"Click this item to DELETE a session",
88+
value:":deleteSession",
89+
}];
90+
}
91+
92+
asyncfunctioncreateSession():Promise<void>{
7793
constsession:string|undefined=awaitvscode.window.showInputBox({
7894
prompt:"Enter the new session name.",
7995
validateInput:(s:string):string|undefined=>s&&s.trim() ?undefined :"Session name must not be empty",
@@ -89,6 +105,47 @@ export async function createSession(): Promise<void> {
89105
}
90106
}
91107

108+
asyncfunctiondeleteSession():Promise<void>{
109+
constchoice:IQuickItemEx<ISession|string>|undefined=awaitvscode.window.showQuickPick(
110+
parseSessionsToPicks(false/* includeOperation */),
111+
{placeHolder:"Please select the session you want to delete"},
112+
);
113+
if(!choice){
114+
return;
115+
}
116+
117+
constselectedSession:ISession=choice.valueasISession;
118+
if(selectedSession.active){
119+
vscode.window.showInformationMessage("Cannot delete an active session.");
120+
return;
121+
}
122+
123+
constaction:vscode.MessageItem|undefined=awaitvscode.window.showWarningMessage(
124+
`This operation cannot be reverted. Are you sure to delete the session:${selectedSession.name}?`,
125+
DialogOptions.yes,
126+
DialogOptions.no,
127+
);
128+
if(action!==DialogOptions.yes){
129+
return;
130+
}
131+
132+
constconfirm:string|undefined=awaitvscode.window.showInputBox({
133+
prompt:"Enter 'yes' to confirm deleting the session",
134+
validateInput:(value:string):string=>{
135+
if(value==="yes"){
136+
return"";
137+
}else{
138+
return"Enter 'yes' to confirm";
139+
}
140+
},
141+
});
142+
143+
if(confirm==="yes"){
144+
awaitleetCodeExecutor.deleteSession(selectedSession.id);
145+
vscode.window.showInformationMessage("The session has been successfully deleted.");
146+
}
147+
}
148+
92149
exportinterfaceISession{
93150
active:boolean;
94151
id:string;

‎src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
5151
vscode.commands.registerCommand("leetcode.toggleLeetCodeCn",()=>plugin.switchEndpoint()),
5252
vscode.commands.registerCommand("leetcode.signin",()=>leetCodeManager.signIn()),
5353
vscode.commands.registerCommand("leetcode.signout",()=>leetCodeManager.signOut()),
54-
vscode.commands.registerCommand("leetcode.selectSessions",()=>session.selectSession()),
55-
vscode.commands.registerCommand("leetcode.createSession",()=>session.createSession()),
54+
vscode.commands.registerCommand("leetcode.manageSessions",()=>session.manageSessions()),
5655
vscode.commands.registerCommand("leetcode.previewProblem",(node:LeetCodeNode)=>show.previewProblem(node)),
5756
vscode.commands.registerCommand("leetcode.showProblem",(node:LeetCodeNode)=>show.showProblem(node)),
5857
vscode.commands.registerCommand("leetcode.searchProblem",()=>show.searchProblem()),

‎src/leetCodeExecutor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ class LeetCodeExecutor implements Disposable {
124124
returnawaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"session","-e",name]);
125125
}
126126

127-
publicasynccreateSession(name:string):Promise<string>{
128-
returnawaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"session","-c",name]);
127+
publicasynccreateSession(id:string):Promise<string>{
128+
returnawaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"session","-c",id]);
129+
}
130+
131+
publicasyncdeleteSession(id:string):Promise<string>{
132+
returnawaitthis.executeCommandEx(this.nodeExecutable,[awaitthis.getLeetCodeBinaryPath(),"session","-d",id]);
129133
}
130134

131135
publicasyncsubmitSolution(filePath:string):Promise<string>{

‎src/statusbar/LeetCodeStatusBarItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class LeetCodeStatusBarItem implements vscode.Disposable {
99

1010
constructor(){
1111
this.statusBarItem=vscode.window.createStatusBarItem();
12-
this.statusBarItem.command="leetcode.selectSessions";
12+
this.statusBarItem.command="leetcode.manageSessions";
1313
}
1414

1515
publicupdateStatusBar(status:UserStatus,user?:string):void{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp