Skip to content

feat: Add support for Cursor editor authentication #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/leetCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as cp from "child_process";
import * as fse from "fs-extra";
import * as os from "os";
import * as path from "path";
import * as requireFromString from "require-from-string";
import requireFromString from "require-from-string";
import { ExtensionContext } from "vscode";
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace, WorkspaceConfiguration } from "vscode";
import { Endpoint, IProblem, leetcodeHasInited, supportedPlugins } from "./shared";
Expand Down
28 changes: 25 additions & 3 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,37 @@ export enum SortingStrategy {
export const PREMIUM_URL_CN = "https://leetcode.cn/premium-payment/?source=vscode";
export const PREMIUM_URL_GLOBAL = "https://leetcode.com/subscribe/?ref=lp_pl&source=vscode";

const protocol = vscode.env.appName.includes('Insiders') ? "vscode-insiders" : "vscode"
// 检测当前编辑器环境并返回对应的协议和扩展标识
const getEditorInfo = () => {
const appName = vscode.env.appName;
if (appName.includes('Cursor')) {
return {
protocol: "cursor",
extensionId: "leetcode.vscode-leetcode" // Cursor 兼容 VSCode 扩展标识
};
} else if (appName.includes('Insiders')) {
return {
protocol: "vscode-insiders",
extensionId: "leetcode.vscode-leetcode"
};
} else {
return {
protocol: "vscode",
extensionId: "leetcode.vscode-leetcode"
};
}
};

const editorInfo = getEditorInfo();
const protocol = editorInfo.protocol;

export const urls = {
// base urls
base: "https://leetcode.com",
graphql: "https://leetcode.com/graphql",
userGraphql: "https://leetcode.com/graphql",
login: "https://leetcode.com/accounts/login/",
authLoginUrl: `https://leetcode.com/authorize-login/${protocol}/?path=leetcode.vscode-leetcode`,
authLoginUrl: `https://leetcode.com/authorize-login/${protocol}/?path=${editorInfo.extensionId}`,
};

export const urlsCn = {
Expand All @@ -142,7 +164,7 @@ export const urlsCn = {
graphql: "https://leetcode.cn/graphql",
userGraphql: "https://leetcode.cn/graphql/",
login: "https://leetcode.cn/accounts/login/",
authLoginUrl: `https://leetcode.cn/authorize-login/${protocol}/?path=leetcode.vscode-leetcode`,
authLoginUrl: `https://leetcode.cn/authorize-login/${protocol}/?path=${editorInfo.extensionId}`,
};

export const getUrl = (key: string) => {
Expand Down
2 changes: 1 addition & 1 deletion 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
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"noImplicitReturns": true,
"strictNullChecks": true,
"noUnusedParameters": true,
"alwaysStrict": true
"alwaysStrict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"exclude": [
"node_modules",
Expand Down