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

Commit1cdca10

Browse files
ringcrljdneo
authored andcommitted
Add a new config: 'outputFolder' to support generate file into a customized folder (LeetCode-OpenSource#123)
1 parentb15f4f8 commit1cdca10

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

‎package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@
247247
"leetcode-cn"
248248
],
249249
"description":"Endpoint of the user account."
250+
},
251+
"leetcode.outputFolder": {
252+
"type":"string",
253+
"scope":"application",
254+
"description":"Specify the relative path to save the problem files."
250255
}
251256
}
252257
}

‎src/commands/show.ts

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the MIT license.
33

44
import*asfsefrom"fs-extra";
5+
import*aspathfrom"path";
56
import*asvscodefrom"vscode";
67
import{LeetCodeNode}from"../explorer/LeetCodeNode";
8+
import{leetCodeChannel}from"../leetCodeChannel";
79
import{leetCodeExecutor}from"../leetCodeExecutor";
810
import{leetCodeManager}from"../leetCodeManager";
911
import{IProblem,IQuickItemEx,languages,ProblemState}from"../shared";
@@ -16,15 +18,15 @@ export async function showProblem(node?: LeetCodeNode): Promise<void> {
1618
if(!node){
1719
return;
1820
}
19-
awaitshowProblemInternal(node.id);
21+
awaitshowProblemInternal(node);
2022
}
2123

2224
exportasyncfunctionsearchProblem():Promise<void>{
2325
if(!leetCodeManager.getUser()){
2426
promptForSignIn();
2527
return;
2628
}
27-
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(
29+
constchoice:IQuickItemEx<IProblem>|undefined=awaitvscode.window.showQuickPick(
2830
parseProblemsToPicks(list.listProblems()),
2931
{
3032
matchOnDetail:true,
@@ -37,7 +39,7 @@ export async function searchProblem(): Promise<void> {
3739
awaitshowProblemInternal(choice.value);
3840
}
3941

40-
asyncfunctionshowProblemInternal(id:string):Promise<void>{
42+
asyncfunctionshowProblemInternal(node:IProblem):Promise<void>{
4143
try{
4244
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
4345
letdefaultLanguage:string|undefined=leetCodeConfig.get<string>("defaultLanguage");
@@ -49,9 +51,21 @@ async function showProblemInternal(id: string): Promise<void> {
4951
return;
5052
}
5153

52-
constoutDir:string=awaitselectWorkspaceFolder();
54+
letoutDir:string=awaitselectWorkspaceFolder();
55+
letrelativePath:string=(leetCodeConfig.get<string>("outputFolder")||"").trim();
56+
constmatchResult:RegExpMatchArray|null=relativePath.match(/\$\{(.*?)\}/);
57+
if(matchResult){
58+
constresolvedPath:string|undefined=awaitresolveRelativePath(matchResult[1].toLocaleLowerCase(),node,language);
59+
if(!resolvedPath){
60+
leetCodeChannel.appendLine("Showing problem canceled by user.");
61+
return;
62+
}
63+
relativePath=resolvedPath;
64+
}
65+
66+
outDir=path.join(outDir,relativePath);
5367
awaitfse.ensureDir(outDir);
54-
constresult:string=awaitleetCodeExecutor.showProblem(id,language,outDir);
68+
constresult:string=awaitleetCodeExecutor.showProblem(node.id,language,outDir);
5569
constreg:RegExp=/\*SourceCode:\s*(.*)/;
5670
constmatch:RegExpMatchArray|null=result.match(reg);
5771
if(match&&match.length>=2){
@@ -76,17 +90,17 @@ async function showProblemInternal(id: string): Promise<void> {
7690
}
7791
}
7892
}catch(error){
79-
awaitpromptForOpenOutputChannel("Failed tofetch the problem information. Please open the output channel for details.",DialogType.error);
93+
awaitpromptForOpenOutputChannel("Failed toshow the problem. Please open the output channel for details.",DialogType.error);
8094
}
8195
}
8296

83-
asyncfunctionparseProblemsToPicks(p:Promise<IProblem[]>):Promise<Array<IQuickItemEx<string>>>{
84-
returnnewPromise(async(resolve:(res:Array<IQuickItemEx<string>>)=>void):Promise<void>=>{
85-
constpicks:Array<IQuickItemEx<string>>=(awaitp).map((problem:IProblem)=>Object.assign({},{
97+
asyncfunctionparseProblemsToPicks(p:Promise<IProblem[]>):Promise<Array<IQuickItemEx<IProblem>>>{
98+
returnnewPromise(async(resolve:(res:Array<IQuickItemEx<IProblem>>)=>void):Promise<void>=>{
99+
constpicks:Array<IQuickItemEx<IProblem>>=(awaitp).map((problem:IProblem)=>Object.assign({},{
86100
label:`${parseProblemDecorator(problem.state,problem.locked)}${problem.id}.${problem.name}`,
87101
description:"",
88102
detail:`AC rate:${problem.passRate}, Difficulty:${problem.difficulty}`,
89-
value:problem.id,
103+
value:problem,
90104
}));
91105
resolve(picks);
92106
});
@@ -102,3 +116,28 @@ function parseProblemDecorator(state: ProblemState, locked: boolean): string {
102116
returnlocked ?"$(lock) " :"";
103117
}
104118
}
119+
120+
asyncfunctionresolveRelativePath(value:string,node:IProblem,selectedLanguage:string):Promise<string|undefined>{
121+
switch(value){
122+
case"tag":
123+
if(node.tags.length===1){
124+
returnnode.tags[0];
125+
}
126+
returnawaitvscode.window.showQuickPick(
127+
node.tags,
128+
{
129+
matchOnDetail:true,
130+
placeHolder:"Multiple tags available, please select one",
131+
ignoreFocusOut:true,
132+
},
133+
);
134+
case"language":
135+
returnselectedLanguage;
136+
case"difficulty":
137+
returnnode.difficulty;
138+
default:
139+
consterrorMsg:string=`The config '${value}' is not supported.`;
140+
leetCodeChannel.appendLine(errorMsg);
141+
thrownewError(errorMsg);
142+
}
143+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp