Skip to content

2.4.1 #66

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
merged 3 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 2.4.1

- 简易 remark 功能, 用于回忆思考过程? 后续需要用这个数据生成文章

## version 2.3.2

- WC320 数据
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- [新增区块测试用例](#区块测试用例)
- [新增搬砖功能(重复练习?)](#搬砖功能的说明)
- [状态栏增加简易计时器](#状态栏增加简易计时器)
- [新增一个 remark 功能](#新增在工作目录存放数据)

# 关于本项目

Expand Down Expand Up @@ -100,6 +101,10 @@
> > .lcpr_data/ 存数据
> >
> > > bricks.json
> >
> > > remark 备注数据
> > >
> > > > qid 备注 remark 数据

### bricks.json 存放格式

Expand Down
69 changes: 36 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
"version": "2.3.2",
"version": "2.4.1",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -184,41 +184,43 @@
"icon": "$(sort-precedence)"
},
{
"command": "mywiki.commentcreateNote",
"title": "Create Note",
"enablement": "!commentIsEmpty"
"command": "lcpr.remarkCreateNote",
"title": "Create Note"
},
{
"command": "mywiki.commentreplyNote",
"title": "Reply",
"enablement": "!commentIsEmpty"
"command": "lcpr.remarkClose",
"title": "关闭?"
},
{
"command": "mywiki.commenteditNote",
"title": "Edit",
"command": "lcpr.remarkReplyNote",
"title": "New Note"
},
{
"command": "lcpr.remarkEditNote",
"title": "Edit Note",
"icon": {
"dark": "resources/edit_inverse.svg",
"light": "resources/edit.svg"
}
},
{
"command": "mywiki.commentdeleteNoteComment",
"title": "Delete",
"command": "lcpr.remarkDeleteNoteComment",
"title": "Delete Note",
"icon": {
"dark": "resources/close_inverse.svg",
"light": "resources/close.svg"
}
},
{
"command": "mywiki.commentsaveNote",
"title": "Save"
"command": "lcpr.remarkSaveNote",
"title": "Save Note"
},
{
"command": "mywiki.commentcancelsaveNote",
"title": "Cancel"
"command": "lcpr.remarkCancelsaveNote",
"title": "Cancel Note"
},
{
"command": "mywiki.commentdispose",
"command": "lcpr.remarkDispose",
"title": "Remove All Notes"
}
],
Expand Down Expand Up @@ -246,53 +248,54 @@
"menus": {
"commandPalette": [
{
"command": "mywiki.commentcreateNote",
"when": "false"
"command": "lcpr.remarkCreateNote",
"when": "true"
},
{
"command": "mywiki.commentreplyNote",
"when": "false"
"command": "lcpr.remarkReplyNote",
"when": "true"
},
{
"command": "mywiki.commentdeleteNoteComment",
"when": "false"
"command": "lcpr.remarkDeleteNoteComment",
"when": "true"
}
],
"comments/commentThread/title": [
{
"command": "lcpr.remarkClose",
"group": "inline",
"when": "commentController == comment-sample"
}
],
"comments/commentThread/title": [],
"comments/commentThread/context": [
{
"command": "mywiki.commentcreateNote",
"command": "lcpr.remarkCreateNote",
"group": "inline",
"when": "commentController == comment-sample && commentThreadIsEmpty"
},
{
"command": "mywiki.commentreplyNote",
"command": "lcpr.remarkReplyNote",
"group": "inline",
"when": "commentController == comment-sample && !commentThreadIsEmpty"
}
],
"comments/comment/title": [
{
"command": "mywiki.commenteditNote",
"command": "lcpr.remarkEditNote",
"group": "group@1",
"when": "commentController == comment-sample"
},
{
"command": "mywiki.commentdeleteNoteComment",
"command": "lcpr.remarkDeleteNoteComment",
"group": "group@2",
"when": "commentController == comment-sample && comment == canDelete"
}
],
"comments/comment/context": [
{
"command": "mywiki.commentcancelsaveNote",
"command": "lcpr.remarkSaveNote",
"group": "inline@1",
"when": "commentController == comment-sample"
},
{
"command": "mywiki.commentsaveNote",
"group": "inline@2",
"when": "commentController == comment-sample"
}
],
"view/title": [
Expand Down
48 changes: 48 additions & 0 deletions src/controller/RemarkController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Filename: /home/cc/vscode-leetcode-problem-rating/src/controller/RemarkController.ts
* Path: /home/cc/vscode-leetcode-problem-rating
* Created Date: Monday, November 28th 2022, 3:29:37 pm
* Author: ccagml
*
* Copyright (c) 2022 ccagml . All rights reserved.
*/

import { CommentReply, Disposable, TextDocument } from "vscode";
import { RemarkComment } from "../model/Model";
import { remarkService } from "../service/RemarkService";

// 视图控制器
class RemarkController implements Disposable {
public dispose(): void {}

public remarkClose(a) {
remarkService.remarkClose(a);
}

public remarkCreateNote(reply: CommentReply) {
remarkService.remarkCreateNote(reply);
}

public remarkReplyNote(reply: CommentReply) {
remarkService.remarkReplyNote(reply);
}

public remarkDeleteNoteComment(comment: RemarkComment) {
remarkService.remarkDeleteNoteComment(comment);
}
public async startRemark(document: TextDocument) {
await remarkService.startRemark(document);
}

public remarkCancelsaveNote(comment: RemarkComment) {
remarkService.remarkCancelsaveNote(comment);
}
public remarkSaveNote(comment: RemarkComment) {
remarkService.remarkSaveNote(comment);
}
public remarkEditNote(comment: RemarkComment) {
remarkService.remarkEditNote(comment);
}
}

export const remarkController: RemarkController = new RemarkController();
4 changes: 4 additions & 0 deletions src/controller/TreeViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,10 @@ class TreeViewController implements Disposable {
return this.getNodeById(this.qidToFid.get(qid) || "");
}

public getQidByFid(id: string) {
return this.fidToQid.get(id);
}

public getFavoriteNodes(): NodeModel[] {
const res: NodeModel[] = [];
for (const node of this.explorerNodeMap.values()) {
Expand Down
85 changes: 85 additions & 0 deletions src/dao/remarkDao.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// > workspace/ 工作目录
// >
// > > .lcpr_data/ 存数据
// > >
// > > > remake/ 备注
// > > >
// > > > > 题目内部编号.json 根据 qid 备注的信息
// > >

import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils";
import { useWsl, toWinPath } from "../utils/SystemUtils";
import * as path from "path";
import * as fse from "fs-extra";

class RemarkDao {
version = 1;
public async get_remark_dir_path() {
const language: string | undefined = await fetchProblemLanguage();
if (!language) {
return;
}
const workspaceFolder: string = await selectWorkspaceFolder(false);
if (!workspaceFolder) {
return;
}
let lcpr_data_path: string = path.join(workspaceFolder, ".lcpr_data");
await fse.ensureDir(lcpr_data_path);

let remark_dir: string = path.join(lcpr_data_path, "remark");
await fse.ensureDir(remark_dir);

remark_dir = useWsl() ? await toWinPath(remark_dir) : remark_dir;
return remark_dir;
}
public async init() {
let lcpr_data_path = await this.get_remark_dir_path();
if (!lcpr_data_path) {
return;
}
}

private async getQidPath(qid: string) {
let remark_dir = await this.get_remark_dir_path();
if (!remark_dir) {
return;
}
if (!qid) {
return;
}
let qid_path: string = path.join(remark_dir, qid);
qid_path = useWsl() ? await toWinPath(qid_path) : qid_path;
return qid_path;
}

private async _write_data(qid: string, data: object) {
let qid_data_path = await this.getQidPath(qid);
if (!qid_data_path) {
return;
}
return await fse.writeFile(qid_data_path, JSON.stringify(data));
}

private async _read_data(qid: string) {
let qid_data_path = await this.getQidPath(qid);
if (!qid_data_path) {
return;
}

if (!(await fse.pathExists(qid_data_path))) {
return {};
}
let temp_data = await fse.readFile(qid_data_path, "utf8");
return JSON.parse(temp_data) || {};
}

public async getInfoByQid(qid: string) {
let all_remark = await this._read_data(qid);
return all_remark || {};
}
public async setInfoByQid(qid: string, info) {
await this._write_data(qid, info);
}
}

export const remarkDao: RemarkDao = new RemarkDao();
Loading