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

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
jdneo merged 15 commits into LeetCode-OpenSource:master from ringcrl:master
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@
"leetcode-cn"
],
"description": "Endpoint of the user account."
},
"leetcode.outputPath": {
"type": "string",
"scope": "application",
"description": "Specify the relative path to save the problem files."
}
}
}
Expand Down
45 changes: 37 additions & 8 deletions src/commands/show.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as fse from "fs-extra";
import * as path from "path";
import * as vscode from "vscode";
import { LeetCodeNode } from "../explorer/LeetCodeNode";
import { leetCodeExecutor } from "../leetCodeExecutor";
Expand All @@ -16,16 +17,17 @@ export async function showProblem(node?: LeetCodeNode): Promise<void> {
if (!node) {
return;
}
await showProblemInternal(node.id);
await showProblemInternal(node);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though type casting from LeetCodeNode to IProblem is fine. Let's add getter in LeetCodeNode to get the data, which is typed as IProblem.

It looks like I need to do some refactors here later after this PR, The definition of LeetCodeNode and IProblem is overlapped.

}

export async function searchProblem(): Promise<void> {
if (!leetCodeManager.getUser()) {
promptForSignIn();
return;
}
const problems: IProblem[] = await list.listProblems();
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(
parseProblemsToPicks(list.listProblems()),
parseProblemsToPicks(problems),
{
matchOnDetail: true,
placeHolder: "Select one problem",
Expand All @@ -34,10 +36,10 @@ export async function searchProblem(): Promise<void> {
if (!choice) {
return;
}
await showProblemInternal(choice.value);
await showProblemInternal(problems.find((problem: IProblem) => problem.id === choice.value) as IProblem);
}

async function showProblemInternal(id: string): Promise<void> {
async function showProblemInternal(node: IProblem): Promise<void> {
try {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
Expand All @@ -49,9 +51,36 @@ async function showProblemInternal(id: string): Promise<void> {
return;
}

const outDir: string = await selectWorkspaceFolder();
let outDir: string = await selectWorkspaceFolder();
const outputPathCfg: string = leetCodeConfig.get<string>("outputPath") || "";
const outputPath: RegExpMatchArray | null = outputPathCfg.match(/\$\{(.*?)\}/);
if (outputPath) {
switch (outputPath[1].toLowerCase()) {
case "tag": {
const closestTag: string = node.tags.reduce((prev: string, curr: string) => {
return curr.length > prev.length ?
curr :
prev;
}, "");
outDir = path.join(outDir, closestTag);
break;
}
case "language": {
outDir = path.join(outDir, language);
break;
}
case "difficulty": {
outDir = path.join(outDir, node.difficulty);
break;
}
default: {
break;
}

}
}
await fse.ensureDir(outDir);
const result: string = await leetCodeExecutor.showProblem(id, language, outDir);
const result: string = await leetCodeExecutor.showProblem(node.id, language, outDir);
const reg: RegExp = /\* Source Code:\s*(.*)/;
const match: RegExpMatchArray | null = result.match(reg);
if (match && match.length >= 2) {
Expand Down Expand Up @@ -80,9 +109,9 @@ async function showProblemInternal(id: string): Promise<void> {
}
}

async function parseProblemsToPicks(p: Promise<IProblem[]>): Promise<Array<IQuickItemEx<string>>> {
async function parseProblemsToPicks(p: IProblem[]): Promise<Array<IQuickItemEx<string>>> {
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: IProblem) => Object.assign({}, {
const picks: Array<IQuickItemEx<string>> = p.map((problem: IProblem) => Object.assign({}, {
label: `${parseProblemDecorator(problem.state, problem.locked)}${problem.id}.${problem.name}`,
description: "",
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
Expand Down

AltStyle によって変換されたページ (->オリジナル) /