From b5cd2220707c47711dfcea40445525689ead3649 Mon Sep 17 00:00:00 2001 From: "sheche@microsoft.com" Date: Mon, 13 Aug 2018 20:56:58 +0800 Subject: [PATCH 1/3] support leetcode cn --- package-lock.json | 2 +- package.json | 38 +++++++++++++++++++----- resources/cn.png | Bin 0 -> 4920 bytes src/commands/plugin.ts | 63 ++++++++++++++++++++++++++++++++++++++++ src/extension.ts | 4 +++ src/leetCodeExecutor.ts | 10 +++++++ src/leetCodeManager.ts | 2 +- src/utils/uiUtils.ts | 7 ++++- 8 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 resources/cn.png create mode 100644 src/commands/plugin.ts diff --git a/package-lock.json b/package-lock.json index c428eb2b..fdf86b8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -776,7 +776,7 @@ }, "event-stream": { "version": "3.3.4", - "resolved": "http://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", + "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", "integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=", "dev": true, "requires": { diff --git a/package.json b/package.json index b2a4a853..34f3e5e6 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ ], "preview": true, "activationEvents": [ + "onCommand:leetcode.toogleLeetCodeCn", "onCommand:leetcode.signin", "onCommand:leetcode.signout", "onCommand:leetcode.selectSessions", @@ -39,6 +40,12 @@ "main": "./out/src/extension", "contributes": { "commands": [ + { + "command": "leetcode.toogleLeetCodeCn", + "title": "Switch endpoint", + "category": "LeetCode", + "icon": "resources/cn.png" + }, { "command": "leetcode.signin", "title": "Sign in", @@ -114,19 +121,24 @@ "menus": { "view/title": [ { - "command": "leetcode.signin", + "command": "leetcode.toogleLeetCodeCn", "when": "view == leetCodeExplorer", "group": "navigation@0" }, { - "command": "leetcode.searchProblem", + "command": "leetcode.signin", "when": "view == leetCodeExplorer", "group": "navigation@1" }, { - "command": "leetcode.refreshExplorer", + "command": "leetcode.searchProblem", "when": "view == leetCodeExplorer", "group": "navigation@2" + }, + { + "command": "leetcode.refreshExplorer", + "when": "view == leetCodeExplorer", + "group": "navigation@3" } ], "view/item/context": [ @@ -172,7 +184,7 @@ "leetcode.showLocked": { "type": "boolean", "default": false, - "scope": "window", + "scope": "application", "description": "Show locked problems." }, "leetcode.defaultLanguage": { @@ -193,20 +205,30 @@ "scala", "swift" ], - "scope": "window", + "scope": "application", "description": "Default language for solving the problems." }, "leetcode.showSetDefaultLanguageHint": { "type": "boolean", "default": true, - "scope": "window", + "scope": "application", "description": "Show a hint to set the default language." }, "leetcode.useWsl": { "type": "boolean", "default": false, - "scope": "window", + "scope": "application", "description": "Use Node.js inside the Windows Subsystem for Linux." + }, + "leetcode.endpoint": { + "type": "string", + "default": "leetcode", + "scope": "application", + "enum": [ + "leetcode", + "leetcode.cn" + ], + "description": "Endpoint of the user account." } } } @@ -216,7 +238,7 @@ "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", "watch": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", + "postinstall": "node ./node_modules/vscode/bin/install && node ./node_modules/leetcode-cli/bin/leetcode plugin -d leetcode.cn", "test": "npm run compile && node ./node_modules/vscode/bin/test", "lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose" }, diff --git a/resources/cn.png b/resources/cn.png new file mode 100644 index 0000000000000000000000000000000000000000..4b05c7f26b635a02986eb834b4862426a97f1e7b GIT binary patch literal 4920 zcma)AWmME(wEYd85(?6d(%nc6og$#LAU$+<3?(ywh;)}UNJ=*hh?J5;mr_GWcRc=Y zt@r({bNAkBopbh=`{nL+;o4ftgm_eV000oGswn6@D#L%k!Fps5fB(}*!LXInlmmd; zxWJn?i2#5n1(BE6hFDqxfbV>^uC1Q#4!P9D@+nvy22E0T(ILZO&;iFl^&kbL2|#`X z1*z;Fth5_ez!XMC`OK|*oFu-MDLPWF_5$RG!}e#DO+;^*XqhUgezQZ=<-EG%T--MM zUsjMbpk!X7kP%r9vQi^Eh5_`i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y~y|Nr^o7F*V;RvWIAaJU7p)(|5sv2s7&-N_!U*lUV`2B<|l!}E4Sw^l!$3grm7Hnj#bSDYesRK z``P>W_EUE|nc&4b({6%0msAf-*MZVF^}rq*{RL^pWG62;5A4gE{sOvr)0)78wCnIm zl$qu@dUqgvKj=pbU?9zuho#3(6;7j~Uh6Tp-L)p5K-8tv8~XUX^Z4r-cv`w!fAF;C zwtA%hzM}*M_-cL&*Gvfu;PDI92?#u%8IhVAfyYE4w~hHU$2mjc|C~-PRuCJ%|F84* Som1PR6HryuQm6u(hy4%6Q&zM9 literal 0 HcmV?d00001 diff --git a/src/commands/plugin.ts b/src/commands/plugin.ts new file mode 100644 index 00000000..a0a6ef0e --- /dev/null +++ b/src/commands/plugin.ts @@ -0,0 +1,63 @@ +"use strict"; + +import * as vscode from "vscode"; +import { leetCodeExecutor } from "../leetCodeExecutor"; +import { IQuickItemEx } from "../shared"; +import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils"; + +export async function toogleLeetCodeCn(): Promise { + const isCnEnbaled: boolean = isLeetCodeCnEnabled(); + const picks: Array> = []; + picks.push( + { + label: `${isCnEnbaled ? "$(check) " : ""}On`, + description: "", + detail: "Enable leetcode-cn.", + value: "on", + }, + { + label: `${isCnEnbaled ? "" : "$(check) "}Off`, + description: "", + detail: "Disable leetcode-cn.", + value: "off", + }, + ); + const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(picks); + if (!choice) { + return; + } + const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); + try { + if (choice.value === "on") { + await leetCodeExecutor.toggleLeetCodeCn(true); + await leetCodeConfig.update("endpoint", "leetcode.cn", true /* UserSetting */); + vscode.window.showInformationMessage("Switched the endpoint to leetcode-cn."); + } else { + await leetCodeExecutor.toggleLeetCodeCn(false); + await leetCodeConfig.update("endpoint", "leetcode", true /* UserSetting */); + vscode.window.showInformationMessage("Switched the endpoint to leetcode."); + } + } catch (error) { + await promptForOpenOutputChannel("Failed to switch endpoint. Please open the output channel for details.", DialogType.error); + } + + try { + await vscode.commands.executeCommand("leetcode.signout"); + await promptForSignIn(); + } catch (error) { + await promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details.", DialogType.error); + } +} + +export async function initializeEndpoint(): Promise { + await leetCodeExecutor.toggleLeetCodeCn(isLeetCodeCnEnabled()); +} + +export function isLeetCodeCnEnabled(): boolean { + const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); + const endpoint: string | undefined = leetCodeConfig.get("endpoint"); + if (endpoint && endpoint === "leetcode.cn") { + return true; + } + return false; +} diff --git a/src/extension.ts b/src/extension.ts index 78182b67..e2c59434 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,7 @@ "use strict"; import * as vscode from "vscode"; +import * as plugin from "./commands/plugin"; import * as session from "./commands/session"; import * as show from "./commands/show"; import * as submit from "./commands/submit"; @@ -20,6 +21,7 @@ export async function activate(context: vscode.ExtensionContext): Promise context.subscriptions.push( vscode.window.registerTreeDataProvider("leetCodeExplorer", leetCodeTreeDataProvider), + vscode.commands.registerCommand("leetcode.toogleLeetCodeCn", () => plugin.toogleLeetCodeCn()), vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()), vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()), vscode.commands.registerCommand("leetcode.selectSessions", () => session.selectSession()), @@ -31,6 +33,8 @@ export async function activate(context: vscode.ExtensionContext): Promise vscode.commands.registerCommand("leetcode.submitSolution", (uri?: vscode.Uri) => submit.submitSolution(uri)), ); + await plugin.initializeEndpoint(); + leetCodeManager.on("statusChanged", () => { leetCodeStatusBarItem.updateStatusBar(leetCodeManager.getStatus(), leetCodeManager.getUser()); leetCodeTreeDataProvider.refresh(); diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index 20353c03..ad303704 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -30,6 +30,9 @@ export interface ILeetCodeExecutor { /* section for solution command */ submitSolution(filePath: string): Promise; testSolution(filePath: string, testString?: string): Promise; + + /* section for plugin command */ + toggleLeetCodeCn(isEnable: boolean): Promise; } class LeetCodeExecutor implements ILeetCodeExecutor { @@ -109,6 +112,13 @@ class LeetCodeExecutor implements ILeetCodeExecutor { return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]); } + public async toggleLeetCodeCn(isEnable: boolean): Promise { + if (isEnable) { + return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]); + } + return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]); + } + private async executeCommandEx(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise { if (wsl.useWsl()) { return await executeCommand("wsl", [command].concat(args), options); diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index 24ad4ebc..350698e2 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -109,7 +109,7 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager { this.userStatus = UserStatus.SignedOut; this.emit("statusChanged"); } catch (error) { - promptForOpenOutputChannel("Failed to sign out. Please open the output channel for details", DialogType.error); + // swallow the error when sign out. } } diff --git a/src/utils/uiUtils.ts b/src/utils/uiUtils.ts index d95b7567..9aa9ea9a 100644 --- a/src/utils/uiUtils.ts +++ b/src/utils/uiUtils.ts @@ -5,6 +5,7 @@ import * as opn from "opn"; import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; +import { isLeetCodeCnEnabled } from "../commands/plugin"; import { leetCodeChannel } from "../leetCodeChannel"; export namespace DialogOptions { @@ -48,7 +49,11 @@ export async function promptForSignIn(): Promise { await vscode.commands.executeCommand("leetcode.signin"); break; case DialogOptions.singUp: - opn("https://leetcode.com"); + if (isLeetCodeCnEnabled()) { + opn("https://leetcode-cn.com"); + } else { + opn("https://leetcode.com"); + } break; default: break; From 1d9e6f4d8c483c9149566e4fdc29ec6673f4b831 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Tue, 14 Aug 2018 15:47:58 +0800 Subject: [PATCH 2/3] refine code --- package.json | 2 +- src/commands/plugin.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 34f3e5e6..84358368 100644 --- a/package.json +++ b/package.json @@ -238,7 +238,7 @@ "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", "watch": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install && node ./node_modules/leetcode-cli/bin/leetcode plugin -d leetcode.cn", + "postinstall": "node ./node_modules/vscode/bin/install && node ./node_modules/leetcode-cli/bin/leetcode plugin -i leetcode.cn", "test": "npm run compile && node ./node_modules/vscode/bin/test", "lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose" }, diff --git a/src/commands/plugin.ts b/src/commands/plugin.ts index a0a6ef0e..9a84dfb1 100644 --- a/src/commands/plugin.ts +++ b/src/commands/plugin.ts @@ -28,15 +28,11 @@ export async function toogleLeetCodeCn(): Promise { } const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); try { - if (choice.value === "on") { - await leetCodeExecutor.toggleLeetCodeCn(true); - await leetCodeConfig.update("endpoint", "leetcode.cn", true /* UserSetting */); - vscode.window.showInformationMessage("Switched the endpoint to leetcode-cn."); - } else { - await leetCodeExecutor.toggleLeetCodeCn(false); - await leetCodeConfig.update("endpoint", "leetcode", true /* UserSetting */); - vscode.window.showInformationMessage("Switched the endpoint to leetcode."); - } + const enabled: boolean = choice.value === "on"; + const endpoint: string = enabled ? "leetcode.cn" : "leetcode"; + await leetCodeExecutor.toggleLeetCodeCn(enabled); + await leetCodeConfig.update("endpoint", endpoint, true /* UserSetting */); + vscode.window.showInformationMessage(`Switched the endpoint to ${endpoint}`); } catch (error) { await promptForOpenOutputChannel("Failed to switch endpoint. Please open the output channel for details.", DialogType.error); } From a7135b61c3394143c29dd86c2211514b78bc533a Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Tue, 14 Aug 2018 15:53:36 +0800 Subject: [PATCH 3/3] refine code --- package.json | 2 +- src/commands/plugin.ts | 9 +++++---- src/shared.ts | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 84358368..b582ecb8 100644 --- a/package.json +++ b/package.json @@ -226,7 +226,7 @@ "scope": "application", "enum": [ "leetcode", - "leetcode.cn" + "leetcode-cn" ], "description": "Endpoint of the user account." } diff --git a/src/commands/plugin.ts b/src/commands/plugin.ts index 9a84dfb1..c904728f 100644 --- a/src/commands/plugin.ts +++ b/src/commands/plugin.ts @@ -3,6 +3,7 @@ import * as vscode from "vscode"; import { leetCodeExecutor } from "../leetCodeExecutor"; import { IQuickItemEx } from "../shared"; +import { Endpoint } from "../shared"; import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils"; export async function toogleLeetCodeCn(): Promise { @@ -12,13 +13,13 @@ export async function toogleLeetCodeCn(): Promise { { label: `${isCnEnbaled ? "$(check) " : ""}On`, description: "", - detail: "Enable leetcode-cn.", + detail: `Enable ${Endpoint.LeetCodeCN}.`, value: "on", }, { label: `${isCnEnbaled ? "" : "$(check) "}Off`, description: "", - detail: "Disable leetcode-cn.", + detail: `Disable ${Endpoint.LeetCodeCN}.`, value: "off", }, ); @@ -29,7 +30,7 @@ export async function toogleLeetCodeCn(): Promise { const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); try { const enabled: boolean = choice.value === "on"; - const endpoint: string = enabled ? "leetcode.cn" : "leetcode"; + const endpoint: string = enabled ? Endpoint.LeetCodeCN : Endpoint.LeetCode; await leetCodeExecutor.toggleLeetCodeCn(enabled); await leetCodeConfig.update("endpoint", endpoint, true /* UserSetting */); vscode.window.showInformationMessage(`Switched the endpoint to ${endpoint}`); @@ -52,7 +53,7 @@ export async function initializeEndpoint(): Promise { export function isLeetCodeCnEnabled(): boolean { const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); const endpoint: string | undefined = leetCodeConfig.get("endpoint"); - if (endpoint && endpoint === "leetcode.cn") { + if (endpoint && endpoint === Endpoint.LeetCodeCN) { return true; } return false; diff --git a/src/shared.ts b/src/shared.ts index 9a5184ee..3a702452 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -33,3 +33,8 @@ export enum ProblemState { NotAC = 2, Unknown = 3, } + +export enum Endpoint { + LeetCode = "leetcode", + LeetCodeCN = "leetcode-cn", +}