Skip to content

add outputPath Config #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 16, 2019
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@
"leetcode-cn"
],
"description": "Endpoint of the user account."
},
"leetcode.outputPath": {
"type": "string",
"default": "",
"scope": "application",
"description": "Specifies the relative path to save the problem files."
}
}
}
Expand Down
30 changes: 29 additions & 1 deletion src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function searchProblem(): Promise<void> {

async function showProblemInternal(id: string): Promise<void> {
try {
const listProblems: IProblem[] = await list.listProblems();
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
if (defaultLanguage && languages.indexOf(defaultLanguage) < 0) {
Expand All @@ -49,7 +50,34 @@ async function showProblemInternal(id: string): Promise<void> {
return;
}

const outDir: string = await selectWorkspaceFolder();
let outDir: string = await selectWorkspaceFolder();
const outputPath: string = leetCodeConfig.get<string>("outputPath") || "";
const problem: IProblem | undefined = listProblems.find((item: IProblem) => item.id === id);
switch (outputPath) {
case "": {
break;
}
case "${tag}": {
if (problem) {
outDir = `${outDir}/${problem.tags[0]}`;
}
break;
}
case "${language}": {
outDir = `${outDir}/${language}`;
break;
}
case "${difficulty}": {
if (problem) {
outDir = `${outDir}/${problem.difficulty}`;
}
break;
}
default: {
outDir = `${outDir}/${outputPath}`;
break;
}
}
await fse.ensureDir(outDir);
const result: string = await leetCodeExecutor.showProblem(id, language, outDir);
const reg: RegExp = /\* Source Code:\s*(.*)/;
Expand Down