@@ -13,7 +13,7 @@ import * as os from "os";
1313import * as path from "path" ;
1414import { ExtensionContext , ProgressLocation , Progress } from "vscode" ;
1515import { ConfigurationChangeEvent , Disposable , MessageItem , window , workspace } from "vscode" ;
16- import { DialogOptions , OutPutType , Endpoint , leetcodeHasInited } from "../model/ConstDefind" ;
16+ import { DialogOptions , OutPutType , Endpoint , leetcodeHasInited , IQuickItemEx } from "../model/ConstDefind" ;
1717import { getLeetCodeEndpoint , getNodePath } from "../utils/ConfigUtils" ;
1818import { openUrl , ShowMessage } from "../utils/OutputUtils" ;
1919import * as systemUtils from "../utils/SystemUtils" ;
@@ -175,13 +175,83 @@ class ExecuteService implements Disposable {
175175 if ( ! needTranslation ) {
176176 cmd . push ( "-T" ) ;
177177 }
178+ let solution ;
178179 if ( cn_help ) {
179180 cmd . push ( "-f" ) ;
181+ solution = await this . callWithMsg (
182+ "正在获取中文题解~~~" ,
183+ this . nodeExecutable ,
184+ cmd ,
185+ undefined ,
186+ this . tryCnMulSolution ,
187+ { }
188+ ) ;
189+ } else {
190+ solution = await this . callWithMsg ( "正在获取题解~~~" , this . nodeExecutable , cmd ) ;
180191 }
181- const solution : string = await this . callWithMsg ( "正在获取题解~~~" , this . nodeExecutable , cmd ) ;
192+
182193 return solution ;
183194 }
184195
196+ public async tryCnMulSolution ( _ , child_process , resolve , reject ) {
197+ child_process . stdout ?. on ( "data" , async ( data : string | Buffer ) => {
198+ data = data . toString ( ) ;
199+ BABA . getProxy ( BabaStr . LogOutputProxy ) . get_log ( ) . append ( data ) ;
200+ let successMatch : any ;
201+ try {
202+ successMatch = JSON . parse ( data ) ;
203+ } catch ( e ) {
204+ successMatch = { } ;
205+ }
206+
207+ if ( successMatch . oper == "requireOper" ) {
208+ let cookie = successMatch . cookie ;
209+ let arg = successMatch . arg ;
210+ if ( arg . oper == "need_select" ) {
211+ let canSelect = arg . canSelect || [ ] ;
212+ const picks : Array < IQuickItemEx < string > > = [ ] ;
213+
214+ canSelect . forEach ( ( element ) => {
215+ if ( element ?. node ?. slug ) {
216+ picks . push ( {
217+ label : `${ element ?. node . title } ` ,
218+ description : `作者:${ element ?. node ?. author ?. username } ` ,
219+ detail : "" ,
220+ value : element ?. node ?. slug ,
221+ } ) ;
222+ }
223+ } ) ;
224+
225+ const choice : IQuickItemEx < string > | undefined = await window . showQuickPick ( picks , {
226+ ignoreFocusOut : true ,
227+ } ) ;
228+ if ( ! choice ) {
229+ child_process . stdin ?. end ( ) ;
230+ return reject ( new Error ( successMatch . msg ) ) ;
231+ }
232+
233+ let select_result = {
234+ c : cookie ,
235+ slug : choice . value ,
236+ } ;
237+ child_process . stdin ?. write ( JSON . stringify ( select_result ) ) ;
238+ }
239+ return ;
240+ }
241+ if ( successMatch . code == 100 ) {
242+ child_process . stdin ?. end ( ) ;
243+ return resolve ( data ) ;
244+ } else if ( successMatch . code < 0 ) {
245+ child_process . stdin ?. end ( ) ;
246+ return reject ( new Error ( successMatch . msg ) ) ;
247+ }
248+ } ) ;
249+ child_process . stderr ?. on ( "data" , ( data : string | Buffer ) => {
250+ BABA . getProxy ( BabaStr . LogOutputProxy ) . get_log ( ) . append ( data . toString ( ) ) ;
251+ } ) ;
252+ child_process . on ( "error" , reject ) ;
253+ }
254+
185255 public async getUserContest ( needTranslation : boolean , username : string ) : Promise < string > {
186256 // solution don't support translation
187257 const cmd : string [ ] = [ await this . getLeetCodeBinaryPath ( ) , "query" , "-b" , username ] ;
0 commit comments