Skip to content

Commit 7dffcc4

Browse files
committed
每日一题,按钮自定义排序,提交的二次确认及自定义提示语,ac beat rate提取
1 parent 750325b commit 7dffcc4

File tree

10 files changed

+103
-2144
lines changed

10 files changed

+103
-2144
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
},
1212
"tslint.autoFixOnSave": true,
1313
"tslint.ignoreDefinitionFiles": true
14-
}
14+
}

package-lock.json

Lines changed: 7 additions & 2132 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "vscode-leetcode",
3-
"displayName": "LeetCode",
2+
"name": "leetcode-hum",
3+
"displayName": "LeetCodeHum",
44
"description": "Solve LeetCode problems in VS Code",
5-
"version": "0.18.1",
6-
"author": "Sheng Chen",
7-
"publisher": "LeetCode",
5+
"version": "0.18.2",
6+
"author": "hummingg",
7+
"publisher": "hummingg",
88
"license": "MIT",
99
"icon": "resources/LeetCode.png",
1010
"engines": {
1111
"vscode": "^1.57.0"
1212
},
1313
"repository": {
1414
"type": "git",
15-
"url": "https://github.com/LeetCode-OpenSource/vscode-leetcode"
15+
"url": "https://github.com/hummingg/vscode-leetcode"
1616
},
17-
"homepage": "https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/README.md",
17+
"homepage": "https://github.com/hummingg/vscode-leetcode/blob/master/README.md",
1818
"categories": [
1919
"Other",
2020
"Snippets"
@@ -32,6 +32,7 @@
3232
"onCommand:leetcode.manageSessions",
3333
"onCommand:leetcode.refreshExplorer",
3434
"onCommand:leetcode.pickOne",
35+
"onCommand:leetcode.problemOfToday",
3536
"onCommand:leetcode.showProblem",
3637
"onCommand:leetcode.previewProblem",
3738
"onCommand:leetcode.searchProblem",
@@ -82,6 +83,12 @@
8283
"title": "Pick One",
8384
"category": "LeetCode"
8485
},
86+
{
87+
"command": "leetcode.problemOfToday",
88+
"title": "Problem Of Today",
89+
"category": "LeetCode",
90+
"icon": "$(calendar)"
91+
},
8592
{
8693
"command": "leetcode.showProblem",
8794
"title": "Show Problem",
@@ -182,6 +189,11 @@
182189
"when": "view == leetCodeExplorer",
183190
"group": "navigation@3"
184191
},
192+
{
193+
"command": "leetcode.problemOfToday",
194+
"when": "view == leetCodeExplorer",
195+
"group": "navigation@4"
196+
},
185197
{
186198
"command": "leetcode.pickOne",
187199
"when": "view == leetCodeExplorer",
@@ -700,6 +712,12 @@
700712
"Acceptance Rate (Descending)"
701713
],
702714
"description": "Sorting strategy for problems list."
715+
},
716+
"leetcode.prompt.confirmSubmit": {
717+
"type": "string",
718+
"default": "",
719+
"scope": "application",
720+
"description": "The prompt of confirm submit"
703721
}
704722
}
705723
}
@@ -728,7 +746,6 @@
728746
"lodash": "^4.17.21",
729747
"markdown-it": "^8.4.2",
730748
"require-from-string": "^2.0.2",
731-
"unescape-js": "^1.1.4",
732-
"vsc-leetcode-cli": "2.8.1"
749+
"unescape-js": "^1.1.4"
733750
}
734751
}

src/commands/show.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ export async function pickOne(): Promise<void> {
5252
await showProblemInternal(randomProblem);
5353
}
5454

