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

Commitac9df4d

Browse files
authored
Better config how to show the problem description (LeetCode-OpenSource#519)
1 parentd160d1f commitac9df4d

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+
"deprecationMessage":"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*assettingUtilsfrom"../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*aswslfrom"../utils/wslUtils";
@@ -166,28 +168,30 @@ async function showProblemInternal(node: IProblem): Promise<void> {
166168

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

169-
awaitleetCodeExecutor.showProblem(node,language,finalPath,leetCodeConfig.get<boolean>("showCommentDescription"));
170-
awaitPromise.all([
171+
constdescriptionConfig:IDescriptionConfiguration=settingUtils.getDescriptionConfiguration();
172+
awaitleetCodeExecutor.showProblem(node,language,finalPath,descriptionConfig.showInComment);
173+
constpromises: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 cangenerate the code file with problem descriptionin the comments by enabling"leetcode.showCommentDescription".',
177+
'You canconfig how to show the problem descriptionthrough"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+
awaitPromise.all(promises);
180187
}catch(error){
181188
awaitpromptForOpenOutputChannel(`${error} Please open the output channel for details.`,DialogType.error);
182189
}
183190
}
184191

185-
asyncfunctionmovePreviewAsideIfNeeded(node:IProblem):Promise<void>{
186-
if(vscode.workspace.getConfiguration("leetcode").get<boolean>("enableSideMode",true)){
187-
returnpreviewProblem(node,true);
188-
}
192+
asyncfunctionshowDescriptionView(node:IProblem):Promise<void>{
193+
returnpreviewProblem(node,vscode.workspace.getConfiguration("leetcode").get<boolean>("enableSideMode",true));
189194
}
190-
191195
asyncfunctionparseProblemsToPicks(p:Promise<IProblem[]>):Promise<Array<IQuickItemEx<IProblem>>>{
192196
returnnewPromise(async(resolve:(res:Array<IQuickItemEx<IProblem>>)=>void):Promise<void>=>{
193197
constpicks:Array<IQuickItemEx<IProblem>>=(awaitp).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-
publicasyncshowProblem(problemNode:IProblem,language:string,filePath:string,detailed:boolean=false):Promise<void>{
90-
consttemplateType:string=detailed ?"-cx" :"-c";
89+
publicasyncshowProblem(problemNode:IProblem,language:string,filePath:string,showDescriptionInComment:boolean=false):Promise<void>{
90+
consttemplateType:string=showDescriptionInComment ?"-cx" :"-c";
9191

9292
if(!awaitfse.pathExists(filePath)){
9393
awaitfse.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+
exportenumDescriptionConfiguration{
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
exportfunctiongetWorkspaceConfiguration():WorkspaceConfiguration{
78
returnworkspace.getConfiguration("leetcode");
@@ -18,3 +19,41 @@ export function getWorkspaceFolder(): string {
1819
exportfunctiongetEditorShortcuts():string[]{
1920
returngetWorkspaceConfiguration().get<string[]>("editor.shortcuts",["submit","test"]);
2021
}
22+
23+
exportfunctiongetDescriptionConfiguration():IDescriptionConfiguration{
24+
constsetting:string=getWorkspaceConfiguration().get<string>("showDescription",DescriptionConfiguration.InWebView);
25+
constconfig:IDescriptionConfiguration={
26+
showInComment:false,
27+
showInWebview:true,
28+
};
29+
switch(setting){
30+
caseDescriptionConfiguration.Both:
31+
config.showInComment=true;
32+
config.showInWebview=true;
33+
break;
34+
caseDescriptionConfiguration.None:
35+
config.showInComment=false;
36+
config.showInWebview=false;
37+
break;
38+
caseDescriptionConfiguration.InFileComment:
39+
config.showInComment=true;
40+
config.showInWebview=false;
41+
break;
42+
caseDescriptionConfiguration.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+
returnconfig;
54+
}
55+
56+
exportinterfaceIDescriptionConfiguration{
57+
showInComment:boolean;
58+
showInWebview:boolean;
59+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp