From 772304ac624c9299e8b4f74048cb81f5f1085bf8 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 26 Feb 2018 12:01:27 +0800 Subject: [PATCH 1/2] fix session switch bug --- src/commands/session.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/commands/session.ts b/src/commands/session.ts index 5f767d2d..6ef22055 100644 --- a/src/commands/session.ts +++ b/src/commands/session.ts @@ -32,7 +32,7 @@ export async function getSessionList(channel: vscode.OutputChannel): Promise { - const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(parseSessionsToPicks(getSessionList(channel))); + const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(parseSessionsToPicks(channel)); if (!choice || choice.description === "Active") { return; } @@ -49,9 +49,15 @@ export async function selectSession(channel: vscode.OutputChannel): Promise): Promise>> { +async function parseSessionsToPicks(channel: vscode.OutputChannel): Promise>> { return new Promise(async (resolve: (res: Array>) => void): Promise => { - const picks: Array> = (await p).map((s: ISession) => Object.assign({}, { + let sessions: ISession[]; + try { + sessions = await getSessionList(channel); + } catch (error) { + return await promptForOpenOutputChannel("Failed to switch session. Please open the output channel for details", DialogType.error, channel); + } + const picks: Array> = 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}`, From 0a7dc26780e32075fff4d146910958b9ac50655b Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 26 Feb 2018 13:06:28 +0800 Subject: [PATCH 2/2] refine code --- src/commands/session.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/commands/session.ts b/src/commands/session.ts index 6ef22055..9003c98d 100644 --- a/src/commands/session.ts +++ b/src/commands/session.ts @@ -51,25 +51,24 @@ export async function selectSession(channel: vscode.OutputChannel): Promise>> { return new Promise(async (resolve: (res: Array>) => void): Promise => { - let sessions: ISession[]; try { - sessions = await getSessionList(channel); + const sessions: ISession[] = await getSessionList(channel); + const picks: Array> = 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, + })); + picks.push({ + label: "$(plus) Create a new session", + description: "", + detail: "Click this item to create a new session", + value: ":createNewSession", + }); + resolve(picks); } catch (error) { - return await promptForOpenOutputChannel("Failed to switch session. Please open the output channel for details", DialogType.error, channel); + return await promptForOpenOutputChannel("Failed to list sessions. Please open the output channel for details", DialogType.error, channel); } - const picks: Array> = 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, - })); - picks.push({ - label: "$(plus) Create a new session", - description: "", - detail: "Click this item to create a new session", - value: ":createNewSession", - }); - resolve(picks); }); }