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

Commite1f3206

Browse files
authored
feat: Can select folder to save the LeetCode files (LeetCode-OpenSource#365)
1 parenta00dac5 commite1f3206

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
|`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`|
122122
|`leetcode.useWsl`| Specify whether to use WSL or not|`false`|
123123
|`leetcode.endpoint`| Specify the active endpoint. Supported endpoints are:`leetcode`,`leetcode-cn`|`leetcode`|
124-
|`leetcode.workspaceFolder`| Specify the path of the workspace folder to store the problem files.|`${home}/.leetcode`|
124+
|`leetcode.workspaceFolder`| Specify the path of the workspace folder to store the problem files.|`""`|
125125
|`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|
126126
|`leetcode.enableStatusBar`| Specify whether the LeetCode status bar will be shown or not.|`true`|
127127
|**(Deprecated)**`leetcode.enableShortcuts`| Specify whether the submit and test shortcuts in editor or not.|`true`|

‎docs/README_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
|`leetcode.defaultLanguage`| 指定答题时使用的默认语言,可选语言有:`bash`,`c`,`cpp`,`csharp`,`golang`,`java`,`javascript`,`kotlin`,`mysql`,`php`,`python`,`python3`,`ruby`,`rust`,`scala`,`swift`|`N/A`|
122122
|`leetcode.useWsl`| 指定是否启用 WSL|`false`|
123123
|`leetcode.endpoint`| 指定使用的终端,可用终端有:`leetcode`,`leetcode-cn`|`leetcode`|
124-
|`leetcode.workspaceFolder`| 指定保存文件的工作区目录|`${home}/.leetcode`|
124+
|`leetcode.workspaceFolder`| 指定保存文件的工作区目录|`""`|
125125
|`leetcode.outputFolder`| 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:<ul><li>`${tag}`: 根据题目的类别进行分类。<li>`${language}`: 根据题目的语言进行分类。</li><li>`${difficulty}`: 根据题目的难度进行分类。</li></ul>例如:`problem-${tag}-${difficulty}`| N/A|
126126
|`leetcode.enableStatusBar`| 指定是否在 VS Code 下方显示插件状态栏。|`true`|
127127
|**(Deprecated)**`leetcode.enableShortcuts`| 指定是否在 VS Code 编辑文件下方显示提交和测试的快捷按钮。|`true`|

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
"type":"string",
315315
"scope":"application",
316316
"description":"The path of the workspace folder to store the problem files.",
317-
"default":"${home}/.leetcode"
317+
"default":""
318318
},
319319
"leetcode.outputFolder": {
320320
"type":"string",

‎src/utils/settingUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) jdneo. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import*asosfrom"os";
54
import{workspace,WorkspaceConfiguration}from"vscode";
65

76
exportfunctiongetWorkspaceConfiguration():WorkspaceConfiguration{
@@ -13,8 +12,7 @@ export function shouldHideSolvedProblem(): boolean {
1312
}
1413

1514
exportfunctiongetWorkspaceFolder():string{
16-
constrawWorkspaceFolder:string=getWorkspaceConfiguration().get<string>("workspaceFolder","${home}/.leetcode");
17-
returnrawWorkspaceFolder.replace(/\${home}/i,os.homedir());
15+
returngetWorkspaceConfiguration().get<string>("workspaceFolder","");
1816
}
1917

2018
exportfunctiongetEditorShortcuts():string[]{

‎src/utils/uiUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined>
9292
returnawaitvscode.window.showOpenDialog(options);
9393
}
9494

95+
exportasyncfunctionshowDirectorySelectDialog():Promise<vscode.Uri[]|undefined>{
96+
constdefaultUri:vscode.Uri|undefined=vscode.workspace.rootPath ?vscode.Uri.file(vscode.workspace.rootPath) :undefined;
97+
constoptions:vscode.OpenDialogOptions={
98+
defaultUri,
99+
canSelectFiles:false,
100+
canSelectFolders:true,
101+
canSelectMany:false,
102+
openLabel:"Select",
103+
};
104+
returnawaitvscode.window.showOpenDialog(options);
105+
}
106+
95107
exportasyncfunctionopenUrl(url:string):Promise<void>{
96108
vscode.commands.executeCommand("vscode.open",vscode.Uri.parse(url));
97109
}

‎src/utils/workspaceUtils.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Copyright (c) jdneo. All rights reserved.
22
// Licensed under the MIT license.
33

4+
import*asosfrom"os";
45
import*aspathfrom"path";
56
import*asvscodefrom"vscode";
6-
import{getWorkspaceFolder}from"./settingUtils";
7+
import{IQuickItemEx}from"../shared";
8+
import{getWorkspaceConfiguration,getWorkspaceFolder}from"./settingUtils";
9+
import{showDirectorySelectDialog}from"./uiUtils";
710
import*aswslfrom"./wslUtils";
811

912
exportasyncfunctionselectWorkspaceFolder():Promise<string>{
10-
constworkspaceFolderSetting:string=getWorkspaceFolder();
13+
letworkspaceFolderSetting:string=getWorkspaceFolder();
14+
if(workspaceFolderSetting.trim()===""){
15+
workspaceFolderSetting=awaitdetermineLeetCodeFolder();
16+
if(workspaceFolderSetting===""){
17+
// User cancelled
18+
returnworkspaceFolderSetting;
19+
}
20+
}
1121
constworkspaceFolders:vscode.WorkspaceFolder[]=vscode.workspace.workspaceFolders||[];
1222
letneedAsk:boolean=true;
1323
for(constfolderofworkspaceFolders){
@@ -70,6 +80,42 @@ function isSubFolder(from: string, to: string): boolean {
7080
return!relative.startsWith("..")&&!path.isAbsolute(relative);
7181
}
7282

83+
asyncfunctiondetermineLeetCodeFolder():Promise<string>{
84+
letresult:string;
85+
constpicks:Array<IQuickItemEx<string>>=[];
86+
picks.push(
87+
{
88+
label:`Default location`,
89+
detail:`${path.join(os.homedir(),".leetcode")}`,
90+
value:`${path.join(os.homedir(),".leetcode")}`,
91+
},
92+
{
93+
label:"$(file-directory) Browse...",
94+
value:":browse",
95+
},
96+
);
97+
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(
98+
picks,
99+
{placeHolder:"Select where you would like to save your LeetCode files"},
100+
);
101+
if(!choice){
102+
result="";
103+
}elseif(choice.value===":browse"){
104+
constdirectory:vscode.Uri[]|undefined=awaitshowDirectorySelectDialog();
105+
if(!directory||directory.length<1){
106+
result="";
107+
}else{
108+
result=directory[0].fsPath;
109+
}
110+
}else{
111+
result=choice.value;
112+
}
113+
114+
getWorkspaceConfiguration().update("workspaceFolder",result,vscode.ConfigurationTarget.Global);
115+
116+
returnresult;
117+
}
118+
73119
enumOpenOption{
74120
openInCurrentWindow="Open in current window",
75121
openInNewWindow="Open in new window",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp