8000 Better config how to show the problem description (#519) · aghao/vscode-leetcode@ac9df4d · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac9df4d

Browse files
authored
Better config how to show the problem description (LeetCode-OpenSource#519)
1 parent d160d1f commit ac9df4d

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

package.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,28 @@
300300
"scope": "application",
301301
"description": "Default language for solving the problems."
302302
},
303+
"leetcode.showDescription": {
304+
"type": "string",
305+
"default": "In Webview",
306+
"enum": [
307+
"In Webview",
308+
"In File Comment",
309+
"Both",
310+
"None"
311+
],
312+
"enumDescriptions": [
313+
"Show the problem description in a new webview window",
314+
"Show the problem description in the file's comment"
315+
],
316+
"scope": "application",
317+
"description": "Specify where to show the description."
318+
},
303319
"leetcode.showCommentDescription": {
304320
"type": "boolean",
305321
"default": false,
306322
"scope": "application",
307-
"description": "Include problem description in comments."
323+
"description": "[Deprecated] Include problem description in comments.",
324+
"deprecation 8000 Message": "This setting will be deprecated in 0.17.0, please use 'leetcode.showDescription' instead"
308325
},
309326
"leetcode.hint.setDefaultLanguage": {
310327
"type": "boolean",

src/commands/show.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { leetCodeExecutor } from "../leetCodeExecutor";
1212
import { leetCodeManager } from "../leetCodeManager";
1313
import { IProblem, IQuickItemEx, languages, ProblemState } from "../shared";
1414
import { genFileExt, genFileName, getNodeIdFromFile } from "../utils/problemUtils";
15+
import * as settingUtils from "../utils/settingUtils";
16+
import { IDescriptionConfiguration } from "../utils/settingUtils";
1517
import { DialogOptions, DialogType, openSettingsEditor, promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/uiUtils";
1618
import { getActiveFilePath, selectWorkspaceFolder } from "../utils/workspaceUtils";
1719
import * as wsl from "../utils/wslUtils";
@@ -166,28 +168,30 @@ async function showProblemInternal(node: IProblem): Promise<void> {
166168

167169
finalPath = wsl.useWsl() ? await wsl.toWinPath(finalPath) : finalPath;
168170

169-
await leetCodeExecutor.showProblem(node, language, finalPath, leetCodeConfig.get<boolean>("showCommentDescription"));
170-
await Promise.all([
171+
const descriptionConfig: IDescriptionConfiguration = settingUtils.getDescriptionConfiguration();
172+
await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment);
173+
const promises: any[] = [
171174
vscode.window.showTextDocument(vscode.Uri.file(finalPath), { preview: false, viewColumn: vscode.ViewColumn.One }),
172-
movePreviewAsideIfNeeded(node),
173175
promptHintMessage(
174176
"hint.commentDescription",
175-
'You can generate the code file with problem description in the comments by enabling "leetcode.showCommentDescription".',
177+
'You can config how to show the problem description through "leetcode.showDescription".',
176178
"Open settings",
177-
(): Promise<any> => openSettingsEditor("leetcode.showCommentDescription"),
179+
(): Promise<any> => openSettingsEditor("leetcode.showDescription"),
178180
),
179-
]);
181+
];
182+
if (descriptionConfig.showInWebview) {
183+
promises.push(showDescriptionView(node));
184+
}
185+
186+
await Promise.all(promises);
180187
} catch (error) {
181188
await promptForOpenOutputChannel(`${error} Please open the output channel for details.`, DialogType.error);
182189
}
183190
}
184191

185-
async function movePreviewAsideIfNeeded(node: IProblem): Promise<void> {
186-
if (vscode.workspace.getConfiguration("leetcode").get<boolean>("enableSideMode", true)) {
187-
return previewProblem(node, true);
188-
}
192+
async function showDescriptionVie 10000 w(node: IProblem): Promise<void> {
193+
return previewProblem(node, vscode.workspace.getConfiguration("leetcode").get<boolean>("enableSideMode", true));
189194
}
190-
191195
async function parseProblemsToPicks(p: Promise<IProblem[]>): Promise<Array<IQuickItemEx<IProblem>>> {
192196
return new Promise(async (resolve: (res: Array<IQuickItemEx<IProblem>>) => void): Promise<void> => {
193197
const picks: Array<IQuickItemEx<IProblem>> = (await p).map((problem: IProblem) => Object.assign({}, {

src/leetCodeExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class LeetCodeExecutor implements Disposable {
8686
);
8787
}
8888

89-
public async showProblem(problemNode: IProblem, language: string, filePath: string, detailed: boolean = false): Promise<void> {
90-
const templateType: string = detailed ? "-cx" : "-c";
89+
public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false): Promise<void> {
90+
const templateType: string = showDescriptionInComment ? "-cx" : "-c";
9191

9292
if (!await fse.pathExists(filePath)) {
9393
await fse.createFile(filePath);

src/shared.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,10 @@ export const supportedPlugins: string[] = [
105105
"solution.discuss",
106106
"leetcode.cn",
107107
];
108+
109+
export enum DescriptionConfiguration {
110+
InWebView = "In Webview",
111+
InFileComment = "In File Comment",
112+
Both = "Both",
113+
None = "None",
114+
}

src/utils/settingUtils.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
import { workspace, WorkspaceConfiguration } from "vscode";
5+
import { DescriptionConfiguration } from "../shared";
56

67
export function getWorkspaceConfiguration(): WorkspaceConfiguration {
78
return workspace.getConfiguration("leetcode");
@@ -18,3 +19,41 @@ export function getWorkspaceFolder(): string {
1819
export function getEditorShortcuts(): string[] {
1920
return getWorkspaceConfiguration().get<string[]>("editor.shortcuts", ["submit", "test"]);
2021
}
22+
23+
export function getDescriptionConfiguration(): IDescriptionConfiguration {
24+
const setting: string = getWorkspaceConfiguration().get<string>("showDescription", DescriptionConfiguration.InWebView);
25+
const config: IDescriptionConfiguration = {
26+
showInComment: false,
27+
showInWebview: true,
28+
};
29+
switch (setting) {
30+
case DescriptionConfiguration.Both:
31+
config.showInComment = true;
32+
config.showInWebview = true;
33+
break;
34+
case DescriptionConfiguration.None:
35+
config.showInComment = false;
36+
config.showInWebview = false;
37+
break;
38+
case DescriptionConfiguration.InFileComment:
39+
config.showInComment = true;
40+
config.showInWebview = false;
41+
break;
42+
case DescriptionConfiguration.InWebView:
43+
config.showInComment = false;
44+
config.showInWebview = true;
45+
break;
46+
}
47+
48+
// To be compatible with the deprecated setting:
49+
if (getWorkspaceConfiguration().get<boolean>("showCommentDescription")) {
50+
config.showInComment = true;
51+
}
52+
53+
return config;
54+
}
55+
56+
export interface IDescriptionConfiguration {
57+
showInComment: boolean;
58+
showInWebview: boolean;
59+
}

0 commit comments

Comments
 (0)
0