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

Commitfc80f68

Browse files
authored
feat: Support interpolation for outputFolder settings (LeetCode-OpenSource#323)
1 parentd01a8f0 commitfc80f68

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
|`leetcode.defaultLanguage`| Specify the default language used to solve the problem. Supported languages are:`bash`,`c`,`cpp`,`csharp`,`golang`,`java`,`javascript`,`kotlin`,`mysql`,`php`,`python`,`python3`,`ruby`,`rust`,`scala`,`swift`|`N/A`|
141141
|`leetcode.useWsl`| Specify whether to use WSL or not|`false`|
142142
|`leetcode.endpoint`| Specify the active endpoint. Supported endpoints are:`leetcode`,`leetcode-cn`|`leetcode`|
143-
|`leetcode.outputFolder`| Specify the relative path to save the problem files. Besides using customized path, there are also several reserved words which can be used here: <ul><li>`${tag}`: Categorize the problem according to their tags.<li>`${language}`: Categorize the problem according to their language.</li><li>`${difficulty}`: Categorize the problem according to their difficulty.</li></ul>| N/A|
143+
|`leetcode.outputFolder`| Specify the relative path to save the problem files. Besides using customized path, there are also several reserved words which can be used here: <ul><li>`${tag}`: Categorize the problem according to their tags.<li>`${language}`: Categorize the problem according to their language.</li><li>`${difficulty}`: Categorize the problem according to their difficulty.</li></ul>For example:`problem-${tag}-${difficulty}`| N/A|
144144
|`leetcode.enableStatusBar`| Specify whether the LeetCode status bar will be shown or not.|`true`|
145145
|`leetcode.enableShortcuts`| Specify whether the submit and test shortcuts in editor or not.|`true`|
146146
|`leetcode.enableSideMode`| Specify whether`preview`,`solution` and`submission` tab should be grouped into the second editor column when solving a problem.|`true`|

‎docs/README_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
|`leetcode.defaultLanguage`| 指定答题时使用的默认语言,可选语言有:`bash`,`c`,`cpp`,`csharp`,`golang`,`java`,`javascript`,`kotlin`,`mysql`,`php`,`python`,`python3`,`ruby`,`rust`,`scala`,`swift`|`N/A`|
141141
|`leetcode.useWsl`| 指定是否启用 WSL|`false`|
142142
|`leetcode.endpoint`| 指定使用的终端,可用终端有:`leetcode`,`leetcode-cn`|`leetcode`|
143-
|`leetcode.outputFolder`| 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:<ul><li>`${tag}`: 根据题目的类别进行分类。<li>`${language}`: 根据题目的语言进行分类。</li><li>`${difficulty}`: 根据题目的难度进行分类。</li></ul>| N/A|
143+
|`leetcode.outputFolder`| 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:<ul><li>`${tag}`: 根据题目的类别进行分类。<li>`${language}`: 根据题目的语言进行分类。</li><li>`${difficulty}`: 根据题目的难度进行分类。</li></ul>例如:`problem-${tag}-${difficulty}`| N/A|
144144
|`leetcode.enableStatusBar`| 指定是否在 VS Code 下方显示插件状态栏。|`true`|
145145
|`leetcode.enableShortcuts`| 指定是否在 VS Code 编辑文件下方显示提交和测试的快捷按钮。|`true`|
146146
|`leetcode.enableSideMode`| 指定在解决一道题时,是否将`问题预览``高票答案``提交结果`窗口集中在编辑器的第二栏。|`true`|

‎src/commands/show.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,12 @@ async function showProblemInternal(node: IProblem): Promise<void> {
107107
constleetCodeConfig:vscode.WorkspaceConfiguration=vscode.workspace.getConfiguration("leetcode");
108108
letoutDir:string=awaitselectWorkspaceFolder();
109109
letrelativePath:string=(leetCodeConfig.get<string>("outputFolder","")).trim();
110-
constmatchResult:RegExpMatchArray|null=relativePath.match(/\$\{(.*?)\}/);
111-
if(matchResult){
112-
constresolvedPath:string|undefined=awaitresolveRelativePath(matchResult[1].toLocaleLowerCase(),node,language);
113-
if(!resolvedPath){
110+
if(relativePath){
111+
relativePath=awaitresolveRelativePath(relativePath,node,language);
112+
if(!relativePath){
114113
leetCodeChannel.appendLine("Showing problem canceled by user.");
115114
return;
116115
}
117-
relativePath=resolvedPath;
118116
}
119117

120118
outDir=path.join(outDir,relativePath);
@@ -166,27 +164,39 @@ function parseProblemDecorator(state: ProblemState, locked: boolean): string {
166164
}
167165
}
168166

169-
asyncfunctionresolveRelativePath(value:string,node:IProblem,selectedLanguage:string):Promise<string|undefined>{
170-
switch(value){
171-
case"tag":
172-
if(node.tags.length===1){
173-
returnnode.tags[0];
174-
}
175-
returnawaitvscode.window.showQuickPick(
176-
node.tags,
177-
{
178-
matchOnDetail:true,
179-
placeHolder:"Multiple tags available, please select one",
180-
ignoreFocusOut:true,
181-
},
182-
);
183-
case"language":
184-
returnselectedLanguage;
185-
case"difficulty":
186-
returnnode.difficulty;
187-
default:
188-
consterrorMsg:string=`The config '${value}' is not supported.`;
189-
leetCodeChannel.appendLine(errorMsg);
190-
thrownewError(errorMsg);
167+
asyncfunctionresolveRelativePath(relativePath:string,node:IProblem,selectedLanguage:string):Promise<string>{
168+
if(/\$\{tag\}/i.test(relativePath)){
169+
consttag:string|undefined=awaitresolveTagForProblem(node);
170+
if(!tag){
171+
return"";
172+
}
173+
relativePath=relativePath.replace(/\$\{tag\}/ig,tag);
191174
}
175+
176+
relativePath=relativePath.replace(/\$\{language\}/ig,selectedLanguage);
177+
relativePath=relativePath.replace(/\$\{difficulty\}/ig,node.difficulty.toLocaleLowerCase());
178+
179+
// Check if there is any unsupported configuration
180+
constmatchResult:RegExpMatchArray|null=relativePath.match(/\$\{(.*?)\}/);
181+
if(matchResult&&matchResult.length>=1){
182+
consterrorMsg:string=`The config '${matchResult[1]}' is not supported.`;
183+
leetCodeChannel.appendLine(errorMsg);
184+
thrownewError(errorMsg);
185+
}
186+
187+
returnrelativePath;
188+
}
189+
190+
asyncfunctionresolveTagForProblem(problem:IProblem):Promise<string|undefined>{
191+
if(problem.tags.length===1){
192+
returnproblem.tags[0];
193+
}
194+
returnawaitvscode.window.showQuickPick(
195+
problem.tags,
196+
{
197+
matchOnDetail:true,
198+
placeHolder:"Multiple tags available, please select one",
199+
ignoreFocusOut:true,
200+
},
201+
);
192202
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp