-
Notifications
You must be signed in to change notification settings - Fork 650
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
Changes from 2 commits
0fc7394
51b6464
8e2f691
fc95c8c
bba3239
4b783ac
77c7140
ce1c238
ca9a209
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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"); | ||
|
@@ -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, | ||
|
@@ -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 */); | ||
} | ||
} | ||
})(); | ||
|
@@ -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(); | ||
|
@@ -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".', | ||
"Open configuration", | ||
(): Thenable<any> => vscode.commands.executeCommand("workbench.action.openSettings", "leetcode.showCommentDescription"), | ||
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 can wrap a method for opening the setting, like
|
||
), | ||
]); | ||
} catch (error) { | ||
await promptForOpenOutputChannel("Failed to show the problem. Please open the output channel for details.", DialogType.error); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }; | ||
|
@@ -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}`)) { | ||
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. Just pass the entire |
||
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 = { | ||
|
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"; | ||
|
||
|
@@ -13,6 +14,7 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview { | |
public show(result: string): void { | ||
this.result = result; | ||
this.showWebviewInternal(); | ||
this.showKeybindingsHint(); | ||
} | ||
|
||
protected getWebviewOption(): ILeetCodeWebviewOption { | ||
|
@@ -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.', | ||
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. You can customize the shortcut key bindings in Preferences > Keyboard Shortcuts. |
||
"Open Keybindings", | ||
(): Thenable<any> => commands.executeCommand("workbench.action.openGlobalKeybindings", "leetcode solution"), | ||
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. Same above, wrap a method, like |
||
); | ||
} | ||
} | ||
|
||
export const leetCodeSubmissionProvider: LeetCodeSubmissionProvider = new LeetCodeSubmissionProvider(); |
There was a problem hiding this comment.
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 .....