Skip to content

Commit 4fe1a11

Browse files
committed
minor changes
1 parent 0424628 commit 4fe1a11

File tree

5 files changed

+77
-36
lines changed

5 files changed

+77
-36
lines changed

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
{
2-
"name": "vscode-leetcode-fork",
3-
"displayName": "LeetCode-fork",
4-
"description": "Solve LeetCode problems in VS Code",
2+
"name": "vscode-leetcode",
3+
"displayName": "LeetCode Enhanced Fork",
4+
"description": "Enhanced fork of LeetCode VS Code extension with Daily Challenges and improved functionality",
55
"version": "0.18.5",
66
"author": "su-mt",
7-
"publisher": "su-mt",
7+
"publisher": "leetcode",
88
"license": "MIT",
99
"icon": "resources/LeetCode.png",
1010
"engines": {
1111
"vscode": "^1.57.0"
1212
},
1313
"repository": {
1414
"type": "git",
15-
"url": "https://github.com/LeetCode-OpenSource/vscode-leetcode"
15+
"url": "https://github.com/su-mt/vscode-leetcode"
1616
},
17-
"homepage": "https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/README.md",
17+
"homepage": "https://github.com/su-mt/vscode-leetcode/blob/feature/daily-challenges/README.md",
1818
"categories": [
19-
"Other",
20-
"Snippets"
19+
"Education",
20+
"Other"
2121
],
2222
"keywords": [
23-
"leetcode",
23+
"leetcode-enhanced",
24+
"coding-practice",
2425
"algorithm",
25-
"interview"
26+
"interview",
27+
"daily-challenges"
2628
],
2729
"preview": true,
2830
"activationEvents": [

src/extension.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ import { globalState } from "./globalState";
2929

3030
export async function activate(context: vscode.ExtensionContext): Promise<void> {
3131
try {
32+
console.log("LeetCode extension: Starting activation...");
33+
3234
if (!(await leetCodeExecutor.meetRequirements(context))) {
35+
console.error("LeetCode extension: Environment doesn't meet requirements");
3336
throw new Error("The environment doesn't meet requirements.");
3437
}
3538

39+
console.log("LeetCode extension: Requirements met, setting up event handlers...");
40+
3641
leetCodeManager.on("statusChanged", () => {
3742
leetCodeStatusBarController.updateStatusBar(leetCodeManager.getStatus(), leetCodeManager.getUser());
3843
leetCodeTreeDataProvider.refresh();
3944
});
4045

46+
console.log("LeetCode extension: Initializing providers...");
4147
leetCodeTreeDataProvider.initialize(context);
4248
globalState.initialize(context);
4349

50+
console.log("LeetCode extension: Registering commands and providers...");
4451
context.subscriptions.push(
4552
leetCodeStatusBarController,
4653
leetCodeChannel,
@@ -100,10 +107,19 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
100107
vscode.commands.registerCommand("leetcode.problems.sort", () => plugin.switchSortingStrategy())
101108
);
102109

103-
await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint());
110+
console.log("LeetCode extension: All commands registered successfully");
111+
console.log("LeetCode extension: Switching endpoint...");
112+
// await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint()); // Отключено для избежания конфликтов
113+
114+
console.log("LeetCode extension: Getting login status...");
104115
await leetCodeManager.getLoginStatus();
116+
117+
console.log("LeetCode extension: Registering URI handler...");
105118
vscode.window.registerUriHandler({ handleUri: leetCodeManager.handleUriSignIn });
119+
120+
console.log("LeetCode extension: Activation completed successfully!");
106121
} catch (error) {
122+
console.error("LeetCode extension activation failed:", error);
107123
leetCodeChannel.appendLine(error.toString());
108124
promptForOpenOutputChannel("Extension initialization failed. Please open output channel for details.", DialogType.error);
109125
}

src/leetCodeExecutor.ts

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as path from "path";
88
import requireFromString = require("require-from-string");
99
import { ExtensionContext } from "vscode";
1010
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace, WorkspaceConfiguration } from "vscode";
11-
import { Endpoint, IProblem, leetcodeHasInited, supportedPlugins } from "./shared";
11+
import { IProblem, leetcodeHasInited, supportedPlugins } from "./shared";
1212
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
1313
import { DialogOptions, openUrl } from "./utils/uiUtils";
1414
import * 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
}

src/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export enum Category {
104104
Daily = "Daily",
105105
}
106106

107-
export const supportedPlugins: string[] = ["company", "solution.discuss", "leetcode.cn"];
107+
export const supportedPlugins: string[] = []; // Отключено для избежания конфликтов с оригинальным расширением
108108

109109
export enum DescriptionConfiguration {
110110
InWebView = "In Webview",

src/webview/markdownEngine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import * as hljs from "highlight.js";
5-
import * as MarkdownIt from "markdown-it";
5+
import MarkdownIt from "markdown-it";
66
import * as os from "os";
77
import * as path from "path";
88
import * as vscode from "vscode";
@@ -72,7 +72,7 @@ class MarkdownEngine implements vscode.Disposable {
7272
}
7373

7474
private initEngine(): MarkdownIt {
75-
const md: any = new (MarkdownIt as any)({
75+
const md: MarkdownIt = new MarkdownIt({
7676
linkify: true,
7777
typographer: true,
7878
highlight: (code: string, lang?: string): string => {

0 commit comments

Comments
 (0)