Skip to content

Commit

Permalink
每日一题,按钮自定义排序,提交的二次确认及自定义提示语,ac beat rate提取
Browse files Browse the repository at this point in the history
  • Loading branch information
hummingg committed Jul 9, 2022
1 parent 750325b commit 7dffcc4
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 2,144 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
},
"tslint.autoFixOnSave": true,
"tslint.ignoreDefinitionFiles": true
}
}
2,139 changes: 7 additions & 2,132 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 26 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "vscode-leetcode",
"displayName": "LeetCode",
"name": "leetcode-hum",
"displayName": "LeetCodeHum",
"description": "Solve LeetCode problems in VS Code",
"version": "0.18.1",
"author": "Sheng Chen",
"publisher": "LeetCode",
"version": "0.18.2",
"author": "hummingg",
"publisher": "hummingg",
"license": "MIT",
"icon": "resources/LeetCode.png",
"engines": {
"vscode": "^1.57.0"
},
"repository": {
"type": "git",
"url": "https://github.com/LeetCode-OpenSource/vscode-leetcode"
"url": "https://github.com/hummingg/vscode-leetcode"
},
"homepage": "https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/README.md",
"homepage": "https://github.com/hummingg/vscode-leetcode/blob/master/README.md",
"categories": [
"Other",
"Snippets"
Expand All @@ -32,6 +32,7 @@
"onCommand:leetcode.manageSessions",
"onCommand:leetcode.refreshExplorer",
"onCommand:leetcode.pickOne",
"onCommand:leetcode.problemOfToday",
"onCommand:leetcode.showProblem",
"onCommand:leetcode.previewProblem",
"onCommand:leetcode.searchProblem",
Expand Down Expand Up @@ -82,6 +83,12 @@
"title": "Pick One",
"category": "LeetCode"
},
{
"command": "leetcode.problemOfToday",
"title": "Problem Of Today",
"category": "LeetCode",
"icon": "$(calendar)"
},
{
"command": "leetcode.showProblem",
"title": "Show Problem",
Expand Down Expand Up @@ -182,6 +189,11 @@
"when": "view == leetCodeExplorer",
"group": "navigation@3"
},
{
"command": "leetcode.problemOfToday",
"when": "view == leetCodeExplorer",
"group": "navigation@4"
},
{
"command": "leetcode.pickOne",
"when": "view == leetCodeExplorer",
Expand Down Expand Up @@ -700,6 +712,12 @@
"Acceptance Rate (Descending)"
],
"description": "Sorting strategy for problems list."
},
"leetcode.prompt.confirmSubmit": {
"type": "string",
"default": "",
"scope": "application",
"description": "The prompt of confirm submit"
}
}
}
Expand Down Expand Up @@ -728,7 +746,6 @@
"lodash": "^4.17.21",
"markdown-it": "^8.4.2",
"require-from-string": "^2.0.2",
"unescape-js": "^1.1.4",
"vsc-leetcode-cli": "2.8.1"
"unescape-js": "^1.1.4"
}
}
28 changes: 28 additions & 0 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ export async function pickOne(): Promise<void> {
await showProblemInternal(randomProblem);
}

