Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commitcfed70a

Browse files
Vigilansjdneo
authored andcommitted
feat: Provide several hints for better user experience (LeetCode-OpenSource#293)
1 parentba756a1 commitcfed70a

File tree

5 files changed

+73
-6
lines changed

5 files changed

+73
-6
lines changed

‎package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,30 @@
268268
"scope":"application",
269269
"description":"Include problem description in comments."
270270
},
271-
"leetcode.showSetDefaultLanguageHint": {
271+
"leetcode.hint.setDefaultLanguage": {
272272
"type":"boolean",
273273
"default":true,
274274
"scope":"application",
275275
"description":"Show a hint to set the default language."
276276
},
277+
"leetcode.hint.configWebviewMarkdown": {
278+
"type":"boolean",
279+
"default":true,
280+
"scope":"application",
281+
"description":"Show a hint to change webview appearance through markdown config."
282+
},
283+
"leetcode.hint.commentDescription": {
284+
"type":"boolean",
285+
"default":true,
286+
"scope":"application",
287+
"description":"Show a hint to enable comment description in solution code file."
288+
},
289+
"leetcode.hint.commandShortcut": {
290+
"type":"boolean",
291+
"default":true,
292+
"scope":"application",
293+
"description":"Show a hint to configure commands key binding."
294+
},
277295
"leetcode.useWsl": {
278296
"type":"boolean",
279297
"default":false,

‎src/commands/show.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { leetCodeChannel } from "../leetCodeChannel";
1010
import{leetCodeExecutor}from"../leetCodeExecutor";
1111
import{leetCodeManager}from"../leetCodeManager";
1212
import{IProblem,IQuickItemEx,languages,ProblemState}from"../shared";
13-
import{DialogOptions,DialogType,promptForOpenOutputChannel,promptForSignIn}from"../utils/uiUtils";
13+
import{DialogOptions,DialogType,openSettingsEditor,promptForOpenOutputChannel,promptForSignIn,promptHintMessage}from"../utils/uiUtils";
1414
import{selectWorkspaceFolder}from"../utils/workspaceUtils";
1515
import*aswslfrom"../utils/wslUtils";
1616
import{leetCodePreviewProvider}from"../webview/leetCodePreviewProvider";
@@ -64,7 +64,6 @@ export async function showSolution(node?: LeetCodeNode): Promise<void> {
6464
}
6565
}
6666

67-
// SUGGESTION: group config retriving into one file
6867
asyncfunctionfetchProblemLanguage():Promise<string|undefined>{
6968
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
7069
letdefaultLanguage:string|undefined=leetCodeConfig.get<string>("defaultLanguage");
@@ -74,7 +73,7 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
7473
constlanguage:string|undefined=defaultLanguage||awaitvscode.window.showQuickPick(languages,{placeHolder:"Select the language you want to use",ignoreFocusOut:true});
7574
// fire-and-forget default language query
7675
(async():Promise<void>=>{
77-
if(language&&!defaultLanguage&&leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")){
76+
if(language&&!defaultLanguage&&leetCodeConfig.get<boolean>("hint.setDefaultLanguage")){
7877
constchoice:vscode.MessageItem|undefined=awaitvscode.window.showInformationMessage(
7978
`Would you like to set '${language}' as your default language?`,
8079
DialogOptions.yes,
@@ -84,7 +83,7 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
8483
if(choice===DialogOptions.yes){
8584
leetCodeConfig.update("defaultLanguage",language,true/* UserSetting */);
8685
}elseif(choice===DialogOptions.never){
87-
leetCodeConfig.update("showSetDefaultLanguageHint",false,true/* UserSetting */);
86+
leetCodeConfig.update("hint.setDefaultLanguage",false,true/* UserSetting */);
8887
}
8988
}
9089
})();
@@ -98,7 +97,6 @@ async function showProblemInternal(node: IProblem): Promise<void> {
9897
return;
9998
}
10099

101-
// SUGGESTION: group config retriving into one file
102100
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
103101
letoutDir:string=awaitselectWorkspaceFolder();
104102
letrelativePath:string=(leetCodeConfig.get<string>("outputFolder","")).trim();
@@ -120,6 +118,12 @@ async function showProblemInternal(node: IProblem): Promise<void> {
120118
awaitPromise.all([
121119
vscode.window.showTextDocument(vscode.Uri.file(filePath),{preview:false,viewColumn:vscode.ViewColumn.One}),
122120
movePreviewAsideIfNeeded(node),
121+
promptHintMessage(
122+
"hint.commentDescription",
123+
'You can generate the code file with problem description in the comments by enabling "leetcode.showCommentDescription".',
124+
"Open settings",
125+
():Promise<any>=>openSettingsEditor("leetcode.showCommentDescription"),
126+
),
123127
]);
124128
}catch(error){
125129
awaitpromptForOpenOutputChannel("Failed to show the problem. Please open the output channel for details.",DialogType.error);

‎src/utils/uiUtils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import*asvscodefrom"vscode";
55
import{getLeetCodeEndpoint}from"../commands/plugin";
66
import{leetCodeChannel}from"../leetCodeChannel";
7+
import{getWorkspaceConfiguration}from"./workspaceUtils";
78

89
exportnamespaceDialogOptions{
910
exportconstopen:vscode.MessageItem={title:"Open"};
@@ -57,6 +58,28 @@ export async function promptForSignIn(): Promise<void> {
5758
}
5859
}
5960

61+
exportasyncfunctionpromptHintMessage(config:string,message:string,choiceConfirm:string,onConfirm:()=>Promise<any>):Promise<void>{
62+
if(getWorkspaceConfiguration().get<boolean>(config)){
63+
constchoiceNoShowAgain:string="Don't show again";
64+
constchoice:string|undefined=awaitvscode.window.showInformationMessage(
65+
message,choiceConfirm,choiceNoShowAgain,
66+
);
67+
if(choice===choiceConfirm){
68+
awaitonConfirm();
69+
}elseif(choice===choiceNoShowAgain){
70+
awaitgetWorkspaceConfiguration().update(config,false,true/* UserSetting */);
71+
}
72+
}
73+
}
74+
75+
exportasyncfunctionopenSettingsEditor(query?:string):Promise<void>{
76+
awaitvscode.commands.executeCommand("workbench.action.openSettings",query);
77+
}
78+
79+
exportasyncfunctionopenKeybindingsEditor(query?:string):Promise<void>{
80+
awaitvscode.commands.executeCommand("workbench.action.openGlobalKeybindings",query);
81+
}
82+
6083
exportasyncfunctionshowFileSelectDialog():Promise<vscode.Uri[]|undefined>{
6184
constdefaultUri:vscode.Uri|undefined=vscode.workspace.rootPath ?vscode.Uri.file(vscode.workspace.rootPath) :undefined;
6285
constoptions:vscode.OpenDialogOptions={

‎src/webview/LeetCodeWebview.ts

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

44
import{commands,ConfigurationChangeEvent,Disposable,ViewColumn,WebviewPanel,window,workspace}from"vscode";
5+
import{openSettingsEditor,promptHintMessage}from"../utils/uiUtils";
56
import{markdownEngine}from"./markdownEngine";
67

78
exportabstractclassLeetCodeWebviewimplementsDisposable{
@@ -41,6 +42,7 @@ export abstract class LeetCodeWebview implements Disposable {
4142
}
4243
}
4344
this.panel.webview.html=this.getWebviewContent();
45+
this.showMarkdownConfigHint();
4446
}
4547

4648
protectedonDidDisposeWebview():void{
@@ -62,6 +64,15 @@ export abstract class LeetCodeWebview implements Disposable {
6264
protectedabstractgetWebviewOption():ILeetCodeWebviewOption;
6365

6466
protectedabstractgetWebviewContent():string;
67+
68+
privateasyncshowMarkdownConfigHint():Promise<void>{
69+
awaitpromptHintMessage(
70+
"hint.configWebviewMarkdown",
71+
'You can change the webview appearance ("fontSize", "lineWidth" & "fontFamily") in "markdown.preview" configuration.',
72+
"Open settings",
73+
():Promise<any>=>openSettingsEditor("markdown.preview"),
74+
);
75+
}
6576
}
6677

6778
exportinterfaceILeetCodeWebviewOption{

‎src/webview/leetCodeSubmissionProvider.ts

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

44
import{ViewColumn}from"vscode";
5+
import{openKeybindingsEditor,promptHintMessage}from"../utils/uiUtils";
56
import{ILeetCodeWebviewOption,LeetCodeWebview}from"./LeetCodeWebview";
67
import{markdownEngine}from"./markdownEngine";
78

@@ -13,6 +14,7 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
1314
publicshow(result:string):void{
1415
this.result=result;
1516
this.showWebviewInternal();
17+
this.showKeybindingsHint();
1618
}
1719

1820
protectedgetWebviewOption():ILeetCodeWebviewOption{
@@ -40,6 +42,15 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
4042
super.onDidDisposeWebview();
4143
deletethis.result;
4244
}
45+
46+
privateasyncshowKeybindingsHint():Promise<void>{
47+
awaitpromptHintMessage(
48+
"hint.commandShortcut",
49+
'You can customize shortcut key bindings in File > Preferences > Keyboard Shortcuts with query "leetcode".',
50+
"Open Keybindings",
51+
():Promise<any>=>openKeybindingsEditor("leetcode solution"),
52+
);
53+
}
4354
}
4455

4556
exportconstleetCodeSubmissionProvider:LeetCodeSubmissionProvider=newLeetCodeSubmissionProvider();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp