- Notifications
You must be signed in to change notification settings - Fork669
feat: Add 'show solution' in editor context menu & code lens#313
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -47,17 +47,24 @@ export async function searchProblem(): Promise<void> { | ||
await showProblemInternal(choice.value); | ||
} | ||
export async function showSolution(input: LeetCodeNode | vscode.Uri): Promise<void> { | ||
let problemInput: string | undefined; | ||
if (input instanceof LeetCodeNode) { | ||
problemInput = input.id; | ||
} else if (input instanceof vscode.Uri) { | ||
problemInput = `"${input.fsPath}"`; | ||
} else { | ||
vscode.window.showErrorMessage("Invalid input to fetch the solution data"); | ||
return; | ||
} | ||
const language: string | undefined = await fetchProblemLanguage(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We could utilize file extension ( exportconstlangExt:Map<string,string>=newMap([["bash","sh"],["c","c"],["cpp","cpp"],["csharp","cs"],["golang","go"],["java","java"],["javascript","js"],["kotlin","kt"],["mysql","sql"],["php","php"],["python","py"],["python3","py"],["ruby","rb"],["rust","rs"],["scala","scala"],["swift","swift"],]); (Yet this choice comes with a risk: currently showing solution for languages like scala has a high probability to fail. This feature could be added in later PR when logic of solution plugin is improved.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. another rick is that it's hard to differentiate py3 & py2 from the | ||
if (!language) { | ||
return; | ||
} | ||
try { | ||
const solution: string = await leetCodeExecutor.showSolution(problemInput, language); | ||
leetCodeSolutionProvider.show(unescapeJS(solution)); | ||
} catch (error) { | ||
leetCodeChannel.appendLine(error.toString()); | ||
await promptForOpenOutputChannel("Failed to fetch the top voted solution. Please open the output channel for details.", DialogType.error); | ||
@@ -133,8 +140,6 @@ async function showProblemInternal(node: IProblem): Promise<void> { | ||
async function movePreviewAsideIfNeeded(node: IProblem): Promise<void> { | ||
if (vscode.workspace.getConfiguration("leetcode").get<boolean>("enableSideMode", true)) { | ||
return previewProblem(node, true); | ||
} | ||
} | ||