MCPcopy Create free account
hub / github.com/LeetCode-OpenSource/vscode-leetcode / showSolution

Function showSolution

src/commands/show.ts:80–107  ·  view source on GitHub ↗
(input: LeetCodeNode | vscode.Uri)

Source from the content-addressed store, hash-verified

78}
79
80export 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
109async function fetchProblemLanguage(): Promise<string | undefined> {
110 const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");

Callers

nothing calls this directly

Calls 6

getActiveFilePathFunction · 0.90
fetchProblemLanguageFunction · 0.85
showSolutionMethod · 0.80
appendLineMethod · 0.80
showMethod · 0.45

Tested by

no test coverage detected