Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve the experience of switch endpoint#92

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 2 commits intomasterfromcs/switch-endpoint
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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
28 changes: 17 additions & 11 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,37 +43,40 @@
"commands": [
{
"command": "leetcode.deleteCache",
"title": "Deletecache",
"title": "DeleteCache",
"category": "LeetCode"
},
{
"command": "leetcode.toogleLeetCodeCn",
"title": "Switchendpoint",
"title": "SwitchEndpoint",
"category": "LeetCode",
"icon": "resources/cn.png"
"icon": {
"light": "resources/light/endpoint.svg",
"dark": "resources/dark/endpoint.svg"
}
},
{
"command": "leetcode.signin",
"title": "Signin",
"title": "SignIn",
"category": "LeetCode",
"icon": {
"light": "resources/light/signin.png",
"dark": "resources/dark/signin.png"
"light": "resources/light/signin.svg",
"dark": "resources/dark/signin.svg"
}
},
{
"command": "leetcode.signout",
"title": "Signout",
"title": "SignOut",
"category": "LeetCode"
},
{
"command": "leetcode.selectSessions",
"title": "Selectsession",
"title": "SelectSession",
"category": "LeetCode"
},
{
"command": "leetcode.createSession",
"title": "Createnew session",
"title": "CreateNew Session",
"category": "LeetCode"
},
{
Expand All@@ -87,14 +90,17 @@
},
{
"command": "leetcode.showProblem",
"title": "Showproblem",
"title": "ShowProblem",
"category": "LeetCode"
},
{
"command": "leetcode.searchProblem",
"title": "Search Problem",
"category": "LeetCode",
"icon": "resources/search.png"
"icon": {
"light": "resources/light/search.svg",
"dark": "resources/dark/search.svg"
}
},
{
"command": "leetcode.testSolution",
Expand Down
Binary file removedresources/cn.png
View file
Open in desktop
Binary file not shown.
6 changes: 6 additions & 0 deletionsresources/dark/endpoint.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletionresources/dark/refresh.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletionsresources/dark/search.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removedresources/dark/signin.png
View file
Open in desktop
Binary file not shown.
7 changes: 7 additions & 0 deletionsresources/dark/signin.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletionsresources/light/endpoint.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletionresources/light/refresh.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletionsresources/light/search.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removedresources/light/signin.png
View file
Open in desktop
Binary file not shown.
7 changes: 7 additions & 0 deletionsresources/light/signin.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removedresources/search.png
View file
Open in desktop
Binary file not shown.
54 changes: 14 additions & 40 deletionssrc/commands/plugin.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import * as fse from "fs-extra";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { IQuickItemEx } from "../shared";
import { Endpoint } from "../shared";
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { deleteCache } from "./cache";

export async functiontoogleLeetCodeCn(): Promise<void> {
const isCnEnbaled: boolean =isLeetCodeCnEnabled();
export async functionswitchEndpoint(): Promise<void> {
const isCnEnbaled: boolean =getLeetCodeEndpoint() === Endpoint.LeetCodeCN;
const picks: Array<IQuickItemEx<string>> = [];
picks.push(
{
label: `${isCnEnbaled ? "$(check) " : ""}On`,
description: "",
detail: `Enable${Endpoint.LeetCodeCN}.`,
value:"on",
label: `${isCnEnbaled ? "" : "$(check) "}LeetCode`,
description: "leetcode.com",
detail: `EnableLeetCode US`,
value:Endpoint.LeetCode,
},
{
label: `${isCnEnbaled ? "" : "$(check) "}Off`,
description: "",
detail: `Disable ${Endpoint.LeetCodeCN}.`,
value:"off",
label: `${isCnEnbaled ? "$(check) " : ""}力扣`,
description: "leetcode-cn.com",
detail: `启用中国版 LeetCode`,
value:Endpoint.LeetCodeCN,
},
);
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
Expand All@@ -34,9 +31,8 @@ export async function toogleLeetCodeCn(): Promise<void> {
}
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
try {
const enabled: boolean = choice.value === "on";
const endpoint: string = enabled ? Endpoint.LeetCodeCN : Endpoint.LeetCode;
await leetCodeExecutor.toggleLeetCodeCn(enabled);
const endpoint: string = choice.value;
await leetCodeExecutor.switchEndpoint(endpoint);
await leetCodeConfig.update("endpoint", endpoint, true /* UserSetting */);
vscode.window.showInformationMessage(`Switched the endpoint to ${endpoint}`);
} catch (error) {
Expand All@@ -52,29 +48,7 @@ export async function toogleLeetCodeCn(): Promise<void> {
}
}

export async function initializeEndpoint(): Promise<void> {
const isCnEnabledInExtension: boolean = isLeetCodeCnEnabled();
const isCnEnabledInCli: boolean = await isLeetCodeCnEnabledInCli();
await leetCodeExecutor.toggleLeetCodeCn(isCnEnabledInExtension);
if (isCnEnabledInCli !== isCnEnabledInExtension) {
await deleteCache();
}
}

export function isLeetCodeCnEnabled(): boolean {
export function getLeetCodeEndpoint(): string {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
const endpoint: string | undefined = leetCodeConfig.get<string>("endpoint");
if (endpoint && endpoint === Endpoint.LeetCodeCN) {
return true;
}
return false;
}

async function isLeetCodeCnEnabledInCli(): Promise<boolean> {
const pluginsStatusFile: string = path.join(os.homedir(), ".lc", "plugins.json");
if (!await fse.pathExists(pluginsStatusFile)) {
return false;
}
const pluginsObj: {} = await fse.readJson(pluginsStatusFile);
return pluginsObj["leetcode.cn"];
return leetCodeConfig.get<string>("endpoint", Endpoint.LeetCode);
}
4 changes: 2 additions & 2 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.window.registerTreeDataProvider("leetCodeExplorer", leetCodeTreeDataProvider),
vscode.languages.registerCodeLensProvider({ scheme: "file" }, codeLensProvider),
vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()),
vscode.commands.registerCommand("leetcode.toogleLeetCodeCn", () => plugin.toogleLeetCodeCn()),
vscode.commands.registerCommand("leetcode.toogleLeetCodeCn", () => plugin.switchEndpoint()),
vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()),
vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()),
vscode.commands.registerCommand("leetcode.selectSessions", () => session.selectSession()),
Expand All@@ -48,7 +48,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.submitSolution", (uri?: vscode.Uri) => submit.submitSolution(uri)),
);

await plugin.initializeEndpoint();
awaitleetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint());
leetCodeManager.getLoginStatus();
}

Expand Down
12 changes: 8 additions & 4 deletionssrc/leetCodeExecutor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
import * as cp from "child_process";
import * as path from "path";
import * as vscode from "vscode";
import { Endpoint } from "./shared";
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
import { DialogOptions, openUrl } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
Expand DownExpand Up@@ -89,11 +90,14 @@ class LeetCodeExecutor {
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]);
}

public async toggleLeetCodeCn(isEnable: boolean): Promise<string> {
if (isEnable) {
return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
public async switchEndpoint(endpoint: string): Promise<string> {
switch (endpoint) {
case Endpoint.LeetCodeCN:
return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
case Endpoint.LeetCode:
default:
return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-d", "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<string> {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp