Skip to content
Prev Previous commit
Next Next commit
minor changes
  • Loading branch information
su-mt committed Jul 3, 2025
commit 4fe1a11cca0032a8ed179060085d56e108801db3
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
{
"name": "vscode-leetcode-fork",
"displayName": "LeetCode-fork",
"description": "Solve LeetCode problems in VS Code",
"name": "vscode-leetcode",
"displayName": "LeetCode Enhanced Fork",
"description": "Enhanced fork of LeetCode VS Code extension with Daily Challenges and improved functionality",
"version": "0.18.5",
"author": "su-mt",
"publisher": "su-mt",
"publisher": "leetcode",
"license": "MIT",
"icon": "resources/LeetCode.png",
"engines": {
"vscode": "^1.57.0"
},
"repository": {
"type": "git",
"url": "https://github.com/LeetCode-OpenSource/vscode-leetcode"
"url": "https://github.com/su-mt/vscode-leetcode"
},
"homepage": "https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/README.md",
"homepage": "https://github.com/su-mt/vscode-leetcode/blob/feature/daily-challenges/README.md",
"categories": [
"Other",
"Snippets"
"Education",
"Other"
],
"keywords": [
"leetcode",
"leetcode-enhanced",
"coding-practice",
"algorithm",
"interview"
"interview",
"daily-challenges"
],
"preview": true,
"activationEvents": [
Expand Down
18 changes: 17 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,25 @@ import { globalState } from "./globalState";

export async function activate(context: vscode.ExtensionContext): Promise<void> {
try {
console.log("LeetCode extension: Starting activation...");

if (!(await leetCodeExecutor.meetRequirements(context))) {
console.error("LeetCode extension: Environment doesn't meet requirements");
throw new Error("The environment doesn't meet requirements.");
}

console.log("LeetCode extension: Requirements met, setting up event handlers...");

leetCodeManager.on("statusChanged", () => {
leetCodeStatusBarController.updateStatusBar(leetCodeManager.getStatus(), leetCodeManager.getUser());
leetCodeTreeDataProvider.refresh();
});

console.log("LeetCode extension: Initializing providers...");
leetCodeTreeDataProvider.initialize(context);
globalState.initialize(context);

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

await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint());
console.log("LeetCode extension: All commands registered successfully");
console.log("LeetCode extension: Switching endpoint...");
// await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint()); // ΠžΡ‚ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΎ для избСТания ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΠΎΠ²

console.log("LeetCode extension: Getting login status...");
await leetCodeManager.getLoginStatus();

console.log("LeetCode extension: Registering URI handler...");
vscode.window.registerUriHandler({ handleUri: leetCodeManager.handleUriSignIn });

console.log("LeetCode extension: Activation completed successfully!");
} catch (error) {
console.error("LeetCode extension activation failed:", error);
leetCodeChannel.appendLine(error.toString());
promptForOpenOutputChannel("Extension initialization failed. Please open output channel for details.", DialogType.error);
}
Expand Down
67 changes: 45 additions & 22 deletions src/leetCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from "path";
import requireFromString = require("require-from-string");
import { ExtensionContext } from "vscode";
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace, WorkspaceConfiguration } from "vscode";
import { Endpoint, IProblem, leetcodeHasInited, supportedPlugins } from "./shared";
import { IProblem, leetcodeHasInited, supportedPlugins } from "./shared";
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
import { DialogOptions, openUrl } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
Expand Down Expand Up @@ -37,12 +37,18 @@ class LeetCodeExecutor implements Disposable {
}

public async meetRequirements(context: ExtensionContext): Promise<boolean> {
console.log("LeetCode: Checking requirements...");

const hasInited: boolean | undefined = context.globalState.get(leetcodeHasInited);
if (!hasInited) {
console.log("LeetCode: Extension not initialized, removing old cache...");
await this.removeOldCache();
}

console.log("LeetCode: Node executable path:", this.nodeExecutable);
if (this.nodeExecutable !== "node") {
if (!await fse.pathExists(this.nodeExecutable)) {
console.error("LeetCode: Node.js executable not found at:", this.nodeExecutable);
throw new Error(`The Node.js executable does not exist on path ${this.nodeExecutable}`);
}
// Wrap the executable with "" to avoid space issue in the path.
Expand All @@ -51,9 +57,13 @@ class LeetCodeExecutor implements Disposable {
this.nodeExecutable = await toWslPath(this.nodeExecutable);
}
}

console.log("LeetCode: Testing Node.js...");
try {
await this.executeCommandEx(this.nodeExecutable, ["-v"]);
console.log("LeetCode: Node.js test successful");
} catch (error) {
console.error("LeetCode: Node.js test failed:", error);
const choice: MessageItem | undefined = await window.showErrorMessage(
"LeetCode extension needs Node.js installed in environment path",
DialogOptions.open,
Expand All @@ -63,16 +73,24 @@ class LeetCodeExecutor implements Disposable {
}
return false;
}

console.log("LeetCode: Checking plugins...");
for (const plugin of supportedPlugins) {
console.log("LeetCode: Checking plugin:", plugin);
try { // Check plugin
await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", plugin]);
console.log("LeetCode: Plugin", plugin, "is available");
} catch (error) { // Remove old cache that may cause the error download plugin and activate
await this.removeOldCache();
await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-i", plugin]);
console.log("LeetCode: Plugin", plugin, "not found, installing...");
// await this.removeOldCache();
// await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-i", plugin]);
console.log("LeetCode: Plugin", plugin, "installed successfully");
}
}

// Set the global state HasInited true to skip delete old cache after init
context.globalState.update(leetcodeHasInited, true);
console.log("LeetCode: Requirements check completed successfully");
return true;
}

Expand Down Expand Up @@ -111,13 +129,13 @@ class LeetCodeExecutor implements Disposable {
if (!await fse.pathExists(filePath)) {
await fse.createFile(filePath);
let codeTemplate: string = await this.executeCommandWithProgressEx("Fetching problem data...", this.nodeExecutable, cmd);

// Add C++ headers if needed
if (shouldAddHeaders && (language === "cpp" || language === "c")) {
const cppHeaders = this.generateCppHeaders();
codeTemplate = cppHeaders + codeTemplate;
}

await fse.writeFile(filePath, codeTemplate);
}
}
Expand Down Expand Up @@ -187,14 +205,19 @@ class LeetCodeExecutor implements Disposable {
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]);
}

