Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide several hints for better user experience #293

Merged
merged 9 commits into from
Apr 28, 2019
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,30 @@
"scope": "application",
"description": "Include problem description in comments."
},
"leetcode.showSetDefaultLanguageHint": {
"leetcode.hint.setDefaultLanguage": {
"type": "boolean",
"default": true,
"scope": "application",
"description": "Show a hint to set the default language."
},
"leetcode.hint.configWebviewMarkdown": {
"type": "boolean",
"default": true,
"scope": "application",
"description": "Show a hint to change webview appearance through markdown config."
},
"leetcode.hint.commentDescription": {
"type": "boolean",
"default": true,
"scope": "application",
"description": "Show a hint to enable comment description in solution code file."
},
"leetcode.hint.commandShortcut": {
"type": "boolean",
"default": true,
"scope": "application",
"description": "Show a hint to configure commands key binding."
},
"leetcode.useWsl": {
"type": "boolean",
"default": false,
Expand Down
14 changes: 9 additions & 5 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { leetCodeChannel } from "../leetCodeChannel";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { IProblem, IQuickItemEx, languages, ProblemState } from "../shared";
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/uiUtils";
import { selectWorkspaceFolder } from "../utils/workspaceUtils";
import * as wsl from "../utils/wslUtils";
import { leetCodePreviewProvider } from "../webview/leetCodePreviewProvider";
Expand Down Expand Up @@ -64,7 +64,6 @@ export async function showSolution(node?: LeetCodeNode): Promise<void> {
}
}

// SUGGESTION: group config retriving into one file
async function fetchProblemLanguage(): Promise<string | undefined> {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
Expand All @@ -74,7 +73,7 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
const language: string | undefined = defaultLanguage || await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use", ignoreFocusOut: true });
// fire-and-forget default language query
(async (): Promise<void> => {
if (language && !defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
if (language && !defaultLanguage && leetCodeConfig.get<boolean>("hint.setDefaultLanguage")) {
const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
`Would you like to set '${language}' as your default language?`,
DialogOptions.yes,
Expand All @@ -84,7 +83,7 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
if (choice === DialogOptions.yes) {
leetCodeConfig.update("defaultLanguage", language, true /* UserSetting */);
} else if (choice === DialogOptions.never) {
leetCodeConfig.update("showSetDefaultLanguageHint", false, true /* UserSetting */);
leetCodeConfig.update("hint.setDefaultLanguage", false, true /* UserSetting */);
}
}
})();
Expand All @@ -98,7 +97,6 @@ async function showProblemInternal(node: IProblem): Promise<void> {
return;
}

// SUGGESTION: group config retriving into one file
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
let outDir: string = await selectWorkspaceFolder();
let relativePath: string = (leetCodeConfig.get<string>("outputFolder", "")).trim();
Expand All @@ -120,6 +118,12 @@ async function showProblemInternal(node: IProblem): Promise<void> {
await Promise.all([
vscode.window.showTextDocument(vscode.Uri.file(filePath), { preview: false, viewColumn: vscode.ViewColumn.One }),
movePreviewAsideIfNeeded(node),
promptHintMessage(
"commentDescription",
'You can generate problem description as comment in the solution code file by enabling "leetcode.showCommentDescription".',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can generate the code file with problem description in the comments by .....

"Open configuration",
(): Thenable<any> => vscode.commands.executeCommand("workbench.action.openSettings", "leetcode.showCommentDescription"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can wrap a method for opening the setting, like

openSettingView(section?: string)

),
]);
} catch (error) {
await promptForOpenOutputChannel("Failed to show the problem. Please open the output channel for details.", DialogType.error);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/uiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as vscode from "vscode";
import { getLeetCodeEndpoint } from "../commands/plugin";
import { leetCodeChannel } from "../leetCodeChannel";
import { getWorkspaceConfiguration } from "./workspaceUtils";

export namespace DialogOptions {
export const open: vscode.MessageItem = { title: "Open" };
Expand Down Expand Up @@ -57,6 +58,20 @@ export async function promptForSignIn(): Promise<void> {
}
}

export async function promptHintMessage(config: string, message: string, choiceConfirm: string, onConfirm: () => Thenable<any>): Promise<void> {
if (getWorkspaceConfiguration().get<boolean>(`hint.${config}`)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass the entire hint.${config} to the method instead of only the ${config} itself since we may have other setting section in the future.

const choiceNoShowAgain: string = "Don't show again";
const choice: string | undefined = await vscode.window.showInformationMessage(
message, choiceConfirm, choiceNoShowAgain,
);
if (choice === choiceConfirm) {
await onConfirm();
} else if (choice === choiceNoShowAgain) {
await getWorkspaceConfiguration().update(`hint.${config}`, false, true /* UserSetting */);
}
}
}

export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined> {
const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined;
const options: vscode.OpenDialogOptions = {
Expand Down
11 changes: 11 additions & 0 deletions src/webview/LeetCodeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import { commands, ConfigurationChangeEvent, Disposable, ViewColumn, WebviewPanel, window, workspace } from "vscode";
import { promptHintMessage } from "../utils/uiUtils";
import { markdownEngine } from "./markdownEngine";

export abstract class LeetCodeWebview implements Disposable {
Expand Down Expand Up @@ -41,6 +42,7 @@ export abstract class LeetCodeWebview implements Disposable {
}
}
this.panel.webview.html = this.getWebviewContent();
this.showMarkdownConfigHint();
}

protected onDidDisposeWebview(): void {
Expand All @@ -62,6 +64,15 @@ export abstract class LeetCodeWebview implements Disposable {
protected abstract getWebviewOption(): ILeetCodeWebviewOption;

protected abstract getWebviewContent(): string;

private async showMarkdownConfigHint(): Promise<void> {
await promptHintMessage(
"configWebviewMarkdown",
'You can change the webview appearance ("fontSize", "lineWidth" & "fontFamily") in "markdown.preview" configuration.',
"Open configuration",
(): Thenable<any> => commands.executeCommand("workbench.action.openSettings", "markdown.preview"),
);
}
}

export interface ILeetCodeWebviewOption {
Expand Down
13 changes: 12 additions & 1 deletion src/webview/leetCodeSubmissionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import { ViewColumn } from "vscode";
import { commands, ViewColumn } from "vscode";
import { promptHintMessage } from "../utils/uiUtils";
import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview";
import { markdownEngine } from "./markdownEngine";

Expand All @@ -13,6 +14,7 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
public show(result: string): void {
this.result = result;
this.showWebviewInternal();
this.showKeybindingsHint();
}

protected getWebviewOption(): ILeetCodeWebviewOption {
Expand Down Expand Up @@ -40,6 +42,15 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
super.onDidDisposeWebview();
delete this.result;
}

private async showKeybindingsHint(): Promise<void> {
await promptHintMessage(
"commandShortcut",
'You can configure custom key bindings with "test", "submit" or any other command in Preferences > Keyboard Shortcuts.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can customize the shortcut key bindings in Preferences > Keyboard Shortcuts.

"Open Keybindings",
(): Thenable<any> => commands.executeCommand("workbench.action.openGlobalKeybindings", "leetcode solution"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same above, wrap a method, like openKeyBindingView(section?: string)

);
}
}

export const leetCodeSubmissionProvider: LeetCodeSubmissionProvider = new LeetCodeSubmissionProvider();