Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 23e5247

Browse files
committed
Revert solution part
1 parent c230f75 commit 23e5247

File tree

5 files changed

+23
-37
lines changed

5 files changed

+23
-37
lines changed

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,13 @@
218218
"command": "leetcode.previewProblem",
219219
"group": "leetcode@1"
220220
},
221-
{
222-
"command": "leetcode.showSolution",
223-
"group": "leetcode@2"
224-
},
225221
{
226222
"command": "leetcode.testSolution",
227-
"group": "leetcode@3"
223+
"group": "leetcode@2"
228224
},
229225
{
230226
"command": "leetcode.submitSolution",
231-
"group": "leetcode@4"
227+
"group": "leetcode@3"
232228
}
233229
]
234230
},

src/codelens/CustomCodeLensProvider.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
2525
title: "Test",
2626
command: "leetcode.testSolution",
2727
}),
28-
new vscode.CodeLens(range, {
29-
title: "Solution",
30-
command: "leetcode.showSolution",
31-
}),
3228
new vscode.CodeLens(range, {
3329
title: "Description",
3430
command: "leetcode.previewProblem",

src/commands/show.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,6 @@ export async function previewProblem(source: IProblem | vscode.Uri | undefined,
3939
}
4040
}
4141

42-
export async function showSolution(source: IProblem | vscode.Uri | undefined): Promise<void> {
43-
try {
44-
let problem: IProblem;
45-
let solutionString: string;
46-
if (source && "difficulty" in source) {
47-
problem = source;
48-
solutionString = await leetCodeExecutor.showSolution(problem.id, await fetchProblemLanguage());
49-
} else {
50-
const filename: string = (await getActiveFilePath(source))!;
51-
const [meta] = splitMetaOutput(await leetCodeExecutor.getDescription(filename));
52-
problem = leetCodeTreeDataProvider.getProblem(meta.id)!;
53-
solutionString = await leetCodeExecutor.showSolution(meta.id, meta.lang);
54-
}
55-
leetCodeSolutionProvider.show(unescapeJS(solutionString), problem);
56-
} catch (error) {
57-
leetCodeChannel.appendLine(error.toString());
58-
await promptForOpenOutputChannel("Failed to fetch the top voted solution. Please open the output channel for details.", DialogType.error);
59-
}
60-
}
61-
6242
export async function showProblem(node?: LeetCodeNode): Promise<void> {
6343
if (!node) {
6444
return;
@@ -84,6 +64,24 @@ export async function searchProblem(): Promise<void> {
8464
await showProblemInternal(choice.value);
8565
}
8666

67+
export async function showSolution(node?: LeetCodeNode): Promise<void> {
68+
if (!node) {
69+
return;
70+
}
71+
const language: string | undefined = await fetchProblemLanguage();
72+
if (!language) {
73+
return;
74+
}
75+
try {
76+
let solution: string = await leetCodeExecutor.showSolution(node, language);
77+
// remove backslash in espaced \'...\'(generated by leetcode's database)
78+
solution = solution.replace(/\\'/g, "'");
79+
await leetCodeSolutionProvider.show(solution, node);
80+
} catch (error) {
81+
await promptForOpenOutputChannel("Failed to fetch the top voted solution. Please open the output channel for details.", DialogType.error);
82+
}
83+
}
84+
8785
// SUGGESTION: group config retriving into one file
8886
async function fetchProblemLanguage(): Promise<string | undefined> {
8987
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
5555
vscode.commands.registerCommand("leetcode.previewProblem", (source: IProblem | vscode.Uri) => show.previewProblem(source)),
5656
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
5757
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
58-
vscode.commands.registerCommand("leetcode.showSolution", (source: IProblem | vscode.Uri) => show.showSolution(source)),
58+
vscode.commands.registerCommand("leetcode.showSolution", (node: IProblem) => show.showSolution(node)),
5959
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
6060
vscode.commands.registerCommand("leetcode.testSolution", (uri?: vscode.Uri) => test.testSolution(uri)),
6161
vscode.commands.registerCommand("leetcode.submitSolution", (uri?: vscode.Uri) => submit.submitSolution(uri)),

src/leetCodeExecutor.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ class LeetCodeExecutor implements Disposable {
106106
return filePath;
107107
}
108108

109-
public async showSolution(keyword: string, language?: string): Promise<string> {
110-
const args: string[] = [await this.getLeetCodeBinaryPath(), "show", keyword, "--solution"];
111-
if (language) {
112-
args.push("-l", language);
113-
}
114-
const solution: string = await this.executeCommandWithProgressEx("Fetching top voted solution from discussions...", this.nodeExecutable, args);
109+
public async showSolution(problemNode: IProblem, language: string): Promise<string> {
110+
const solution: string = await this.executeCommandWithProgressEx("Fetching top voted solution from discussions...", "node", [await this.getLeetCodeBinaryPath(), "show", problemNode.id, "--solution", "-l", language]);
115111
return solution;
116112
}
117113

0 commit comments

Comments
 (0)