Skip to content

Commit 6bf5f51

Browse files
authored
Merge pull request #253 from ccagml/mvc
重构 log 输出 和 remark 代码, 减少代码耦合
2 parents 1731945 + e263469 commit 6bf5f51

17 files changed

+201
-157
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# version 3.1.1
2+
3+
- 重构 log 输出 和 remark 代码, 减少代码耦合
4+
15
# version 2.19.19
26

37
- win10 上 python3 调试 sys.argv 会忽略空字符串参数

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "2.19.19",
5+
"version": "3.1.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",

src/BABA.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ export enum BabaStr {
2828
statusBar_update_status = "statusBar_update_status",
2929
statusBar_update = "statusBar_update",
3030
statusBar_update_UserContestInfo = "statusBar_update_UserContestInfo",
31+
InitAll = "InitAll",
32+
LogOutputProxy = "LogOutputProxy",
33+
LogOutputMediator = "LogOutputMediator",
34+
Remark_remarkCreateNote = "Remark_remarkCreateNote",
35+
Remark_remarkClose = "Remark_remarkClose",
36+
Remark_remarkReplyNote = "Remark_remarkReplyNote",
37+
Remark_remarkDeleteNoteComment = "Remark_remarkDeleteNoteComment",
38+
Remark_remarkCancelsaveNote = "Remark_remarkCancelsaveNote",
39+
Remark_remarkSaveNote = "Remark_remarkSaveNote",
40+
Remark_remarkEditNote = "Remark_remarkEditNote",
41+
Remark_startRemark = "Remark_startRemark",
42+
Remark_includeTemplates = "Remark_includeTemplates",
3143
}
3244

