@@ -52,13 +52,91 @@ export async function pickOne(): Promise<void> {
52
52
await showProblemInternal ( randomProblem ) ;
53
53
}
54
54
55
+ export async function generateDocumentation ( ) : Promise < void > {
56
+ const ids : string | undefined = await vscode . window . showInputBox ( {
57
+ prompt : "Enter problem id. e.g. 1, 1-10, 1,2,3, 1,2,3-10" ,
58
+ ignoreFocusOut : true ,
59
+ validateInput : ( s : string ) : string | undefined => s && s . trim ( ) ? undefined : "The input must not be empty" ,
60
+ } ) ;
61
+ if ( ! ids ) {
62
+ return ;
63
+ }
64
+ const idArray : string [ ] = ids . split ( "," ) ;
65
+ const nodeArray : IProblem [ ] = [ ] ;
66
+ for ( const id of idArray ) {
67
+ const _id : string = id . trim ( ) ;
68
+ if ( _id . search ( "-" ) > 0 ) {
69
+ const range : string [ ] = _id . split ( "-" ) ;
70
+ const start : number = parseInt ( range [ 0 ] , 10 ) ;
71
+ const end : number = parseInt ( range [ 1 ] , 10 ) ;
72
+ if ( start > 0 && end > 0 && start <= end ) {
73
+ for ( let i : number = start ; i <= end ; i ++ ) {
74
+ console . log ( `Show documentation: ${ i } ` ) ;
75
+ const node : IProblem | undefined = explorerNodeManager . getNodeById ( i . toString ( ) ) ;
76
+ if ( node ) {
77
+ nodeArray . push ( node ) ;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ else {
83
+ console . log ( `Show documentation: ${ _id } ` ) ;
84
+ const node : IProblem | undefined = explorerNodeManager . getNodeById ( _id ) ;
85
+ if ( node ) {
86
+ nodeArray . push ( node ) ;
87
+ }
88
+ }
89
+ }
90
+
91
+ for ( const node of nodeArray ) {
92
+ const finalPath : string = await assureDoucumentation ( node ) ;
93
+ if ( ! finalPath ) {
94
+ continue ;
95
+ }
96
+ try {
97
+ await leetCodeExecutor . showDocumentationInternal ( node , finalPath ) ;
98
+ }
99
+ catch ( error ) {
100
+ console . log ( error ) ;
101
+ vscode . window . showErrorMessage ( error ) ;
102
+ }
103
+ }
104
+ }
105
+
55
106
export async function showProblem ( node ?: LeetCodeNode ) : Promise < void > {
56
107
if ( ! node ) {
57
108
return ;
58
109
}
59
110
await showProblemInternal ( node ) ;
60
111
}
61
112
113
+ async function assureDoucumentation ( node : IProblem ) : Promise < string > {
114
+ const leetCodeConfig : vscode . WorkspaceConfiguration = getWorkspaceConfiguration ( ) ;
115
+ const workspaceFolder : string = await selectWorkspaceFolder ( ) ;
116
+ if ( ! workspaceFolder ) {
117
+ return "" ;
118
+ }
119
+
120
+ const fileFolder : string = leetCodeConfig . get < string > ( `filePath.doc.folder` , "" ) . trim ( ) ;
121
+ const fileName : string = leetCodeConfig . get < string > ( `filePath.doc.filename` , "" ) . trim ( ) ;
122
+ if ( fileFolder === "" || fileName === "" ) {
123
+ await promptForOpenOutputChannel ( "Please configure the file path first." , DialogType . error ) ;
124
+ return "" ;
125
+ }
126
+
127
+ let finalPath : string = path . join ( workspaceFolder , fileFolder , fileName ) ;
128
+ if ( finalPath ) {
129
+ finalPath = await resolveRelativePath ( finalPath , node , "md" ) ;
130
+ if ( ! finalPath ) {
131
+ leetCodeChannel . appendLine ( "Showing problem canceled by user." ) ;
132
+ return "" ;
133
+ }
134
+ }
135
+ finalPath = wsl . useWsl ( ) ? await wsl . toWinPath ( finalPath ) : finalPath ;
136
+ console . log ( `Documentation path: ${ finalPath } ` ) ;
137
+ return finalPath ;
138
+ }
139
+
62
140
export async function showDocumentation ( node ?: LeetCodeNode ) : Promise < void > {
63
141
if ( ! node ) {
64
142
return ;
0 commit comments