55+
export async function problemOfToday(): Promise<void> {
56+
if (!leetCodeManager.getUser()) {
57+
promptForSignIn();
58+
return;
59+
}
60+
try {
61+
const nodes: LeetCodeNode[] = explorerNodeManager.getAllNodes()
62+
const problemOfTodayStr: string = await leetCodeExecutor.problemOfToday();
63+
const lines: string[] = problemOfTodayStr.split("\n");
64+
const reg: RegExp = /^\[(.+)\]\s.*/
65+
const match: RegExpMatchArray | null = lines[0].match(reg);
66+
if (match != null) {
67+
const id = match[1]
68+
// vscode.window.showInformationMessage(`MyDebug: problemid ${id}`);
69+
const problemOfToday: IProblem[] = nodes.filter(one => one.id === id);
70+
if (problemOfToday.length != 1) {
71+
explorerNodeManager.getNodeById(id);
72+
await promptForOpenOutputChannel("Fail to load problem of today. You may need to refresh the problem list.", DialogType.error);
73+
}
74+
else {
75+
await showProblemInternal(problemOfToday[0]);
76+
}
77+
}
78+
}
79+
catch {
80+
await promptForOpenOutputChannel("Fail to load problem of today. Open the output channel for details.", DialogType.error);
81+
}
82+
}
5583
export async function showProblem(node?: LeetCodeNode): Promise<void> {
5684
if (!node) {
5785
return;

src/commands/submit.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import * as vscode from "vscode";
55
import { leetCodeTreeDataProvider } from "../explorer/LeetCodeTreeDataProvider";
66
import { leetCodeExecutor } from "../leetCodeExecutor";
77
import { leetCodeManager } from "../leetCodeManager";
8-
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
8+
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
99
import { getActiveFilePath } from "../utils/workspaceUtils";
10+
import { getConfirmSubmitPrompt } from "../utils/settingUtils";
1011
import { leetCodeSubmissionProvider } from "../webview/leetCodeSubmissionProvider";
1112

1213
export async function submitSolution(uri?: vscode.Uri): Promise<void> {
@@ -15,6 +16,15 @@ export async function submitSolution(uri?: vscode.Uri): Promise<void> {
1516
return;
1617
}
1718

19+
const prompt: string = getConfirmSubmitPrompt();
20+
if (prompt) {
21+
// const choice = await vscode.window.showInformationMessage("humming, 确定一定以及肯定要提交吗?", DialogOptions.yes, DialogOptions.no);
22+
const choice = await vscode.window.showInformationMessage(prompt, DialogOptions.yes, DialogOptions.no);
23+
if (choice != DialogOptions.yes) {
24+
return;
25+
}
26+
27+
}
1828
const filePath: string | undefined = await getActiveFilePath(uri);
1929
if (!filePath) {
2030
return;

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
5858
vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)),
5959
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
6060
vscode.commands.registerCommand("leetcode.pickOne", () => show.pickOne()),
61+
vscode.commands.registerCommand("leetcode.problemOfToday", () => show.problemOfToday()),
6162
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
6263
vscode.commands.registerCommand("leetcode.showSolution", (input: LeetCodeNode | vscode.Uri) => show.showSolution(input)),
6364
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),

src/leetCodeExecutor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class LeetCodeExecutor implements Disposable {
2020
private configurationChangeListener: Disposable;
2121

2222
constructor() {
23-
this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli");
23+
// this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli");
24+
this.leetCodeRootPath = path.join(__dirname, "leetcode-cli");
2425
this.nodeExecutable = this.getNodePath();
2526
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
2627
if (event.affectsConfiguration("leetcode.nodePath")) {
@@ -100,6 +101,11 @@ class LeetCodeExecutor implements Disposable {
100101
return await this.executeCommandEx(this.nodeExecutable, cmd);
101102
}
102103

104+
public async problemOfToday(): Promise<string> {
105+
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", "-d"];
106+
return await this.executeCommandWithProgressEx("Loading problem of today...", this.nodeExecutable, cmd);
107+
}
108+
103109
public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false, needTranslation: boolean): Promise<void> {
104110
const templateType: string = showDescriptionInComment ? "-cx" : "-c";
105111
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", problemNode.id, templateType, "-l", language];

src/leetcode-cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 7f0d21103ea73e0b4d00c2c14404398d6ff7dc1a

src/utils/settingUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ export interface IDescriptionConfiguration {
6666
showInComment: boolean;
6767
showInWebview: boolean;
6868
}
69+
70+
export function getConfirmSubmitPrompt(): string {
71+
return getWorkspaceConfiguration().get<string>("prompt.confirmSubmit", "");
72+
}

src/webview/leetCodeSubmissionProvider.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
2626

2727
protected getWebviewContent(): string {
2828
const styles: string = markdownEngine.getStyles();
29+
// window.showInformationMessage(this.result.messages.join('\n'));
2930
const title: string = `## ${this.result.messages[0]}`;
3031
const messages: string[] = this.result.messages.slice(1).map((m: string) => `* ${m}`);
3132
const sections: string[] = Object.keys(this.result)
@@ -36,10 +37,26 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
3637
this.result[key].join("\n"),
3738
"```",
3839
].join("\n"));
40+
41+
const indicatorPat: RegExp = /[ \(/]{1}([\d.]+( ms| %| MB)?)/gm;
42+
let orderedindIcators: string = "";
43+
if (this.result.messages[0] == 'Accepted') {
44+
let indicators: string[] = []
45+
const msgs: string = messages.join('\n');
46+
let indicator: RegExpExecArray | null = indicatorPat.exec(msgs);
47+
while (indicator != null) {
48+
indicators.push(indicator[1].replace(' ', ''));
49+
indicator = indicatorPat.exec(msgs);
50+
}
51+
orderedindIcators = '* ' + [indicators[0] + ': ', indicators[3] + `(${indicators[2]})`, indicators[4] + `(${indicators[5]})`,].join(' ') + '; ';
52+
}
53+
orderedindIcators += '\n';
54+
3955
const body: string = markdownEngine.render([
4056
title,
4157
...messages,
4258
...sections,
59+
orderedindIcators
4360
].join("\n"));
4461
return `
4562
<!DOCTYPE html>

0 commit comments

Comments
 (0)