@@ -4,11 +4,12 @@ import * as vscode from "vscode";
4
4
import { leetCodeManager } from "../leetCodeManager" ;
5
5
import { IQuickItemEx , leetCodeBinaryPath } from "../shared" ;
6
6
import * as cp from "../utils/cpUtils" ;
7
- import { DialogType , promptForOpenOutputChannel } from "../utils/uiUtils" ;
7
+ import { DialogType , promptForOpenOutputChannel , promptForSignIn } from "../utils/uiUtils" ;
8
8
9
9
export async function getSessionList ( ) : Promise < ISession [ ] > {
10
10
const signInStatus = leetCodeManager . getUser ( ) ;
11
11
if ( ! signInStatus ) {
12
+ promptForSignIn ( ) ;
12
13
return [ ] ;
13
14
}
14
15
const result : string = await cp . executeCommand ( "node" , [ leetCodeBinaryPath , "session" ] ) ;
@@ -32,7 +33,11 @@ export async function getSessionList(): Promise<ISession[]> {
32
33
33
34
export async function selectSession ( ) : Promise < void > {
34
35
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" ) ;
36
41
return ;
37
42
}
38
43
try {
@@ -51,10 +56,30 @@ async function parseSessionsToPicks(p: Promise<ISession[]>): Promise<Array<IQuic
51
56
detail : `AC Questions: ${ s . acQuestions } , AC Submits: ${ s . acSubmits } ` ,
52
57
value : s . id ,
53
58
} ) ) ;
59
+ picks . push ( {
60
+ label : "$(plus) Create a new session" ,
61
+ description : "" ,
62
+ value : ":createNewSession" ,
63
+ } ) ;
54
64
resolve ( picks ) ;
55
65
} ) ;
56
66
}
57
67
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
+
58
83
export interface ISession {
59
84
active : boolean ;
60
85
id : string ;
0 commit comments