@@ -4,11 +4,12 @@ import * as vscode from "vscode";
44import { leetCodeManager } from "../leetCodeManager" ;
55import { IQuickItemEx , leetCodeBinaryPath } from "../shared" ;
66import * as cp from "../utils/cpUtils" ;
7- import { DialogType , promptForOpenOutputChannel } from "../utils/uiUtils" ;
7+ import { DialogType , promptForOpenOutputChannel , promptForSignIn } from "../utils/uiUtils" ;
88
99export async function getSessionList ( ) : Promise < ISession [ ] > {
1010 const signInStatus = leetCodeManager . getUser ( ) ;
1111 if ( ! signInStatus ) {
12+ promptForSignIn ( ) ;
1213 return [ ] ;
1314 }
1415 const result : string = await cp . executeCommand ( "node" , [ leetCodeBinaryPath , "session" ] ) ;
@@ -32,7 +33,11 @@ export async function getSessionList(): Promise<ISession[]> {
3233
3334export async function selectSession ( ) : Promise < void > {
3435 const choice : IQuickItemEx < string > | undefined = await vscode . window . showQuickPick ( parseSessionsToPicks ( getSessionList ( ) ) ) ;
35- if ( ! choice || choice . description ) {
36+ if ( ! choice || choice . description === "Active" ) {
37+ return ;
38+ }
39+ if ( choice . value === ":createNewSession" ) {
40+ await vscode . commands . executeCommand ( "leetcode.createSession" ) ;
3641 return ;
3742 }
3843 try {
@@ -51,10 +56,30 @@ async function parseSessionsToPicks(p: Promise<ISession[]>): Promise<Array<IQuic
5156 detail : `AC Questions: ${ s . acQuestions } , AC Submits: ${ s . acSubmits } ` ,
5257 value : s . id ,
5358 } ) ) ;
59+ picks . push ( {
60+ label : "$(plus) Create a new session" ,
61+ description : "" ,
62+ value : ":createNewSession" ,
63+ } ) ;
5464 resolve ( picks ) ;
5565 } ) ;
5666}
5767
68+ export async function createSession ( ) : Promise < void > {
69+ const session : string | undefined = await vscode . window . showInputBox ( {
70+ prompt : "Enter the new session name." ,
71+ validateInput : ( s : string ) => s . trim ( ) ? undefined : "Session name must not be empty" ,
72+ } ) ;
73+ if ( ! session ) {
74+ return ;
75+ }
76+ try {
77+ await cp . executeCommand ( "node" , [ leetCodeBinaryPath , "session" , "-c" , session ] ) ;
78+ } catch ( error ) {
79+ await promptForOpenOutputChannel ( "Failed to create session. Please open the output channel for details" , DialogType . error ) ;
80+ }
81+ }
82+
5883export interface ISession {
5984 active : boolean ;
6085 id : string ;
0 commit comments