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

feat: Support delete a session#358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 5 commits intomasterfromcs/issue-198
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -110,7 +110,7 @@
<img src="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/session.png" alt="Manage Session" />
</p>

- 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.
- 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.


## Settings
Expand Down
2 changes: 1 addition & 1 deletiondocs/README_zh-CN.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -110,7 +110,7 @@
<img src="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/session.png" alt="管理存档" />
</p>

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


## 插件配置项
Expand Down
6 changes: 3 additions & 3 deletionspackage-lock.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

14 changes: 4 additions & 10 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,8 +29,7 @@
"onCommand:leetcode.toggleLeetCodeCn",
"onCommand:leetcode.signin",
"onCommand:leetcode.signout",
"onCommand:leetcode.selectSessions",
"onCommand:leetcode.createSession",
"onCommand:leetcode.manageSessions",
"onCommand:leetcode.refreshExplorer",
"onCommand:leetcode.showProblem",
"onCommand:leetcode.previewProblem",
Expand DownExpand Up@@ -72,13 +71,8 @@
"category": "LeetCode"
},
{
"command": "leetcode.selectSessions",
"title": "Select Session",
"category": "LeetCode"
},
{
"command": "leetcode.createSession",
"title": "Create New Session",
"command": "leetcode.manageSessions",
"title": "Manage Sessions",
"category": "LeetCode"
},
{
Expand DownExpand Up@@ -394,6 +388,6 @@
"markdown-it": "^8.4.2",
"require-from-string": "^2.0.2",
"unescape-js": "^1.1.1",
"vsc-leetcode-cli": "2.6.7"
"vsc-leetcode-cli": "2.6.8"
}
}
91 changes: 74 additions & 17 deletionssrc/commands/session.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { IQuickItemEx } from "../shared";
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import {DialogOptions,DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";

export async function getSessionList(): Promise<ISession[]> {
const signInStatus: string | undefined = leetCodeManager.getUser();
Expand All@@ -32,48 +32,64 @@ export async function getSessionList(): Promise<ISession[]> {
return sessions;
}

export async functionselectSession(): Promise<void> {
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(parseSessionsToPicks());
export async functionmanageSessions(): Promise<void> {
const choice: IQuickItemEx<ISession |string> | undefined = await vscode.window.showQuickPick(parseSessionsToPicks(true /* includeOperation */));
if (!choice || choice.description === "Active") {
return;
}
if (choice.value === ":createNewSession") {
await vscode.commands.executeCommand("leetcode.createSession");
if (choice.value === ":createSession") {
await createSession();
return;
}
if (choice.value === ":deleteSession") {
await deleteSession();
return;
}
try {
await leetCodeExecutor.enableSession(choice.value);
await leetCodeExecutor.enableSession((choice.value as ISession).id);
vscode.window.showInformationMessage(`Successfully switched to session '${choice.label}'.`);
await vscode.commands.executeCommand("leetcode.refreshExplorer");
} catch (error) {
await promptForOpenOutputChannel("Failed to switch session. Please open the output channel for details.", DialogType.error);
}
}

async function parseSessionsToPicks(): Promise<Array<IQuickItemEx<string>>> {
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
async function parseSessionsToPicks(includeOperations: boolean = false): Promise<Array<IQuickItemEx<ISession |string>>> {
return new Promise(async (resolve: (res: Array<IQuickItemEx<ISession |string>>) => void): Promise<void> => {
try {
const sessions: ISession[] = await getSessionList();
const picks: Array<IQuickItemEx<string>> = sessions.map((s: ISession) => Object.assign({}, {
const picks: Array<IQuickItemEx<ISession |string>> = sessions.map((s: ISession) => Object.assign({}, {
label: `${s.active ? "$(check) " : ""}${s.name}`,
description: s.active ? "Active" : "",
detail: `AC Questions: ${s.acQuestions}, AC Submits: ${s.acSubmits}`,
value: s.id,
value: s,
}));
picks.push({
label: "$(plus) Create a new session",
description: "",
detail: "Click this item to create a new session",
value: ":createNewSession",
});

if (includeOperations) {
picks.push(...parseSessionManagementOperations());
}
resolve(picks);
} catch (error) {
return await promptForOpenOutputChannel("Failed to list sessions. Please open the output channel for details.", DialogType.error);
}
});
}

export async function createSession(): Promise<void> {
function parseSessionManagementOperations(): Array<IQuickItemEx<string>> {
return [{
label: "$(plus) Create a session",
description: "",
detail: "Click this item to create a session",
value: ":createSession",
}, {
label: "$(trashcan) Delete a session",
description: "",
detail: "Click this item to DELETE a session",
value: ":deleteSession",
}];
}

async function createSession(): Promise<void> {
const session: string | undefined = await vscode.window.showInputBox({
prompt: "Enter the new session name.",
validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Session name must not be empty",
Expand All@@ -89,6 +105,47 @@ export async function createSession(): Promise<void> {
}
}

async function deleteSession(): Promise<void> {
const choice: IQuickItemEx<ISession | string> | undefined = await vscode.window.showQuickPick(
parseSessionsToPicks(false /* includeOperation */),
{ placeHolder: "Please select the session you want to delete" },
);
if (!choice) {
return;
}

const selectedSession: ISession = choice.value as ISession;
if (selectedSession.active) {
vscode.window.showInformationMessage("Cannot delete an active session.");
return;
}

const action: vscode.MessageItem | undefined = await vscode.window.showWarningMessage(
`This operation cannot be reverted. Are you sure to delete the session: ${selectedSession.name}?`,
DialogOptions.yes,
DialogOptions.no,
);
if (action !== DialogOptions.yes) {
return;
}

const confirm: string | undefined = await vscode.window.showInputBox({
prompt: "Enter 'yes' to confirm deleting the session",
validateInput: (value: string): string => {
if (value === "yes") {
return "";
} else {
return "Enter 'yes' to confirm";
}
},
});

if (confirm === "yes") {
await leetCodeExecutor.deleteSession(selectedSession.id);
vscode.window.showInformationMessage("The session has been successfully deleted.");
}
}

export interface ISession {
active: boolean;
id: string;
Expand Down
3 changes: 1 addition & 2 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,8 +51,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.toggleLeetCodeCn", () => plugin.switchEndpoint()),
vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()),
vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()),
vscode.commands.registerCommand("leetcode.selectSessions", () => session.selectSession()),
vscode.commands.registerCommand("leetcode.createSession", () => session.createSession()),
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.searchProblem", () => show.searchProblem()),
Expand Down
8 changes: 6 additions & 2 deletionssrc/leetCodeExecutor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,8 +124,12 @@ class LeetCodeExecutor implements Disposable {
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-e", name]);
}

public async createSession(name: string): Promise<string> {
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-c", name]);
public async createSession(id: string): Promise<string> {
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-c", id]);
}

public async deleteSession(id: string): Promise<string> {
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-d", id]);
}

public async submitSolution(filePath: string): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletionsrc/statusbar/LeetCodeStatusBarItem.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ export class LeetCodeStatusBarItem implements vscode.Disposable {

constructor() {
this.statusBarItem = vscode.window.createStatusBarItem();
this.statusBarItem.command = "leetcode.selectSessions";
this.statusBarItem.command = "leetcode.manageSessions";
}

public updateStatusBar(status: UserStatus, user?: string): void {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp