MCPcopy Index your code
hub / github.com/LeetCode-OpenSource/vscode-leetcode / switchEndpoint

Function switchEndpoint

src/commands/plugin.ts:12–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10import { deleteCache } from "./cache";
11
12export async function switchEndpoint(): Promise<void> {
13 const isCnEnabled: boolean = getLeetCodeEndpoint() === Endpoint.LeetCodeCN;
14 const picks: Array<IQuickItemEx<string>> = [];
15 picks.push(
16 {
17 label: `${isCnEnabled ? "" : "$(check) "}LeetCode`,
18 description: "leetcode.com",
19 detail: `Enable LeetCode US`,
20 value: Endpoint.LeetCode,
21 },
22 {
23 label: `${isCnEnabled ? "$(check) " : ""}力扣`,
24 description: "leetcode.cn",
25 detail: `启用中国版 LeetCode`,
26 value: Endpoint.LeetCodeCN,
27 },
28 );
29 const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
30 if (!choice || choice.value === getLeetCodeEndpoint()) {
31 return;
32 }
33 const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
34 try {
35 const endpoint: string = choice.value;
36 await leetCodeExecutor.switchEndpoint(endpoint);
37 await leetCodeConfig.update("endpoint", endpoint, true /* UserSetting */);
38 vscode.window.showInformationMessage(`Switched the endpoint to ${endpoint}`);
39 } catch (error) {
40 await promptForOpenOutputChannel("Failed to switch endpoint. Please open the output channel for details.", DialogType.error);
41 }
42
43 try {
44 await vscode.commands.executeCommand("leetcode.signout");
45 await deleteCache();
46 await promptForSignIn();
47 } catch (error) {
48 await promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details.", DialogType.error);
49 }
50}
51
52export function getLeetCodeEndpoint(): string {
53 const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");

Callers

nothing calls this directly

Calls 5

deleteCacheFunction · 0.90
promptForSignInFunction · 0.90
getLeetCodeEndpointFunction · 0.85
switchEndpointMethod · 0.80

Tested by

no test coverage detected