Skip to content

Commit ca3cda5

Browse files
committed
检查监听
1 parent 608a74b commit ca3cda5

File tree

6 files changed

+140
-29
lines changed

6 files changed

+140
-29
lines changed

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,15 @@
7171
"trace": true,
7272
"preLaunchTask": "window_npm"
7373
},
74+
{
75+
"name": "debugcheck",
76+
"program": "${workspaceFolder}/check_list_case.js",
77+
"request": "launch",
78+
"sourceMaps": true,
79+
"outFiles": [
80+
"${workspaceRoot}/check_list_case.js"
81+
],
82+
"type": "node"
83+
},
7484
]
7585
}

c.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tsc ./check_list_case.ts
2+
node ./check_list_case.js
3+
rm -rf ./check_list_case.js

check_list_case.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// const fs = require("fs");
2+
// const path = require("path");
3+
4+
// // 指定要遍历的目录路径
5+
// const directoryPath = "./src";
6+
7+
// // 递归遍历目录并获取所有.ts文件
8+
// function getTsFiles(dir) {
9+
// const files = fs.readdirSync(dir);
10+
// const tsFiles: any = [];
11+
12+
// files.forEach((file) => {
13+
// const filePath = path.join(dir, file);
14+
// const stat = fs.statSync(filePath);
15+
16+
// if (stat.isDirectory()) {
17+
// tsFiles.push(...getTsFiles(filePath)); // 递归处理子目录
18+
// } else if (file.endsWith(".ts")) {
19+
// tsFiles.push(filePath);
20+
// }
21+
// });
22+
23+
// return tsFiles;
24+
// }
25+
26+
// const tsFiles = getTsFiles(directoryPath);
27+
28+
// console.log("所有.ts文件:", tsFiles);
29+
const fs = require("fs");
30+
const path = require("path");
31+
32+
// 指定要遍历的目录路径
33+
const directoryPath = "./src";
34+
35+
// 递归遍历目录并获取所有.ts文件
36+
function getTsFiles(dir) {
37+
const files = fs.readdirSync(dir);
38+
const tsFiles: any = [];
39+
40+
files.forEach((file) => {
41+
const filePath = path.join(dir, file);
42+
const stat = fs.statSync(filePath);
43+
44+
if (stat.isDirectory()) {
45+
tsFiles.push(...getTsFiles(filePath)); // 递归处理子目录
46+
} else if (file.endsWith(".ts")) {
47+
tsFiles.push(filePath);
48+
}
49+
});
50+
51+
return tsFiles;
52+
}
53+
54+
// 读取文件内容并查找listNotificationInterests函数
55+
function findListNotificationInterestsContent(filePath) {
56+
const fileContent = fs.readFileSync(filePath, "utf8");
57+
const regex = /listNotificationInterests\(\): string\[\] {\s*return\s*\[([\s\S]*?)\s*\];/m;
58+
const matches = fileContent.match(regex);
59+
60+
if (matches && matches[1]) {
61+
// 获取返回内容
62+
const content = matches[1]
63+
.replace(/['"]+/g, "") // 去除引号
64+
.split(",") // 分割成数组
65+
.map((item) => item.trim()); // 移除空白字符
66+
67+
return content;
68+
}
69+
70+
return null;
71+
}
72+
73+
const tsFiles = getTsFiles(directoryPath);
74+
75+
// 读取文件内容并查找listNotificationInterests函数
76+
function findListContent(filePath) {
77+
const fileContent = fs.readFileSync(filePath, "utf8");
78+
// 匹配 handleNotification 函数
79+
const handleNotificationRegex = /async\s+handleNotification\s*\(.*\)\s*{([\s\S]*?)}/;
80+
const handleNotificationMatches = handleNotificationRegex.exec(fileContent);
81+
82+
if (handleNotificationMatches && handleNotificationMatches[1]) {
83+
const handleNotificationContent = handleNotificationMatches[1];
84+
85+
let caseRegex = /case\s+.*?:([\s\S]*?)(?=case\s+|$)/g;
86+
let caseMatches = handleNotificationContent.match(caseRegex);
87+
let new_result: any = [];
88+
if (caseMatches) {
89+
caseMatches.forEach(function (caseMatch) {
90+
let trimmedCaseMatch = caseMatch.match(/case\s+(.*?):([\s\S]*)/);
91+
if (trimmedCaseMatch) {
92+
new_result.push(trimmedCaseMatch[1]);
93+
}
94+
95+
// if (trimmedCaseMatch && !content.includes(trimmedCaseMatch[1])) {
96+
// console.log(filePath, "没有:", trimmedCaseMatch[1], "\n");
97+
// }
98+
});
99+
}
100+
return new_result;
101+
}
102+
}
103+
104+
tsFiles.forEach((filePath) => {
105+
const all_listen = findListNotificationInterestsContent(filePath);
106+
let all_case = findListContent(filePath);
107+
if (all_case) {
108+
all_case.forEach((element) => {
109+
if (!all_listen.includes(element)) {
110+
console.log(filePath, "没有:", element, "\n");
111+
}
112+
});
113+
}
114+
});

src/controller/TreeViewController.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -924,25 +924,7 @@ class TreeViewController implements Disposable {
924924
this.searchSet = new Map<string, ISearchSet>();
925925
}
926926

927-
public checkSubmit(e: ISubmitEvent) {
928-
if (e.sub_type == "submit" && e.accepted) {
929-
const day_start = systemUtils.getDayStart(); //获取当天零点的时间
930-
const day_end = systemUtils.getDayEnd(); //获取当天23:59:59的时间
931-
let need_get_today: boolean = false;
932-
this.searchSet.forEach((element) => {
933-
if (element.type == SearchSetType.Day) {
934-
if (day_start <= element.time && element.time <= day_end) {
935-
if (e.fid == element.value) {
936-
need_get_today = true;
937-
}
938-
}
939-
}
940-
});
941-
if (need_get_today) {
942-
BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
943-
}
944-
}
945-
}
927+
946928

947929
public async refreshCheck(): Promise<void> {
948930
let sbp = BABA.getProxy(BabaStr.StatusBarProxy);

src/todayData/TodayDataModule.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { BABAMediator, BABAProxy, BabaStr, BaseCC, BABA } from "../BABA";
11-
import { OutPutType } from "../model/ConstDefind";
11+
import { ISubmitEvent, OutPutType } from "../model/ConstDefind";
1212
import { ITodayDataResponse } from "../model/TreeNodeModel";
1313
import { isUseEndpointTranslation } from "../utils/ConfigUtils";
1414
import { promptForSignIn, ShowMessage } from "../utils/OutputUtils";
@@ -39,6 +39,13 @@ class TodayData {
3939
BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
4040
}
4141
}
42+
public async checkSubmit(e: ISubmitEvent) {
43+
if (e.sub_type == "submit" && e.accepted) {
44+
if (this.getFidInfo(e.fid)) {
45+
await BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
46+
}
47+
}
48+
}
4249
}
4350

4451
const todayData: TodayData = new TodayData();
@@ -99,7 +106,7 @@ export class TodayDataMediator extends BABAMediator {
99106
}
100107

101108
listNotificationInterests(): string[] {
102-
return [BabaStr.VSCODE_DISPOST, BabaStr.StartReadData];
109+
return [BabaStr.VSCODE_DISPOST, BabaStr.StartReadData, BabaStr.CommitResult_showFinish];
103110
}
104111
async handleNotification(_notification: BaseCC.BaseCC.INotification) {
105112
switch (_notification.getName()) {
@@ -108,6 +115,9 @@ export class TodayDataMediator extends BABAMediator {
108115
case BabaStr.StartReadData:
109116
await BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
110117
break;
118+
case BabaStr.CommitResult_showFinish:
119+
todayData.checkSubmit(_notification.getBody());
120+
break;
111121
default:
112122
break;
113123
}

src/treeData/TreeDataService.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ export class TreeDataService implements vscode.TreeDataProvider<TreeNodeModel> {
4040
this.context = context;
4141
}
4242

43-
public async checkSubmit(e: ISubmitEvent) {
44-
await treeViewController.checkSubmit(e);
45-
}
46-
4743
public cleanUserScore() {
4844
treeViewController.clearUserScore();
4945
}
@@ -388,7 +384,6 @@ export class TreeDataMediator extends BABAMediator {
388384
BabaStr.BABACMD_refresh,
389385
BabaStr.InitFile,
390386
BabaStr.TreeData_cleanUserScore,
391-
BabaStr.CommitResult_showFinish,
392387
BabaStr.TreeData_switchEndpoint,
393388
BabaStr.BABACMD_previewProblem,
394389
BabaStr.BABACMD_showProblem,
@@ -443,9 +438,6 @@ export class TreeDataMediator extends BABAMediator {
443438
treeDataService.cleanUserScore();
444439
break;
445440

446-
case BabaStr.CommitResult_showFinish:
447-
treeDataService.checkSubmit(body);
448-
break;
449441
case BabaStr.TreeData_switchEndpoint:
450442
treeDataService.switchEndpoint();
451443
case BabaStr.BABACMD_previewProblem:

0 commit comments

Comments
 (0)