()
| 10 | import { deleteCache } from "./cache"; |
| 11 | |
| 12 | export 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 | |
| 52 | export function getLeetCodeEndpoint(): string { |
| 53 | const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); |
nothing calls this directly
no test coverage detected