@@ -8,7 +8,7 @@ import * as path from "path";
8
8
import requireFromString = require( "require-from-string" ) ;
9
9
import { ExtensionContext } from "vscode" ;
10
10
import { ConfigurationChangeEvent , Disposable , MessageItem , window , workspace , WorkspaceConfiguration } from "vscode" ;
11
- import { Endpoint , IProblem , leetcodeHasInited , supportedPlugins } from "./shared" ;
11
+ import { IProblem , leetcodeHasInited , supportedPlugins } from "./shared" ;
12
12
import { executeCommand , executeCommandWithProgress } from "./utils/cpUtils" ;
13
13
import { DialogOptions , openUrl } from "./utils/uiUtils" ;
14
14
import * as wsl from "./utils/wslUtils" ;
@@ -37,12 +37,18 @@ class LeetCodeExecutor implements Disposable {
37
37
}
38
38
39
39
public async meetRequirements ( context : ExtensionContext ) : Promise < boolean > {
40
+ console . log ( "LeetCode: Checking requirements..." ) ;
41
+
40
42
const hasInited : boolean | undefined = context . globalState . get ( leetcodeHasInited ) ;
41
43
if ( ! hasInited ) {
44
+ console . log ( "LeetCode: Extension not initialized, removing old cache..." ) ;
42
45
await this . removeOldCache ( ) ;
43
46
}
47
+
48
+ console . log ( "LeetCode: Node executable path:" , this . nodeExecutable ) ;
44
49
if ( this . nodeExecutable !== "node" ) {
45
50
if ( ! await fse . pathExists ( this . nodeExecutable ) ) {
51
+ console . error ( "LeetCode: Node.js executable not found at:" , this . nodeExecutable ) ;
46
52
throw new Error ( `The Node.js executable does not exist on path ${ this . nodeExecutable } ` ) ;
47
53
}
48
54
// Wrap the executable with "" to avoid space issue in the path.
@@ -51,9 +57,13 @@ class LeetCodeExecutor implements Disposable {
51
57
this . nodeExecutable = await toWslPath ( this . nodeExecutable ) ;
52
58
}
53
59
}
60
+
61
+ console . log ( "LeetCode: Testing Node.js..." ) ;
54
62
try {
55
63
await this . executeCommandEx ( this . nodeExecutable , [ "-v" ] ) ;
64
+ console . log ( "LeetCode: Node.js test successful" ) ;
56
65
} catch ( error ) {
66
+ console . error ( "LeetCode: Node.js test failed:" , error ) ;
57
67
const choice : MessageItem | undefined = await window . showErrorMessage (
58
68
"LeetCode extension needs Node.js installed in environment path" ,
59
69
DialogOptions . open ,
@@ -63,16 +73,24 @@ class LeetCodeExecutor implements Disposable {
63
73
}
64
74
return false ;
65
75
}
76
+
77
+ console . log ( "LeetCode: Checking plugins..." ) ;
66
78
for ( const plugin of supportedPlugins ) {
79
+ console . log ( "LeetCode: Checking plugin:" , plugin ) ;
67
80
try { // Check plugin
68
81
await this . executeCommandEx ( this . nodeExecutable , [ await this . getLeetCodeBinaryPath ( ) , "plugin" , "-e" , plugin ] ) ;
82
+ console . log ( "LeetCode: Plugin" , plugin , "is available" ) ;
69
83
} 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" ) ;
72
88
}
73
89
}
90
+
74
91
// Set the global state HasInited true to skip delete old cache after init
75
92
context . globalState . update ( leetcodeHasInited , true ) ;
93
+ console . log ( "LeetCode: Requirements check completed successfully" ) ;
76
94
return true ;
77
95
}
78
96
@@ -111,13 +129,13 @@ class LeetCodeExecutor implements Disposable {
111
129
if ( ! await fse . pathExists ( filePath ) ) {
112
130
await fse . createFile ( filePath ) ;
113
131
let codeTemplate : string = await this . executeCommandWithProgressEx ( "Fetching problem data..." , this . nodeExecutable , cmd ) ;
114
-
132
+
115
133
// Add C++ headers if needed
116
134
if ( shouldAddHeaders && ( language === "cpp" || language === "c" ) ) {
117
135
const cppHeaders = this . generateCppHeaders ( ) ;
118
136
codeTemplate = cppHeaders + codeTemplate ;
119
137
}
120
-
138
+
121
139
await fse . writeFile ( filePath , codeTemplate ) ;
122
140
}
123
141
}
@@ -187,14 +205,19 @@ class LeetCodeExecutor implements Disposable {
187
205
return await this . executeCommandWithProgressEx ( "Submitting to LeetCode..." , this . nodeExecutable , [ await this . getLeetCodeBinaryPath ( ) , "test" , `"${ filePath } "` ] ) ;
188
206
}
189
207
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
+ /*
191
213
switch (endpoint) {
192
214
case Endpoint.LeetCodeCN:
193
215
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
194
216
case Endpoint.LeetCode:
195
217
default:
196
218
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]);
197
219
}
220
+ */
198
221
}
199
222
200
223
public async toggleFavorite ( node : IProblem , addToFavorite : boolean ) : Promise < void > {
@@ -261,16 +284,16 @@ class LeetCodeExecutor implements Disposable {
261
284
return [ ] ;
262
285
}
263
286
}
264
-
287
+
265
288
public async getDailyChallengeHistory ( _needTranslation ?: boolean , days : number = 30 ) : Promise < any [ ] > {
266
289
try {
267
290
const https = require ( 'https' ) ;
268
-
291
+
269
292
// Получаем данные за последние дни
270
293
const endDate = new Date ( ) ;
271
294
const startDate = new Date ( ) ;
272
295
startDate . setDate ( endDate . getDate ( ) - days ) ;
273
-
296
+
274
297
const query = `
275
298
query dailyCodingQuestionRecords($year: Int!, $month: Int!) {
276
299
dailyCodingChallengeV2(year: $year, month: $month) {
@@ -300,27 +323,27 @@ class LeetCodeExecutor implements Disposable {
300
323
}
301
324
}
302
325
` ;
303
-
326
+
304
327
const challenges : any [ ] = [ ] ;
305
328
const processedMonths = new Set < string > ( ) ;
306
-
329
+
307
330
// Получаем данные для текущего и предыдущего месяца
308
331
for ( let i = 0 ; i <= 1 ; i ++ ) {
309
332
const targetDate = new Date ( ) ;
310
333
targetDate . setMonth ( targetDate . getMonth ( ) - i ) ;
311
-
334
+
312
335
const year = targetDate . getFullYear ( ) ;
313
336
const month = targetDate . getMonth ( ) + 1 ;
314
337
const monthKey = `${ year } -${ month } ` ;
315
-
338
+
316
339
if ( processedMonths . has ( monthKey ) ) continue ;
317
340
processedMonths . add ( monthKey ) ;
318
-
341
+
319
342
const postData = JSON . stringify ( {
320
343
query : query ,
321
344
variables : { year, month }
322
345
} ) ;
323
-
346
+
324
347
const options = {
325
348
hostname : 'leetcode.com' ,
326
349
port : 443 ,
@@ -332,7 +355,7 @@ class LeetCodeExecutor implements Disposable {
332
355
'User-Agent' : 'vscode-leetcode-extension'
333
356
}
334
357
} ;
335
-
358
+
336
359
const response = await new Promise < string > ( ( resolve , reject ) => {
337
360
const req = https . request ( options , ( res : any ) => {
338
361
let data = '' ;
@@ -343,15 +366,15 @@ class LeetCodeExecutor implements Disposable {
343
366
resolve ( data ) ;
344
367
} ) ;
345
368
} ) ;
346
-
369
+
347
370
req . on ( 'error' , ( error : any ) => {
348
371
reject ( error ) ;
349
372
} ) ;
350
-
373
+
351
374
req . write ( postData ) ;
352
375
req . end ( ) ;
353
376
} ) ;
354
-
377
+
355
378
const jsonData = JSON . parse ( response ) ;
356
379
if ( jsonData . data && jsonData . data . dailyCodingChallengeV2 && jsonData . data . dailyCodingChallengeV2 . challenges ) {
357
380
const monthChallenges = jsonData . data . dailyCodingChallengeV2 . challenges
@@ -372,14 +395,14 @@ class LeetCodeExecutor implements Disposable {
372
395
link : challenge . link
373
396
} ;
374
397
} ) ;
375
-
398
+
376
399
challenges . push ( ...monthChallenges ) ;
377
400
}
378
401
}
379
-
402
+
380
403
// Сортируем по дате (новые сверху)
381
404
challenges . sort ( ( a , b ) => new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( ) ) ;
382
-
405
+
383
406
// Ограничиваем количество дней
384
407
return challenges . slice ( 0 , days ) ;
385
408
}
0 commit comments