Skip to content

Commit 1435385

Browse files
committed
增加周赛场次信息展示
1 parent 9ddf859 commit 1435385

File tree

4 files changed

+90
-73
lines changed

4 files changed

+90
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.18.1
2+
3+
- 增加周赛场次信息展示
4+
15
## version 2.17.8
26

37
- 替换中文题解中的 textit

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "2.17.8",
5+
"version": "2.18.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",

src/rpc/factory/api/showApi.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2022 ccagml . All rights reserved.
88
*/
99

10-
let util = require("util");
10+
// let util = require("util");
1111
let childProcess = require("child_process");
1212

1313
import { storageUtils } from "../../utils/storageUtils";
@@ -110,23 +110,23 @@ class ShowApi extends ApiBase {
110110
}
111111

112112
showProblem(problem, argv) {
113-
const taglist = [problem.category]
114-
.concat(problem.companies || [])
115-
.concat(problem.tags || [])
116-
.map((x) => " " + x + " ")
117-
.join(" ");
118-
const langlist = problem.templates
119-
.map((x) => " " + x.value + " ")
120-
.sort()
121-
.join(" ");
113+
// const taglist = [problem.category]
114+
// .concat(problem.companies || [])
115+
// .concat(problem.tags || [])
116+
// .map((x) => " " + x + " ")
117+
// .join(" ");
118+
// const langlist = problem.templates
119+
// .map((x) => " " + x.value + " ")
120+
// .sort()
121+
// .join(" ");
122122

123123
let code;
124124
const needcode = argv.gen || argv.codeonly;
125125
if (needcode) {
126126
const template = problem.templates.find((x) => x.value === argv.lang);
127127
if (!template) {
128128
reply.info('Not supported language "' + argv.lang + '"');
129-
reply.warn("Supported languages: " + langlist);
129+
// reply.warn("Supported languages: " + langlist);
130130
return;
131131
}
132132

@@ -157,33 +157,42 @@ class ShowApi extends ApiBase {
157157
}
158158
}
159159

160-
reply.info(`[${problem.fid}] ${problem.name}`);
161-
reply.info();
162-
reply.info(problem.link);
163-
if (argv.extra) {
164-
reply.info();
165-
reply.info("Tags: " + taglist);
166-
reply.info();
167-
reply.info("Langs: " + langlist);
168-
}
169-
170-
reply.info();
171-
reply.info(`* ${problem.category}`);
172-
reply.info(`* ${problem.level} (${problem.percent.toFixed(2)}%)`);
173-
174-
if (problem.likes) reply.info(`* Likes: ${problem.likes}`);
175-
if (problem.dislikes) reply.info(`* Dislikes: ${problem.dislikes}`);
176-
else reply.info(`* Dislikes: -`);
177-
if (problem.totalAC) reply.info(`* Total Accepted: ${problem.totalAC}`);
178-
if (problem.totalSubmit) reply.info(`* Total Submissions: ${problem.totalSubmit}`);
179-
if (problem.testable && problem.testcase) {
180-
let testcase_value = util.inspect(problem.testcase);
181-
reply.info(`* Testcase Example: ${testcase_value}`);
182-
}
183-
if (filename) reply.info(`* Source Code: ${filename}`);
184-
185-
reply.info();
186-
reply.info(problem.desc);
160+
let preview_data: any = {};
161+
preview_data.url = problem.link;
162+
preview_data.category = `${problem.category}`;
163+
preview_data.difficulty = `${problem.level} (${problem.percent.toFixed(2)}%)`;
164+
preview_data.likes = `${problem.likes}`;
165+
preview_data.dislikes = `${problem.dislikes}`;
166+
preview_data.desc = problem.desc;
167+
reply.info(JSON.stringify(preview_data));
168+
169+
// reply.info(`[${problem.fid}] ${problem.name}`);
170+
// reply.info();
171+
// reply.info(problem.link);
172+
// if (argv.extra) {
173+
// reply.info();
174+
// reply.info("Tags: " + taglist);
175+
// reply.info();
176+
// reply.info("Langs: " + langlist);
177+
// }
178+
179+
// reply.info();
180+
// reply.info(`* ${problem.category}`);
181+
// reply.info(`* ${problem.level} (${problem.percent.toFixed(2)}%)`);
182+
183+
// if (problem.likes) reply.info(`* Likes: ${problem.likes}`);
184+
// if (problem.dislikes) reply.info(`* Dislikes: ${problem.dislikes}`);
185+
// else reply.info(`* Dislikes: -`);
186+
// if (problem.totalAC) reply.info(`* Total Accepted: ${problem.totalAC}`);
187+
// if (problem.totalSubmit) reply.info(`* Total Submissions: ${problem.totalSubmit}`);
188+
// if (problem.testable && problem.testcase) {
189+
// let testcase_value = util.inspect(problem.testcase);
190+
// reply.info(`* Testcase Example: ${testcase_value}`);
191+
// }
192+
// if (filename) reply.info(`* Source Code: ${filename}`);
193+
194+
// reply.info();
195+
// reply.info(problem.desc);
187196
}
188197

