(input: LeetCodeNode | vscode.Uri)
| 78 | } |
| 79 | |
| 80 | export async function showSolution(input: LeetCodeNode | vscode.Uri): Promise<void> { |
| 81 | let problemInput: string | undefined; |
| 82 | if (input instanceof LeetCodeNode) { // Triggerred from explorer |
| 83 | problemInput = input.id; |
| 84 | } else if (input instanceof vscode.Uri) { // Triggerred from Code Lens/context menu |
| 85 | problemInput = `"${input.fsPath}"`; |
| 86 | } else if (!input) { // Triggerred from command |
| 87 | problemInput = await getActiveFilePath(); |
| 88 | } |
| 89 | |
| 90 | if (!problemInput) { |
| 91 | vscode.window.showErrorMessage("Invalid input to fetch the solution data."); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | const language: string | undefined = await fetchProblemLanguage(); |
| 96 | if (!language) { |
| 97 | return; |
| 98 | } |
| 99 | try { |
| 100 | const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation(); |
| 101 | const solution: string = await leetCodeExecutor.showSolution(problemInput, language, needTranslation); |
| 102 | leetCodeSolutionProvider.show(unescapeJS(solution)); |
| 103 | } catch (error) { |
| 104 | leetCodeChannel.appendLine(error.toString()); |
| 105 | await promptForOpenOutputChannel("Failed to fetch the top voted solution. Please open the output channel for details.", DialogType.error); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | async function fetchProblemLanguage(): Promise<string | undefined> { |
| 110 | const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); |
nothing calls this directly
no test coverage detected