Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f6352cd

Browse files
author
chengruilin
committed
feat: add tag selector
1 parent d96bca9 commit f6352cd

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/commands/show.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function searchProblem(): Promise<void> {
2626
return;
2727
}
2828
const problems: IProblem[] = await list.listProblems();
29-
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(
29+
const choice: IQuickItemEx<IProblem> | undefined = await vscode.window.showQuickPick(
3030
parseProblemsToPicks(problems),
3131
{
3232
matchOnDetail: true,
@@ -36,7 +36,7 @@ export async function searchProblem(): Promise<void> {
3636
if (!choice) {
3737
return;
3838
}
39-
await showProblemInternal(problems.find((problem: IProblem) => problem.id === choice.value) as IProblem);
39+
await showProblemInternal(choice.value);
4040
}
4141

4242
async function showProblemInternal(node: IProblem): Promise<void> {
@@ -57,12 +57,22 @@ async function showProblemInternal(node: IProblem): Promise<void> {
5757
if (outputPath) {
5858
switch (outputPath[1].toLowerCase()) {
5959
case "tag":
60-
const closestTag: string = node.tags.reduce((prev: string, curr: string) => {
61-
return curr.length > prev.length ?
62-
curr :
63-
prev;
64-
}, "");
65-
outDir = path.join(outDir, closestTag);
60+
let tag: string | undefined;
61+
if (node.tags.length === 1) {
62+
tag = node.tags[0];
63+
} else {
64+
tag = await vscode.window.showQuickPick(
65+
node.tags,
66+
{
67+
matchOnDetail: true,
68+
placeHolder: "Select one tag",
69+
},
70+
);
71+
}
72+
if (!tag) {
73+
return;
74+
}
75+
outDir = path.join(outDir, tag);
6676
break;
6777
case "language":
6878
outDir = path.join(outDir, language);
@@ -108,13 +118,13 @@ async function showProblemInternal(node: IProblem): Promise<void> {
108118
}
109119
}
110120

111-
async function parseProblemsToPicks(p: IProblem[]): Promise<Array<IQuickItemEx<string>>> {
112-
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
113-
const picks: Array<IQuickItemEx<string>> = p.map((problem: IProblem) => Object.assign({}, {
121+
async function parseProblemsToPicks(p: IProblem[]): Promise<Array<IQuickItemEx<IProblem>>> {
122+
return new Promise(async (resolve: (res: Array<IQuickItemEx<IProblem>>) => void): Promise<void> => {
123+
const picks: Array<IQuickItemEx<IProblem>> = p.map((problem: IProblem) => Object.assign({}, {
114124
label: `${parseProblemDecorator(problem.state, problem.locked)}${problem.id}.${problem.name}`,
115125
description: "",
116126
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
117-
value: problem.id,
127+
value: problem,
118128
}));
119129
resolve(picks);
120130
});

0 commit comments

Comments
 (0)