export async function problemOfToday(): Promise<void> {
if (!leetCodeManager.getUser()) {
promptForSignIn();
return;
}
try {
const nodes: LeetCodeNode[] = explorerNodeManager.getAllNodes()
const problemOfTodayStr: string = await leetCodeExecutor.problemOfToday();
const lines: string[] = problemOfTodayStr.split("\n");
const reg: RegExp = /^\[(.+)\]\s.*/
const match: RegExpMatchArray | null = lines[0].match(reg);
if (match != null) {
const id = match[1]
// vscode.window.showInformationMessage(`MyDebug: problemid ${id}`);
const problemOfToday: IProblem[] = nodes.filter(one => one.id === id);
if (problemOfToday.length != 1) {
explorerNodeManager.getNodeById(id);
await promptForOpenOutputChannel("Fail to load problem of today. You may need to refresh the problem list.", DialogType.error);
}
else {
await showProblemInternal(problemOfToday[0]);
}
}
}
catch {
await promptForOpenOutputChannel("Fail to load problem of today. Open the output channel for details.", DialogType.error);
}
}
export async function showProblem(node?: LeetCodeNode): Promise<void> {
if (!node) {
return;
Expand Down
12 changes: 11 additions & 1 deletion src/commands/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import * as vscode from "vscode";
import { leetCodeTreeDataProvider } from "../explorer/LeetCodeTreeDataProvider";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { getActiveFilePath } from "../utils/workspaceUtils";
import { getConfirmSubmitPrompt } from "../utils/settingUtils";
import { leetCodeSubmissionProvider } from "../webview/leetCodeSubmissionProvider";

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

const prompt: string = getConfirmSubmitPrompt();
if (prompt) {
// const choice = await vscode.window.showInformationMessage("humming, 确定一定以及肯定要提交吗?", DialogOptions.yes, DialogOptions.no);
const choice = await vscode.window.showInformationMessage(prompt, DialogOptions.yes, DialogOptions.no);
if (choice != DialogOptions.yes) {
return;
}

}
const filePath: string | undefined = await getActiveFilePath(uri);
if (!filePath) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)),
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
vscode.commands.registerCommand("leetcode.pickOne", () => show.pickOne()),
vscode.commands.registerCommand("leetcode.problemOfToday", () => show.problemOfToday()),
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
vscode.commands.registerCommand("leetcode.showSolution", (input: LeetCodeNode | vscode.Uri) => show.showSolution(input)),
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
Expand Down
8 changes: 7 additions & 1 deletion src/leetCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class LeetCodeExecutor implements Disposable {
private configurationChangeListener: Disposable;

constructor() {
this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli");
// this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli");
this.leetCodeRootPath = path.join(__dirname, "leetcode-cli");
this.nodeExecutable = this.getNodePath();
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration("leetcode.nodePath")) {
Expand Down Expand Up @@ -100,6 +101,11 @@ class LeetCodeExecutor implements Disposable {
return await this.executeCommandEx(this.nodeExecutable, cmd);
}

public async problemOfToday(): Promise<string> {
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", "-d"];
return await this.executeCommandWithProgressEx("Loading problem of today...", this.nodeExecutable, cmd);
}

public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false, needTranslation: boolean): Promise<void> {
const templateType: string = showDescriptionInComment ? "-cx" : "-c";
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", problemNode.id, templateType, "-l", language];
Expand Down
1 change: 1 addition & 0 deletions src/leetcode-cli
Submodule leetcode-cli added at 7f0d21
4 changes: 4 additions & 0 deletions src/utils/settingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ export interface IDescriptionConfiguration {
showInComment: boolean;
showInWebview: boolean;
}

export function getConfirmSubmitPrompt(): string {
return getWorkspaceConfiguration().get<string>("prompt.confirmSubmit", "");
}
17 changes: 17 additions & 0 deletions src/webview/leetCodeSubmissionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {

protected getWebviewContent(): string {
const styles: string = markdownEngine.getStyles();
// window.showInformationMessage(this.result.messages.join('\n'));
const title: string = `## ${this.result.messages[0]}`;
const messages: string[] = this.result.messages.slice(1).map((m: string) => `* ${m}`);
const sections: string[] = Object.keys(this.result)
Expand All @@ -36,10 +37,26 @@ class LeetCodeSubmissionProvider extends LeetCodeWebview {
this.result[key].join("\n"),
"```",
].join("\n"));

const indicatorPat: RegExp = /[ \(/]{1}([\d.]+( ms| %| MB)?)/gm;
let orderedindIcators: string = "";
if (this.result.messages[0] == 'Accepted') {
let indicators: string[] = []
const msgs: string = messages.join('\n');
let indicator: RegExpExecArray | null = indicatorPat.exec(msgs);
while (indicator != null) {
indicators.push(indicator[1].replace(' ', ''));
indicator = indicatorPat.exec(msgs);
}
orderedindIcators = '* ' + [indicators[0] + ': ', indicators[3] + `(${indicators[2]})`, indicators[4] + `(${indicators[5]})`,].join(' ') + '; ';
}
orderedindIcators += '\n';

const body: string = markdownEngine.render([
title,
...messages,
...sections,
orderedindIcators
].join("\n"));
return `
<!DOCTYPE html>
Expand Down

0 comments on commit 7dffcc4

Please sign in to comment.