public async switchEndpoint(endpoint: string): Promise<string> {
public async switchEndpoint(_endpoint: string): Promise<string> {
// ΠžΡ‚ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΎ для избСТания ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΠΎΠ² с ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹ΠΌ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ΠΌ
console.log("LeetCode: Endpoint switching disabled to avoid conflicts");
return "Endpoint switching disabled";
/*
switch (endpoint) {
case Endpoint.LeetCodeCN:
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
case Endpoint.LeetCode:
default:
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]);
}
*/
}

public async toggleFavorite(node: IProblem, addToFavorite: boolean): Promise<void> {
Expand Down Expand Up @@ -261,16 +284,16 @@ class LeetCodeExecutor implements Disposable {
return [];
}
}

public async getDailyChallengeHistory(_needTranslation?: boolean, days: number = 30): Promise<any[]> {
try {
const https = require('https');

// ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ Π΄Π°Π½Π½Ρ‹Π΅ Π·Π° послСдниС Π΄Π½ΠΈ
const endDate = new Date();
const startDate = new Date();
startDate.setDate(endDate.getDate() - days);

const query = `
query dailyCodingQuestionRecords($year: Int!, $month: Int!) {
dailyCodingChallengeV2(year: $year, month: $month) {
Expand Down Expand Up @@ -300,27 +323,27 @@ class LeetCodeExecutor implements Disposable {
}
}
`;

const challenges: any[] = [];
const processedMonths = new Set<string>();

// ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ Π΄Π°Π½Π½Ρ‹Π΅ для Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ ΠΈ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅Π³ΠΎ мСсяца
for (let i = 0; i <= 1; i++) {
const targetDate = new Date();
targetDate.setMonth(targetDate.getMonth() - i);

const year = targetDate.getFullYear();
const month = targetDate.getMonth() + 1;
const monthKey = `${year}-${month}`;

if (processedMonths.has(monthKey)) continue;
processedMonths.add(monthKey);

const postData = JSON.stringify({
query: query,
variables: { year, month }
});

const options = {
hostname: 'leetcode.com',
port: 443,
Expand All @@ -332,7 +355,7 @@ class LeetCodeExecutor implements Disposable {
'User-Agent': 'vscode-leetcode-extension'
}
};

const response = await new Promise<string>((resolve, reject) => {
const req = https.request(options, (res: any) => {
let data = '';
Expand All @@ -343,15 +366,15 @@ class LeetCodeExecutor implements Disposable {
resolve(data);
});
});

req.on('error', (error: any) => {
reject(error);
});

req.write(postData);
req.end();
});

const jsonData = JSON.parse(response);
if (jsonData.data && jsonData.data.dailyCodingChallengeV2 && jsonData.data.dailyCodingChallengeV2.challenges) {
const monthChallenges = jsonData.data.dailyCodingChallengeV2.challenges
Expand All @@ -372,14 +395,14 @@ class LeetCodeExecutor implements Disposable {
link: challenge.link
};
});

challenges.push(...monthChallenges);
}
}

// Π‘ΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠΎ Π΄Π°Ρ‚Π΅ (Π½ΠΎΠ²Ρ‹Π΅ свСрху)
challenges.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());

// ΠžΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΠ²Π°Π΅ΠΌ количСство Π΄Π½Π΅ΠΉ
return challenges.slice(0, days);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export enum Category {
Daily = "Daily",
}

export const supportedPlugins: string[] = ["company", "solution.discuss", "leetcode.cn"];
export const supportedPlugins: string[] = []; // ΠžΡ‚ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΎ для избСТания ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΠΎΠ² с ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹ΠΌ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ΠΌ

export enum DescriptionConfiguration {
InWebView = "In Webview",
Expand Down
4 changes: 2 additions & 2 deletions src/webview/markdownEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import * as hljs from "highlight.js";
import * as MarkdownIt from "markdown-it";
import MarkdownIt from "markdown-it";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
Expand Down Expand Up @@ -72,7 +72,7 @@ class MarkdownEngine implements vscode.Disposable {
}

private initEngine(): MarkdownIt {
const md: any = new (MarkdownIt as any)({
const md: MarkdownIt = new MarkdownIt({
linkify: true,
typographer: true,
highlight: (code: string, lang?: string): string => {
Expand Down