@@ -132,45 +132,61 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
132
132
return language ;
133
133
}
134
134
135
- async function showProblemInternal ( node : IProblem ) : Promise < void > {
136
- try {
137
- const language : string | undefined = await fetchProblemLanguage ( ) ;
138
- if ( ! language ) {
139
- return ;
140
- }
141
-
142
- const leetCodeConfig : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "leetcode" ) ;
143
- const workspaceFolder : string = await selectWorkspaceFolder ( ) ;
144
- if ( ! workspaceFolder ) {
145
- return ;
146
- }
135
+ async function createPath ( language :string , node :IProblem ) :Promise < string > {
136
+ const leetCodeConfig : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "leetcode" ) ;
137
+ const workspaceFolder : string = await selectWorkspaceFolder ( ) ;
138
+ if ( ! workspaceFolder ) {
139
+ Promise . reject ( "No workspace is opened." ) ;
140
+ }
147
141
148
- const fileFolder : string = leetCodeConfig
149
- . get < string > ( `filePath.${ language } .folder` , leetCodeConfig . get < string > ( `filePath.default.folder` , "" ) )
150
- . trim ( ) ;
151
- const fileName : string = leetCodeConfig
152
- . get < string > (
153
- `filePath.${ language } .filename` ,
154
- leetCodeConfig . get < string > ( `filePath.default.filename` ) || genFileName ( node , language ) ,
155
- )
156
- . trim ( ) ;
142
+ const fileFolder : string = leetCodeConfig
143
+ . get < string > ( `filePath.${ language } .folder` , leetCodeConfig . get < string > ( `filePath.default.folder` , "" ) )
144
+ . trim ( ) ;
145
+ const fileName : string = leetCodeConfig
146
+ . get < string > (
147
+ `filePath.${ language } .filename` ,
148
+ leetCodeConfig . get < string > ( `filePath.default.filename` ) || genFileName ( node , language ) ,
149
+ )
150
+ . trim ( ) ;
157
151
158
- let finalPath : string = path . join ( workspaceFolder , fileFolder , fileName ) ;
152
+ let finalPath : string = path . join ( workspaceFolder , fileFolder , fileName ) ;
159
153
160
- if ( finalPath ) {
161
- finalPath = await resolveRelativePath ( finalPath , node , language ) ;
162
- if ( ! finalPath ) {
163
- leetCodeChannel . appendLine ( "Showing problem canceled by user." ) ;
164
- return ;
165
- }
154
+ if ( finalPath ) {
155
+ finalPath = await resolveRelativePath ( finalPath , node , language ) ;
156
+ if ( ! finalPath ) {
157
+ leetCodeChannel . appendLine ( "Showing problem canceled by user." ) ;
158
+ Promise . reject ( "Showing problem canceled by user." ) ;
166
159
}
160
+ }
161
+
162
+ finalPath = wsl . useWsl ( ) ? await wsl . toWinPath ( finalPath ) : finalPath ;
163
+ return finalPath ;
164
+ }
167
165
168
- finalPath = wsl . useWsl ( ) ? await wsl . toWinPath ( finalPath ) : finalPath ;
166
+ async function showProblemInternal ( node : IProblem ) : Promise < void > {
167
+ try {
168
+ let language : string | undefined = await fetchProblemLanguage ( ) ;
169
+ if ( ! language ) {
170
+ return ;
171
+ }
172
+ let finalPath : string = await createPath ( language , node ) ;
169
173
170
174
const descriptionConfig : IDescriptionConfiguration = settingUtils . getDescriptionConfiguration ( ) ;
171
175
const needTranslation : boolean = settingUtils . shouldUseEndpointTranslation ( ) ;
176
+ try {
177
+ await leetCodeExecutor . showProblem ( node , language , finalPath , descriptionConfig . showInComment , needTranslation ) ;
178
+ } catch ( e ) {
179
+ if ( e instanceof Error ) {
180
+ //this shows all languages, not just the ones, which are supported for this specific problem
181
+ language = await vscode . window . showQuickPick ( languages , { placeHolder : "This problem is not supporting your default language, please choose another" , ignoreFocusOut : true } ) ;
182
+ if ( language === undefined ) { throw e ; }
172
183
173
- await leetCodeExecutor . showProblem ( node , language , finalPath , descriptionConfig . showInComment , needTranslation ) ;
184
+ finalPath = await createPath ( language , node ) ;
185
+ await leetCodeExecutor . showProblem ( node , language , finalPath , descriptionConfig . showInComment , needTranslation ) ;
186
+ } else {
187
+ throw e ;
188
+ }
189
+ }
174
190
const promises : any [ ] = [
175
191
vscode . window . showTextDocument ( vscode . Uri . file ( finalPath ) , { preview : false , viewColumn : vscode . ViewColumn . One } ) ,
176
192
promptHintMessage (
0 commit comments