@@ -8,7 +8,7 @@ import * as path from "path";
88import requireFromString = require( "require-from-string" ) ;
99import { ExtensionContext } from "vscode" ;
1010import { ConfigurationChangeEvent , Disposable , MessageItem , window , workspace , WorkspaceConfiguration } from "vscode" ;
11- import { Endpoint , IProblem , leetcodeHasInited , supportedPlugins } from "./shared" ;
11+ import { IProblem , leetcodeHasInited , supportedPlugins } from "./shared" ;
1212import { executeCommand , executeCommandWithProgress } from "./utils/cpUtils" ;
1313import { DialogOptions , openUrl } from "./utils/uiUtils" ;
1414import * as wsl from "./utils/wslUtils" ;
@@ -37,12 +37,18 @@ class LeetCodeExecutor implements Disposable {
3737 }
3838
3939 public async meetRequirements ( context : ExtensionContext ) : Promise < boolean > {
40+ console . log ( "LeetCode: Checking requirements..." ) ;
41+
4042 const hasInited : boolean | undefined = context . globalState . get ( leetcodeHasInited ) ;
4143 if ( ! hasInited ) {
44+ console . log ( "LeetCode: Extension not initialized, removing old cache..." ) ;
4245 await this . removeOldCache ( ) ;
4346 }
47+
48+ console . log ( "LeetCode: Node executable path:" , this . nodeExecutable ) ;
4449 if ( this . nodeExecutable !== "node" ) {
4550 if ( ! await fse . pathExists ( this . nodeExecutable ) ) {
51+ console . error ( "LeetCode: Node.js executable not found at:" , this . nodeExecutable ) ;
4652 throw new Error ( `The Node.js executable does not exist on path ${ this . nodeExecutable } ` ) ;
4753 }
4854 // Wrap the executable with "" to avoid space issue in the path.
@@ -51,9 +57,13 @@ class LeetCodeExecutor implements Disposable {
5157 this . nodeExecutable = await toWslPath ( this . nodeExecutable ) ;
5258 }
5359 }
60+
61+ console . log ( "LeetCode: Testing Node.js..." ) ;
5462 try {
5563 await this . executeCommandEx ( this . nodeExecutable , [ "-v" ] ) ;
64+ console . log ( "LeetCode: Node.js test successful" ) ;
5665 } catch ( error ) {
66+ console . error ( "LeetCode: Node.js test failed:" , error ) ;
5767 const choice : MessageItem | undefined = await window . showErrorMessage (
5868 "LeetCode extension needs Node.js installed in environment path" ,
5969 DialogOptions . open ,
@@ -63,16 +73,24 @@ class LeetCodeExecutor implements Disposable {
6373 }
6474 return false ;
6575 }
76+
77+ console . log ( "LeetCode: Checking plugins..." ) ;
6678 for ( const plugin of supportedPlugins ) {
79+ console . log ( "LeetCode: Checking plugin:" , plugin ) ;
6780 try { // Check plugin
6881 await this . executeCommandEx ( this . nodeExecutable , [ await this . getLeetCodeBinaryPath ( ) , "plugin" , "-e" , plugin ] ) ;
82+ console . log ( "LeetCode: Plugin" , plugin , "is available" ) ;
6983 } catch ( error ) { // Remove old cache that may cause the error download plugin and activate
70- await this . removeOldCache ( ) ;
71- await this . executeCommandEx ( this . nodeExecutable , [ await this . getLeetCodeBinaryPath ( ) , "plugin" , "-i" , plugin ] ) ;
84+ console . log ( "LeetCode: Plugin" , plugin , "not found, installing..." ) ;
85+ // await this.removeOldCache();
86+ // await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-i", plugin]);
87+ console . log ( "LeetCode: Plugin" , plugin , "installed successfully" ) ;
7288 }
7389 }
90+
7491 // Set the global state HasInited true to skip delete old cache after init
7592 context . globalState . update ( leetcodeHasInited , true ) ;
93+ console . log ( "LeetCode: Requirements check completed successfully" ) ;
7694 return true ;
7795 }
7896
@@ -111,13 +129,13 @@ class LeetCodeExecutor implements Disposable {
111129 if ( ! await fse . pathExists ( filePath ) ) {
112130 await fse . createFile ( filePath ) ;
113131 let codeTemplate : string = await this . executeCommandWithProgressEx ( "Fetching problem data..." , this . nodeExecutable , cmd ) ;
114-
132+
115133 // Add C++ headers if needed
116134 if ( shouldAddHeaders && ( language === "cpp" || language === "c" ) ) {
117135 const cppHeaders = this . generateCppHeaders ( ) ;
118136 codeTemplate = cppHeaders + codeTemplate ;
119137 }
120-
138+
121139 await fse . writeFile ( filePath , codeTemplate ) ;
122140 }
123141 }
@@ -187,14 +205,19 @@ class LeetCodeExecutor implements Disposable {
187205 return await this . executeCommandWithProgressEx ( "Submitting to LeetCode..." , this . nodeExecutable , [ await this . getLeetCodeBinaryPath ( ) , "test" , `"${ filePath } "` ] ) ;
188206 }
189207
190- public async switchEndpoint ( endpoint : string ) : Promise < string > {
208+ public async switchEndpoint ( _endpoint : string ) : Promise < string > {
209+ // Отключено для избежания конфликтов с оригинальным расширением
210+ console . log ( "LeetCode: Endpoint switching disabled to avoid conflicts" ) ;
211+ return "Endpoint switching disabled" ;
212+ /*
191213 switch (endpoint) {
192214 case Endpoint.LeetCodeCN:
193215 return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
194216 case Endpoint.LeetCode:
195217 default:
196218 return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]);
197219 }
220+ */
198221 }
199222
200223 public async toggleFavorite ( node : IProblem , addToFavorite : boolean ) : Promise < void > {
@@ -261,16 +284,16 @@ class LeetCodeExecutor implements Disposable {
261284 return [ ] ;
262285 }
263286 }
264-
287+
265288 public async getDailyChallengeHistory ( _needTranslation ?: boolean , days : number = 30 ) : Promise < any [ ] > {
266289 try {
267290 const https = require ( 'https' ) ;
268-
291+
269292 // Получаем данные за последние дни
270293 const endDate = new Date ( ) ;
271294 const startDate = new Date ( ) ;
272295 startDate . setDate ( endDate . getDate ( ) - days ) ;
273-
296+
274297 const query = `
275298 query dailyCodingQuestionRecords($year: Int!, $month: Int!) {
276299 dailyCodingChallengeV2(year: $year, month: $month) {
@@ -300,27 +323,27 @@ class LeetCodeExecutor implements Disposable {
300323 }
301324 }
302325 ` ;
303-
326+
304327 const challenges : any [ ] = [ ] ;
305328 const processedMonths = new Set < string > ( ) ;
306-
329+
307330 // Получаем данные для текущего и предыдущего месяца
308331 for ( let i = 0 ; i <= 1 ; i ++ ) {
309332 const targetDate = new Date ( ) ;
310333 targetDate . setMonth ( targetDate . getMonth ( ) - i ) ;
311-
334+
312335 const year = targetDate . getFullYear ( ) ;
313336 const month = targetDate . getMonth ( ) + 1 ;
314337 const monthKey = `${ year } -${ month } ` ;
315-
338+
316339 if ( processedMonths . has ( monthKey ) ) continue ;
317340 processedMonths . add ( monthKey ) ;
318-
341+
319342 const postData = JSON . stringify ( {
320343 query : query ,
321344 variables : { year, month }
322345 } ) ;
323-
346+
324347 const options = {
325348 hostname : 'leetcode.com' ,
326349 port : 443 ,
@@ -332,7 +355,7 @@ class LeetCodeExecutor implements Disposable {
332355 'User-Agent' : 'vscode-leetcode-extension'
333356 }
334357 } ;
335-
358+
336359 const response = await new Promise < string > ( ( resolve , reject ) => {
337360 const req = https . request ( options , ( res : any ) => {
338361 let data = '' ;
@@ -343,15 +366,15 @@ class LeetCodeExecutor implements Disposable {
343366 resolve ( data ) ;
344367 } ) ;
345368 } ) ;
346-
369+
347370 req . on ( 'error' , ( error : any ) => {
348371 reject ( error ) ;
349372 } ) ;
350-
373+
351374 req . write ( postData ) ;
352375 req . end ( ) ;
353376 } ) ;
354-
377+
355378 const jsonData = JSON . parse ( response ) ;
356379 if ( jsonData . data && jsonData . data . dailyCodingChallengeV2 && jsonData . data . dailyCodingChallengeV2 . challenges ) {
357380 const monthChallenges = jsonData . data . dailyCodingChallengeV2 . challenges
@@ -372,14 +395,14 @@ class LeetCodeExecutor implements Disposable {
372395 link : challenge . link
373396 } ;
374397 } ) ;
375-
398+
376399 challenges . push ( ...monthChallenges ) ;
377400 }
378401 }
379-
402+
380403 // Сортируем по дате (новые сверху)
381404 challenges . sort ( ( a , b ) => new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( ) ) ;
382-
405+
383406 // Ограничиваем количество дней
384407 return challenges . slice ( 0 , days ) ;
385408 }
0 commit comments