Skip to content

Commit bc2caa1

Browse files
authored
fix session switch bug (LeetCode-OpenSource#13)
* fix session switch bug * refine code
1 parent 8ea762c commit bc2caa1

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/commands/session.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function getSessionList(channel: vscode.OutputChannel): Promise<ISe
3232
}
3333

3434
export async function selectSession(channel: vscode.OutputChannel): Promise<void> {
35-
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(parseSessionsToPicks(getSessionList(channel)));
35+
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(parseSessionsToPicks(channel));
3636
if (!choice || choice.description === "Active") {
3737
return;
3838
}
@@ -49,21 +49,26 @@ export async function selectSession(channel: vscode.OutputChannel): Promise<void
4949
}
5050
}
5151

52-
async function parseSessionsToPicks(p: Promise<ISession[]>): Promise<Array<IQuickItemEx<string>>> {
52+
async function parseSessionsToPicks(channel: vscode.OutputChannel): Promise<Array<IQuickItemEx<string>>> {
5353
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
54-
const picks: Array<IQuickItemEx<string>> = (await p).map((s: ISession) => Object.assign({}, {
55-
label: `${s.active ? "$(check) " : ""}${s.name}`,
56-
description: s.active ? "Active" : "",
57-
detail: `AC Questions: ${s.acQuestions}, AC Submits: ${s.acSubmits}`,
58-
value: s.id,
59-
}));
60-
picks.push({
61-
label: "$(plus) Create a new session",
62-
description: "",
63-
detail: "Click this item to create a new session",
64-
value: ":createNewSession",
65-
});
66-
resolve(picks);
54+
try {
55+
const sessions: ISession[] = await getSessionList(channel);
56+
const picks: Array<IQuickItemEx<string>> = sessions.map((s: ISession) => Object.assign({}, {
57+
label: `${s.active ? "$(check) " : ""}${s.name}`,
58+
description: s.active ? "Active" : "",
59+
detail: `AC Questions: ${s.acQuestions}, AC Submits: ${s.acSubmits}`,
60+
value: s.id,
61+
}));
62+
picks.push({
63+
label: "$(plus) Create a new session",
64+
description: "",
65+
detail: "Click this item to create a new session",
66+
value: ":createNewSession",
67+
});
68+
resolve(picks);
69+
} catch (error) {
70+
return await promptForOpenOutputChannel("Failed to list sessions. Please open the output channel for details", DialogType.error, channel);
71+
}
6772
});
6873
}
6974

0 commit comments

Comments
 (0)
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