Skip to content

Commit a9e799b

Browse files
authored
Merge pull request #66 from ccagml/main
2.4.1
2 parents 8361e0f + 9ce5e50 commit a9e799b

File tree

11 files changed

+459
-186
lines changed

11 files changed

+459
-186
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.4.1
2+
3+
- 简易 remark 功能, 用于回忆思考过程? 后续需要用这个数据生成文章
4+
15
## version 2.3.2
26

37
- WC320 数据

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [新增区块测试用例](#区块测试用例)
2525
- [新增搬砖功能(重复练习?)](#搬砖功能的说明)
2626
- [状态栏增加简易计时器](#状态栏增加简易计时器)
27+
- [新增一个 remark 功能](#新增在工作目录存放数据)
2728

2829
# 关于本项目
2930

@@ -100,6 +101,10 @@
100101
> > .lcpr_data/ 存数据
101102
> >
102103
> > > bricks.json
104+
> >
105+
> > > remark 备注数据
106+
> > >
107+
> > > > qid 备注 remark 数据
103108
104109
### bricks.json 存放格式
105110

package.json

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
5-
"version": "2.3.2",
5+
"version": "2.4.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -184,41 +184,43 @@
184184
"icon": "$(sort-precedence)"
185185
},
186186
{
187-
"command": "mywiki.commentcreateNote",
188-
"title": "Create Note",
189-
"enablement": "!commentIsEmpty"
187+
"command": "lcpr.remarkCreateNote",
188+
"title": "Create Note"
190189
},
191190
{
192-
"command": "mywiki.commentreplyNote",
193-
"title": "Reply",
194-
"enablement": "!commentIsEmpty"
191+
"command": "lcpr.remarkClose",
192+
"title": "关闭?"
195193
},
196194
{
197-
"command": "mywiki.commenteditNote",
198-
"title": "Edit",
195+
"command": "lcpr.remarkReplyNote",
196+
"title": "New Note"
197+
},
198+
{
199+
"command": "lcpr.remarkEditNote",
200+
"title": "Edit Note",
199201
"icon": {
200202
"dark": "resources/edit_inverse.svg",
201203
"light": "resources/edit.svg"
202204
}
203205
},
204206
{
205-
"command": "mywiki.commentdeleteNoteComment",
206-
"title": "Delete",
207+
"command": "lcpr.remarkDeleteNoteComment",
208+
"title": "Delete Note",
207209
"icon": {
208210
"dark": "resources/close_inverse.svg",
209211
"light": "resources/close.svg"
210212
}
211213
},
212214
{
213-
"command": "mywiki.commentsaveNote",
214-
"title": "Save"
215+
"command": "lcpr.remarkSaveNote",
216+
"title": "Save Note"
215217
},
216218
{
217-
"command": "mywiki.commentcancelsaveNote",
218-
"title": "Cancel"
219+
"command": "lcpr.remarkCancelsaveNote",
220+
"title": "Cancel Note"
219221
},
220222
{
221-
"command": "mywiki.commentdispose",
223+
"command": "lcpr.remarkDispose",
222224
"title": "Remove All Notes"
223225
}
224226
],
@@ -246,53 +248,54 @@
246248
"menus": {
247249
"commandPalette": [
248250
{
249-
"command": "mywiki.commentcreateNote",
250-
"when": "false"
251+
"command": "lcpr.remarkCreateNote",
252+
"when": "true"
251253
},
252254
{
253-
"command": "mywiki.commentreplyNote",
254-
"when": "false"
255+
"command": "lcpr.remarkReplyNote",
256+
"when": "true"
255257
},
256258
{
257-
"command": "mywiki.commentdeleteNoteComment",
258-
"when": "false"
259+
"command": "lcpr.remarkDeleteNoteComment",
260+
"when": "true"
261+
}
262+
],
263+
"comments/commentThread/title": [
264+
{
265+
"command": "lcpr.remarkClose",
266+
"group": "inline",
267+
"when": "commentController == comment-sample"
259268
}
260269
],
261-
"comments/commentThread/title": [],
262270
"comments/commentThread/context": [
263271
{
264-
"command": "mywiki.commentcreateNote",
272+
"command": "lcpr.remarkCreateNote",
265273
"group": "inline",
266274
"when": "commentController == comment-sample && commentThreadIsEmpty"
267275
},
268276
{
269-
"command": "mywiki.commentreplyNote",
277+
"command": "lcpr.remarkReplyNote",
270278
"group": "inline",
271279
"when": "commentController == comment-sample && !commentThreadIsEmpty"
272280
}
273281
],
274282
"comments/comment/title": [
275283
{
276-
"command": "mywiki.commenteditNote",
284+
"command": "lcpr.remarkEditNote",
277285
"group": "group@1",
278286
"when": "commentController == comment-sample"
279287
},
280288
{
281-
"command": "mywiki.commentdeleteNoteComment",
289+
"command": "lcpr.remarkDeleteNoteComment",
282290
"group": "group@2",
283291
"when": "commentController == comment-sample && comment == canDelete"
284292
}
285293
],
286294
"comments/comment/context": [
287295
{
288-
"command": "mywiki.commentcancelsaveNote",
296+
"command": "lcpr.remarkSaveNote",
289297
"group": "inline@1",
290298
"when": "commentController == comment-sample"
291-
},
292-
{
293-
"command": "mywiki.commentsaveNote",
294-
"group": "inline@2",
295-
"when": "commentController == comment-sample"
296299
}
297300
],
298301
"view/title": [

src/controller/RemarkController.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Filename: /home/cc/vscode-leetcode-problem-rating/src/controller/RemarkController.ts
3+
* Path: /home/cc/vscode-leetcode-problem-rating
4+
* Created Date: Monday, November 28th 2022, 3:29:37 pm
5+
* Author: ccagml
6+
*
7+
* Copyright (c) 2022 ccagml . All rights reserved.
8+
*/
9+
10+
import { CommentReply, Disposable, TextDocument } from "vscode";
11+
import { RemarkComment } from "../model/Model";
12+
import { remarkService } from "../service/RemarkService";
13+
14+
// 视图控制器
15+
class RemarkController implements Disposable {
16+
public dispose(): void {}
17+
18+
public remarkClose(a) {
19+
remarkService.remarkClose(a);
20+
}
21+
22+
public remarkCreateNote(reply: CommentReply) {
23+
remarkService.remarkCreateNote(reply);
24+
}
25+
26+
public remarkReplyNote(reply: CommentReply) {
27+
remarkService.remarkReplyNote(reply);
28+
}
29+
30+
public remarkDeleteNoteComment(comment: RemarkComment) {
31+
remarkService.remarkDeleteNoteComment(comment);
32+
}
33+
public async startRemark(document: TextDocument) {
34+
await remarkService.startRemark(document);
35+
}
36+
37+
public remarkCancelsaveNote(comment: RemarkComment) {
38+
remarkService.remarkCancelsaveNote(comment);
39+
}
40+
public remarkSaveNote(comment: RemarkComment) {
41+
remarkService.remarkSaveNote(comment);
42+
}
43+
public remarkEditNote(comment: RemarkComment) {
44+
remarkService.remarkEditNote(comment);
45+
}
46+
}
47+
48+
export const remarkController: RemarkController = new RemarkController();

src/controller/TreeViewController.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,10 @@ class TreeViewController implements Disposable {
13911391
return this.getNodeById(this.qidToFid.get(qid) || "");
13921392
}
13931393

1394+
public getQidByFid(id: string) {
1395+
return this.fidToQid.get(id);
1396+
}
1397+
13941398
public getFavoriteNodes(): NodeModel[] {
13951399
const res: NodeModel[] = [];
13961400
for (const node of this.explorerNodeMap.values()) {

src/dao/remarkDao.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// > workspace/ 工作目录
2+
// >
3+
// > > .lcpr_data/ 存数据
4+
// > >
5+
// > > > remake/ 备注
6+
// > > >
7+
// > > > > 题目内部编号.json 根据 qid 备注的信息
8+
// > >
9+
10+
import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils";
11+
import { useWsl, toWinPath } from "../utils/SystemUtils";
12+
import * as path from "path";
13+
import * as fse from "fs-extra";
14+
15+
class RemarkDao {
16+
version = 1;
17+
public async get_remark_dir_path() {
18+
const language: string | undefined = await fetchProblemLanguage();
19+
if (!language) {
20+
return;
21+
}
22+
const workspaceFolder: string = await selectWorkspaceFolder(false);
23+
if (!workspaceFolder) {
24+
return;
25+
}
26+
let lcpr_data_path: string = path.join(workspaceFolder, ".lcpr_data");
27+
await fse.ensureDir(lcpr_data_path);
28+
29+
let remark_dir: string = path.join(lcpr_data_path, "remark");
30+
await fse.ensureDir(remark_dir);
31+
32+
remark_dir = useWsl() ? await toWinPath(remark_dir) : remark_dir;
33+
return remark_dir;
34+
}
35+
public async init() {
36+
let lcpr_data_path = await this.get_remark_dir_path();
37+
if (!lcpr_data_path) {
38+
return;
39+
}
40+
}
41+
42+
private async getQidPath(qid: string) {
43+
let remark_dir = await this.get_remark_dir_path();
44+
if (!remark_dir) {
45+
return;
46+
}
47+
if (!qid) {
48+
return;
49+
}
50+
let qid_path: string = path.join(remark_dir, qid);
51+
qid_path = useWsl() ? await toWinPath(qid_path) : qid_path;
52+
return qid_path;
53+
}
54+
55+
private async _write_data(qid: string, data: object) {
56+
let qid_data_path = await this.getQidPath(qid);
57+
if (!qid_data_path) {
58+
return;
59+
}
60+
return await fse.writeFile(qid_data_path, JSON.stringify(data));
61+
}
62+
63+
private async _read_data(qid: string) {
64+
let qid_data_path = await this.getQidPath(qid);
65+
if (!qid_data_path) {
66+
return;
67+
}
68+
69+
if (!(await fse.pathExists(qid_data_path))) {
70+
return {};
71+
}
72+
let temp_data = await fse.readFile(qid_data_path, "utf8");
73+
return JSON.parse(temp_data) || {};
74+
}
75+
76+
public async getInfoByQid(qid: string) {
77+
let all_remark = await this._read_data(qid);
78+
return all_remark || {};
79+
}
80+
public async setInfoByQid(qid: string, info) {
81+
await this._write_data(qid, info);
82+
}
83+
}
84+
85+
export const remarkDao: RemarkDao = new RemarkDao();

0 commit comments

Comments
 (0)