3345
export class BABA {

src/controller/LoginController.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as systemUtils from "../utils/SystemUtils";
1212
import { executeService } from "../service/ExecuteService";
1313
import { OutPutType, Endpoint, IQuickItemEx, loginArgsMapping, UserStatus } from "../model/Model";
1414
import { createEnvOption } from "../utils/CliUtils";
15-
import { logOutput, promptForOpenOutputChannel } from "../utils/OutputUtils";
15+
import { promptForOpenOutputChannel } from "../utils/OutputUtils";
1616
import { eventService } from "../service/EventService";
1717
import { window, QuickPickOptions, ProgressLocation, Progress } from "vscode";
1818
import { treeDataService } from "../service/TreeDataService";
@@ -59,7 +59,8 @@ class LoginContorller {
5959
childProc.stdout?.on("data", async (data: string | Buffer) => {
6060
data = data.toString();
6161
// vscode.window.showInformationMessage(`cc login msg ${data}.`);
62-
logOutput.append(data);
62+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().append(data);
63+
6364
if (data.includes("twoFactorCode")) {
6465
const twoFactor: string | undefined = await window.showInputBox({
6566
prompt: "Enter two-factor code.",
@@ -90,7 +91,9 @@ class LoginContorller {
9091
}
9192
});
9293

93-
childProc.stderr?.on("data", (data: string | Buffer) => logOutput.append(data.toString()));
94+
childProc.stderr?.on("data", (data: string | Buffer) => {
95+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().append(data.toString());
96+
});
9497
childProc.on("error", reject);
9598

9699
const name: string | undefined = await window.showInputBox({

src/controller/MainController.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import * as systemUtils from "../utils/SystemUtils";
1111
import { executeService } from "../service/ExecuteService";
1212
import { ExtensionContext } from "vscode";
1313
import { treeDataService } from "../service/TreeDataService";
14-
import { logOutput } from "../utils/OutputUtils";
1514
import { extensionState } from "../utils/problemUtils";
16-
import { nlsUtils } from "../utils/NlsUtils";
1715

1816
import * as fse from "fs-extra";
17+
import { BABA, BabaStr } from "../BABA";
1918
// 做杂活
2019
class MainContorller {
2120
constructor() {}
@@ -58,7 +57,7 @@ class MainContorller {
5857
cur_version_num *= 100;
5958
cur_version_num += Number(e);
6059
});
61-
logOutput.setLCPTCTX("version", cur_version_num);
60+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().setLCPTCTX("version", cur_version_num);
6261
}
6362

6463
// 初始化上下文
@@ -68,7 +67,6 @@ class MainContorller {
6867
* @param {ExtensionContext} context - ExtensionContext
6968
*/
7069
public initialize(context: ExtensionContext) {
71-
nlsUtils.init();
7270
this.setGlobal(context);
7371
treeDataService.initialize(context);
7472
extensionState.context = context;

src/controller/RemarkController.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/controller/TreeViewController.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import { ISearchSet } from "../model/Model";
5858
import { previewService } from "../service/PreviewService";
5959
import { executeService } from "../service/ExecuteService";
6060
import { getNodeIdFromFile } from "../utils/SystemUtils";
61-
import { logOutput, promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/OutputUtils";
61+
import { promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/OutputUtils";
6262
import { treeDataService } from "../service/TreeDataService";
6363
import {
6464
genFileExt,
@@ -689,7 +689,7 @@ class TreeViewController implements Disposable {
689689
);
690690
solutionService.show(solution);
691691
} catch (error) {
692-
logOutput.appendLine(error.toString());
692+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
693693
await promptForOpenOutputChannel("Failed to fetch the top voted solution. 请查看控制台信息~", OutPutType.error);
694694
}
695695
}
@@ -701,7 +701,7 @@ class TreeViewController implements Disposable {
701701
// solutionService.show(solution);
702702
// debugContorller.try_get_diy_param();
703703
} catch (error) {
704-
logOutput.appendLine(error.toString());
704+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
705705
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);
706706
}
707707
}
@@ -840,7 +840,7 @@ class TreeViewController implements Disposable {
840840
if (finalPath) {
841841
finalPath = await this.resolveRelativePath(finalPath, node, language);
842842
if (!finalPath) {
843-
logOutput.appendLine("Showing problem canceled by user.");
843+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine("Showing problem canceled by user.");
844844
return;
845845
}
846846
}
@@ -985,7 +985,7 @@ class TreeViewController implements Disposable {
985985
const tt: userContestRanKingBase = Object.assign({}, userContestRankingObj, query_result.userContestRanking);
986986
eventService.emit("searchUserContest", tt);
987987
} catch (error) {
988-
logOutput.appendLine(error.toString());
988+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
989989
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);
990990
}
991991
}
@@ -1014,7 +1014,7 @@ class TreeViewController implements Disposable {
10141014
await bricksDataService.refresh();
10151015
}
10161016
} catch (error) {
1017-
logOutput.appendLine(error.toString());
1017+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
10181018
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);
10191019
}
10201020
}
@@ -1097,7 +1097,7 @@ class TreeViewController implements Disposable {
10971097
return getDayNowStr();
10981098
default:
10991099
errorMsg = `The config '${placeholder}' is not supported.`;
1100-
logOutput.appendLine(errorMsg);
1100+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(errorMsg);
11011101
throw new Error(errorMsg);
11021102
}
11031103
});

src/debugex/debugCpp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as fse from "fs-extra";
22
import * as path from "path";
33
import * as vscode from "vscode";
4-
import { logOutput } from "../utils/OutputUtils";
54

65
import { executeCommand } from "../utils/CliUtils";
76
import {
@@ -18,6 +17,7 @@ import { isWindows } from "../utils/SystemUtils";
1817

1918
import { DebugBase } from "../debugex/debugBase";
2019
import { debugArgDao } from "../dao/debugArgDao";
20+
import { BABA, BabaStr } from "../BABA";
2121

2222
function getGdbDefaultConfig(): IDebugConfig {
2323
return {
@@ -396,8 +396,8 @@ class DebugCpp extends DebugBase {
396396
);
397397
} catch (e) {
398398
vscode.window.showErrorMessage(e);
399-
logOutput.append(e.stack);
400-
logOutput.show();
399+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().append(e.stack);
400+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().show();
401401
return;
402402
}
403403

@@ -450,8 +450,8 @@ class DebugCpp extends DebugBase {
450450
);
451451
} catch (e) {
452452
vscode.window.showErrorMessage(e);
453-
logOutput.append(e.stack);
454-
logOutput.show();
453+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().append(e.stack);
454+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().show();
455455
return;
456456
}
457457

src/extension.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { treeViewController } from "./controller/TreeViewController";
1313
import { NodeModel } from "./model/NodeModel";
1414
import { treeDataService } from "./service/TreeDataService";
1515
import { treeItemDecorationService } from "./service/TreeItemDecorationService";
16-
import { logOutput, promptForOpenOutputChannel } from "./utils/OutputUtils";
16+
import { promptForOpenOutputChannel } from "./utils/OutputUtils";
1717
import { executeService } from "./service/ExecuteService";
1818
import { eventController } from "./controller/EventController";
1919
import { previewService } from "./service/PreviewService";
@@ -26,12 +26,12 @@ import { getLeetCodeEndpoint } from "./utils/ConfigUtils";
2626
import { BricksType, OutPutType, RemarkComment } from "./model/Model";
2727
import { bricksDataService } from "./service/BricksDataService";
2828
import { bricksViewController } from "./controller/BricksViewController";
29-
import { remarkController } from "./controller/RemarkController";
3029
import { debugContorller } from "./controller/DebugController";
3130
import { BABA, BabaStr } from "./BABA";
3231
import { StatusBarTimeMediator, StatusBarTimeProxy } from "./statusBarTime/StatusBarTimeModule";
3332
import { StatusBarMediator, StatusBarProxy } from "./statusBar/StatusBarModule";
34-
import { RemarkProxy, RemarkMediator } from "./service/RemarkService";
33+
import { LogOutputMediator, LogOutputProxy } from "./logOutput/logOutputModule";
34+
import { RemarkMediator, RemarkProxy } from "./remark/RemarkServiceModule";
3535

3636
//==================================BABA========================================
3737

@@ -52,8 +52,12 @@ export async function activate(context: ExtensionContext): Promise<void> {
5252
StatusBarMediator,
5353
RemarkProxy,
5454
RemarkMediator,
55+
LogOutputProxy,
56+
LogOutputMediator,
5557
]);
5658

59+
BABA.sendNotification(BabaStr.InitAll, context);
60+
5761
// 初始化控制器
5862
mainContorller.initialize(context);
5963
// 检查node环境
@@ -64,7 +68,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
6468

6569
// 资源管理
6670
context.subscriptions.push(
67-
logOutput,
6871
previewService,
6972
submissionService,
7073
solutionService,
@@ -133,31 +136,31 @@ export async function activate(context: ExtensionContext): Promise<void> {
133136
commands.registerCommand("lcpr.removeQidFromGroup", (node) => bricksViewController.removeQidFromGroup(node)),
134137

135138
commands.registerCommand("lcpr.remarkCreateNote", (reply: CommentReply) => {
136-
remarkController.remarkCreateNote(reply);
139+
BABA.sendNotification(BabaStr.Remark_remarkCreateNote, reply);
137140
}),
138141
commands.registerCommand("lcpr.remarkClose", (a) => {
139-
remarkController.remarkClose(a);
142+
BABA.sendNotification(BabaStr.Remark_remarkClose, a);
140143
}),
141144
commands.registerCommand("lcpr.remarkReplyNote", (reply: CommentReply) => {
142-
remarkController.remarkReplyNote(reply);
145+
BABA.sendNotification(BabaStr.Remark_remarkReplyNote, reply);
143146
}),
144147
commands.registerCommand("lcpr.remarkDeleteNoteComment", (comment: RemarkComment) => {
145-
remarkController.remarkDeleteNoteComment(comment);
148+
BABA.sendNotification(BabaStr.Remark_remarkDeleteNoteComment, comment);
146149
}),
147150
commands.registerCommand("lcpr.remarkCancelsaveNote", (comment: RemarkComment) => {
148-
remarkController.remarkCancelsaveNote(comment);
151+
BABA.sendNotification(BabaStr.Remark_remarkCancelsaveNote, comment);
149152
}),
150153
commands.registerCommand("lcpr.remarkSaveNote", (comment: RemarkComment) => {
151-
remarkController.remarkSaveNote(comment);
154+
BABA.sendNotification(BabaStr.Remark_remarkSaveNote, comment);
152155
}),
153156
commands.registerCommand("lcpr.remarkEditNote", (comment: RemarkComment) => {
154-
remarkController.remarkEditNote(comment);
157+
BABA.sendNotification(BabaStr.Remark_remarkEditNote, comment);
155158
}),
156159
commands.registerCommand("lcpr.startRemark", (document: TextDocument) => {
157-
remarkController.startRemark(document);
160+
BABA.sendNotification(BabaStr.Remark_startRemark, document);
158161
}),
159162
commands.registerCommand("lcpr.includeTemplates", (document: TextDocument) => {
160-
remarkController.includeTemplates(document);
163+
BABA.sendNotification(BabaStr.Remark_includeTemplates, document);
161164
}),
162165
commands.registerCommand("lcpr.simpleDebug", (document: TextDocument, testCase?) =>
163166
debugContorller.startDebug(document, testCase)
@@ -176,7 +179,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
176179
await loginContorller.getLoginStatus();
177180
await bricksViewController.initialize();
178181
} catch (error) {
179-
logOutput.appendLine(error.toString());
182+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
180183
promptForOpenOutputChannel(
181184
"Extension initialization failed. Please open output channel for details.",
182185
OutPutType.error

0 commit comments

Comments
 (0)