189198
call(argv) {

src/service/PreviewService.ts

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ class PreviewService extends BaseWebViewService {
7676
}
7777
</style>`,
7878
};
79-
const { title, url, category, difficulty, likes, dislikes, body } = this.description;
79+
const { title, url, category, difficulty, likes, dislikes, body, contest_slug, problem_index, problem_score } =
80+
this.description;
8081
const head: string = markdownService.render(`# [${title}](${url})`);
8182
const info: string = markdownService.render(
8283
[
83-
`| Category | Difficulty | Likes | Dislikes |`,
84-
`| :------: | :--------: | :---: | :------: |`,
85-
`| ${category} | ${difficulty} | ${likes} | ${dislikes} |`,
84+
`| Category | Difficulty | Likes | Dislikes | ContestSlug | ProblemIndex | Score |`,
85+
`| :------: | :--------: | :---: | :------: | :---------: | :----------: | :---: |`,
86+
`| ${category} | ${difficulty} | ${likes} | ${dislikes} | ${contest_slug} | ${problem_index} | ${problem_score} | `,
8687
].join("\n")
8788
);
8889
const tags: string = [
@@ -145,41 +146,41 @@ class PreviewService extends BaseWebViewService {
145146
}
146147
}
147148

148-
// private async hideSideBar(): Promise<void> {
149-
// await commands.executeCommand("workbench.action.focusSideBar");
150-
// await commands.executeCommand("workbench.action.toggleSidebarVisibility");
151-
// }
152-
153149
private parseDescription(descString: string, problem: IProblem): IDescription {
154-
const [
155-
,
156-
,
157-
/* title */ url,
158-
,
159-
,
160-
,
161-
,
162-
,
163-
/* tags */ /* langs */ category,
164-
difficulty,
165-
likes,
166-
dislikes,
167-
,
168-
,
169-
,
170-
,
171-
/* accepted */ /* submissions */ /* testcase */ ...body
172-
] = descString.split("\n");
150+
// const [
151+
// ,
152+
// ,
153+
// /* title */ url,
154+
// ,
155+
// ,
156+
// ,
157+
// ,
158+
// ,
159+
// /* tags */ /* langs */ category,
160+
// difficulty,
161+
// likes,
162+
// dislikes,
163+
// ,
164+
// ,
165+
// ,
166+
// ,
167+
// /* accepted */ /* submissions */ /* testcase */ ...body
168+
// ] = descString.split("\n");
169+
170+
let preview_data = JSON.parse(descString);
173171
return {
174172
title: problem.name,
175-
url,
173+
url: preview_data.url,
176174
tags: problem.tags,
177175
companies: problem.companies,
178-
category: category.slice(2),
179-
difficulty: difficulty.slice(2),
180-
likes: likes.split(": ")[1].trim(),
181-
dislikes: dislikes.split(": ")[1].trim(),
182-
body: body.join("\n").replace(/<pre>[\r\n]*([^]+?)[\r\n]*<\/pre>/g, "<pre><code>$1</code></pre>"),
176+
category: preview_data.category,
177+
difficulty: preview_data.difficulty,
178+
likes: preview_data.likes,
179+
dislikes: preview_data.dislikes,
180+
body: preview_data.desc.replace(/<pre>[\r\n]*([^]+?)[\r\n]*<\/pre>/g, "<pre><code>$1</code></pre>"),
181+
contest_slug: problem?.scoreData?.ContestSlug || "-",
182+
problem_index: problem?.scoreData?.ProblemIndex || "-",
183+
problem_score: problem?.scoreData?.score || "0",
183184
};
184185
}
185186

@@ -209,6 +210,9 @@ interface IDescription {
209210
likes: string;
210211
dislikes: string;
211212
body: string;
213+
contest_slug: string;
214+
problem_index: string;
215+
problem_score: string;
212216
}
213217

214218
interface IWebViewMessage {

0 commit comments

Comments
 (0)