Skip to content

Commit b8550cd

Browse files
🔧 refactor(utils): 重构通知、本地化和工具类结构
- 【目录优化】 - 将工具类按功能拆分至独立目录 - 重新组织i18n、notification等模块目录结构 - 【通知优化】 - 重构NotificationHandler为通知管理系统 - 统一错误处理和消息提示机制 - 添加格式化参数支持 - 【本地化优化】 - 重构LocalizationManager为独立的i18n模块 - 简化消息格式化API - 统一本地化资源加载方式 - 【代码优化】 - 移除冗余工具类文件 - 优化错误处理和参数传递 - 统一API调用方式和错误处理 - 简化模块间依赖关系
1 parent db6ff67 commit b8550cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2218
-1004
lines changed

README.cursor.md

+311
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
项目结构总览
2+
这是一个 VSCode 扩展项目,主要用于 AI 辅助的代码提交信息生成、周报生成和代码审查。项目采用 TypeScript + React 技术栈开发。
3+
4+
5+
.
6+
├── CHANGELOG.md
7+
├── CHANGELOG.zh-CN.md
8+
├── commitlint.config.mjs
9+
├── dish-ai-commit-0.6.1.vsix
10+
├── dish-ai-commit-0.6.2.vsix
11+
├── eslint.config.mjs
12+
├── i18n
13+
│ ├── en.json
14+
│ └── zh-cn.json
15+
├── images
16+
│ ├── icon.svg
17+
│ └── logo.png
18+
├── license
19+
├── package.json
20+
├── package-lock.json
21+
├── pnpm-lock.yaml
22+
├── README.cursor.md
23+
├── README.md
24+
├── README.zh-CN.md
25+
├── src
26+
│ ├── ai
27+
│ │ ├── AIProviderFactory.ts
28+
│ │ ├── providers
29+
│ │ │ ├── BaseOpenAIProvider.ts
30+
│ │ │ ├── DashScopeProvider.ts
31+
│ │ │ ├── DeepseekAIProvider.ts
32+
│ │ │ ├── DoubaoProvider.ts
33+
│ │ │ ├── GeminiAIProvider.ts
34+
│ │ │ ├── OllamaProvider.ts
35+
│ │ │ ├── OpenAIProvider.ts
36+
│ │ │ ├── VscodeProvider.ts
37+
│ │ │ └── ZhipuAIProvider.ts
38+
│ │ ├── types.ts
39+
│ │ └── utils
40+
│ │ └── generateHelper.ts
41+
│ ├── commands
42+
│ │ ├── BaseCommand.ts
43+
│ │ ├── GenerateCommitCommand.ts
44+
│ │ ├── GenerateWeeklyReportCommand.ts
45+
│ │ ├── ReviewCodeCommand.ts
46+
│ │ └── SelectModelCommand.ts
47+
│ ├── commands.ts
48+
│ ├── config
49+
│ │ ├── ConfigGenerator.ts
50+
│ │ ├── ConfigSchema.ts
51+
│ │ ├── ConfigurationManager.ts
52+
│ │ ├── DefaultConfig.ts
53+
│ │ ├── generated
54+
│ │ │ └── configKeys.ts
55+
│ │ └── types.ts
56+
│ ├── constants.ts
57+
│ ├── extension.ts
58+
│ ├── prompt
59+
│ │ ├── codeReview.ts
60+
│ │ ├── prompt.ts
61+
│ │ └── weeklyReport.ts
62+
│ ├── scm
63+
│ │ ├── AuthorService.ts
64+
│ │ ├── CommitLogStrategy.ts
65+
│ │ ├── GitProvider.ts
66+
│ │ ├── SCMProvider.ts
67+
│ │ ├── SvnProvider.ts
68+
│ │ └── SvnUtils.ts
69+
│ ├── scripts
70+
│ │ └── updateConfig.ts
71+
│ ├── services
72+
│ │ ├── ModelPickerService.ts
73+
│ │ └── weeklyReport.ts
74+
│ ├── types
75+
│ │ └── weeklyReport.ts
76+
│ ├── utils
77+
│ │ ├── date
78+
│ │ │ ├── date.md
79+
│ │ │ ├── DateUtils.ts
80+
│ │ │ └── index.ts
81+
│ │ ├── diff
82+
│ │ │ ├── DiffFormatter.ts
83+
│ │ │ ├── diff.md
84+
│ │ │ ├── DiffSimplifier.ts
85+
│ │ │ ├── DiffSplitter.ts
86+
│ │ │ ├── index.ts
87+
│ │ │ └── types.ts
88+
│ │ ├── i18n
89+
│ │ │ ├── i18n.md
90+
│ │ │ ├── index.ts
91+
│ │ │ └── LocalizationManager.ts
92+
│ │ ├── index.ts
93+
│ │ ├── notification
94+
│ │ │ ├── index.ts
95+
│ │ │ ├── NotificationManager.ts
96+
│ │ │ ├── notification.md
97+
│ │ │ ├── NotificationTypes.ts
98+
│ │ │ └── ProgressHandler.ts
99+
│ │ ├── review
100+
│ │ │ ├── CodeReviewReportGenerator.ts
101+
│ │ │ ├── index.ts
102+
│ │ │ └── review.md
103+
│ │ └── webview
104+
│ │ ├── index.ts
105+
│ │ ├── webview.md
106+
│ │ └── webview.ts
107+
│ ├── webview
108+
│ │ ├── config
109+
│ │ │ └── ModelConfigurationManager.ts
110+
│ │ ├── handlers
111+
│ │ │ └── WeeklyReportMessageHandler.ts
112+
│ │ ├── providers
113+
│ │ │ └── WeeklyReportViewProvider.ts
114+
│ │ ├── services
115+
│ │ │ └── WeeklyReportGenerator.ts
116+
│ │ └── WeeklyReportPanel.ts
117+
│ └── webview-ui
118+
│ ├── components.json
119+
│ ├── eslint.config.js
120+
│ ├── index.html
121+
│ ├── package.json
122+
│ ├── pnpm-lock.yaml
123+
│ ├── postcss.config.js
124+
│ ├── src
125+
│ │ ├── App.css
126+
│ │ ├── App.tsx
127+
│ │ ├── components
128+
│ │ │ ├── DateRangeSelector.tsx
129+
│ │ │ ├── Editor.tsx
130+
│ │ │ └── ui
131+
│ │ │ ├── accordion.tsx
132+
│ │ │ ├── alert-dialog.tsx
133+
│ │ │ ├── alert.tsx
134+
│ │ │ ├── aspect-ratio.tsx
135+
│ │ │ ├── avatar.tsx
136+
│ │ │ ├── badge.tsx
137+
│ │ │ ├── breadcrumb.tsx
138+
│ │ │ ├── button.tsx
139+
│ │ │ ├── calendar.tsx
140+
│ │ │ ├── card.tsx
141+
│ │ │ ├── carousel.tsx
142+
│ │ │ ├── chart.tsx
143+
│ │ │ ├── checkbox.tsx
144+
│ │ │ ├── collapsible.tsx
145+
│ │ │ ├── command.tsx
146+
│ │ │ ├── context-menu.tsx
147+
│ │ │ ├── dialog.tsx
148+
│ │ │ ├── drawer.tsx
149+
│ │ │ ├── dropdown-menu.tsx
150+
│ │ │ ├── form.tsx
151+
│ │ │ ├── hover-card.tsx
152+
│ │ │ ├── input-otp.tsx
153+
│ │ │ ├── input.tsx
154+
│ │ │ ├── label.tsx
155+
│ │ │ ├── menubar.tsx
156+
│ │ │ ├── navigation-menu.tsx
157+
│ │ │ ├── pagination.tsx
158+
│ │ │ ├── popover.tsx
159+
│ │ │ ├── progress.tsx
160+
│ │ │ ├── radio-group.tsx
161+
│ │ │ ├── resizable.tsx
162+
│ │ │ ├── scroll-area.tsx
163+
│ │ │ ├── select.tsx
164+
│ │ │ ├── separator.tsx
165+
│ │ │ ├── sheet.tsx
166+
│ │ │ ├── skeleton.tsx
167+
│ │ │ ├── slider.tsx
168+
│ │ │ ├── sonner.tsx
169+
│ │ │ ├── switch.tsx
170+
│ │ │ ├── table.tsx
171+
│ │ │ ├── tabs.tsx
172+
│ │ │ ├── textarea.tsx
173+
│ │ │ ├── toaster.tsx
174+
│ │ │ ├── toast.tsx
175+
│ │ │ ├── toggle-group.tsx
176+
│ │ │ ├── toggle.tsx
177+
│ │ │ └── tooltip.tsx
178+
│ │ ├── constants.ts
179+
│ │ ├── contexts
180+
│ │ │ └── ExtensionContext.tsx
181+
│ │ ├── hooks
182+
│ │ │ └── use-toast.ts
183+
│ │ ├── index.css
184+
│ │ ├── lib
185+
│ │ │ ├── constants.ts
186+
│ │ │ ├── utils.ts
187+
│ │ │ └── vscode.ts
188+
│ │ ├── main.tsx
189+
│ │ ├── types
190+
│ │ │ └── vscode.d.ts
191+
│ │ └── vite-env.d.ts
192+
│ ├── tailwind.config.js
193+
│ ├── tsconfig.app.json
194+
│ ├── tsconfig.app.tsbuildinfo
195+
│ ├── tsconfig.json
196+
│ ├── tsconfig.node.json
197+
│ ├── tsconfig.node.tsbuildinfo
198+
│ └── vite.config.ts
199+
├── tsconfig.json
200+
├── vsc-extension-quickstart.md
201+
└── webview-ui-dist
202+
├── index.css
203+
├── index.html
204+
└── index.js
205+
206+
36 directories, 164 files
207+
首先看顶层目录的组织方式:
208+
1. 基础配置文件 - package.json, tsconfig.json 等用于项目配置
209+
2. 文档文件 - README.md 及其国际化版本
210+
3. src/ - 主要源代码目录
211+
4. webview-ui-dist/ - 编译后的 WebView UI 文件
212+
5. i18n/ - 国际化资源文件
213+
214+
项目采用 TypeScript 开发,使用了现代前端工具链。从目录结构可以看出这是一个功能完整的 VS Code 扩展,包含:
215+
- AI 辅助功能 (src/ai/)
216+
- 命令系统 (src/commands/)
217+
- 配置管理 (src/config/)
218+
- 源代码管理集成 (src/scm/)
219+
- WebView UI (src/webview-ui/)
220+
顶级目录重要文件:
221+
package.json: 项目的 NPM 配置文件,定义了项目依赖和 VS Code 扩展配置
222+
tsconfig.json: TypeScript 编译配置
223+
README.md/README.zh-CN.md: 项目文档及其中文版本
224+
CHANGELOG.md/CHANGELOG.zh-CN.md: 版本变更记录
225+
i18n: 国际化资源文件目录
226+
src 目录 - 主要源代码:
227+
ai/: AI 相关实现
228+
229+
providers/: 不同 AI 服务提供商的实现
230+
AIProviderFactory.ts: AI 提供商工厂类
231+
types.ts: AI 相关类型定义
232+
commands/: VS Code 命令实现
233+
234+
BaseCommand.ts: 基础命令类
235+
GenerateCommitCommand.ts: 生成提交信息命令
236+
GenerateWeeklyReportCommand.ts: 生成周报命令
237+
ReviewCodeCommand.ts: 代码审查命令
238+
SelectModelCommand.ts: 选择 AI 模型命令
239+
config/: 配置管理
240+
241+
ConfigSchema.ts: 配置模式定义
242+
ConfigurationManager.ts: 配置管理器
243+
generated/configKeys.ts: 生成的配置键常量
244+
scm/: 源代码管理集成
245+
246+
GitProvider.ts: Git 集成
247+
SvnProvider.ts: SVN 集成
248+
SCMProvider.ts: SCM 提供商接口
249+
utils/: 工具函数
250+
251+
date/: 日期处理
252+
diff/: 差异比较
253+
i18n: 国际化
254+
notification/: 通知管理
255+
review/: 代码审查
256+
webview/: WebView 相关
257+
webview-ui/ 目录 - WebView UI 实现:
258+
使用 React + TypeScript 构建
259+
包含多个UI组件
260+
使用 Tailwind CSS 进行样式管理
261+
完整的构建配置
262+
项目特点:
263+
完善的国际化支持
264+
模块化的架构设计
265+
丰富的工具函数支持
266+
规范的代码组织
267+
完整的构建和发布流程
268+
269+
3. 主要功能模块
270+
3.1 AI 集成模块 (src/ai/)
271+
支持多种 AI 提供商:OpenAI、Gemini、DashScope、DeepSeek、ZhipuAI 等
272+
使用工厂模式管理不同 AI 提供商
273+
统一的接口定义和类型系统
274+
3.2 命令模块 (src/commands/)
275+
生成代码提交信息
276+
生成周报
277+
代码审查
278+
AI 模型选择
279+
3.3 源代码管理模块 (src/scm/)
280+
支持 Git 和 SVN 两种版本控制系统
281+
统一的 SCM 提供商接口
282+
版本控制相关操作封装
283+
3.4 配置管理 (src/config/)
284+
扩展配置管理
285+
默认配置提供
286+
配置模式定义
287+
3.5 WebView UI (src/webview-ui/)
288+
基于 React + TypeScript
289+
使用 Vite 作为构建工具
290+
现代化 UI 组件库
291+
支持主题切换
292+
响应式设计
293+
4. 技术特点
294+
架构设计
295+
模块化架构
296+
工厂模式
297+
依赖注入
298+
面向接口编程
299+
技术栈
300+
TypeScript
301+
React
302+
Vite
303+
Tailwind CSS
304+
VSCode Extension API
305+
代码质量
306+
ESLint 代码检查
307+
TypeScript 类型检查
308+
统一的代码风格
309+
国际化
310+
支持多语言(中英文文档)
311+
本地化管理器

i18n/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"gemini.apiKey.missing": "Gemini API Key is not configured. Would you like to configure it now?",
9292
"dashscope.apiKey.missing": "DashScope API Key is not configured. Would you like to configure it now?",
9393
"doubao.apiKey.missing": "Doubao API Key is not configured. Would you like to configure it now?",
94-
"reviewing.code": "Reviewing code...",
94+
"reviewing.code": "Reviewing code",
9595
"getting.file.changes": "Getting file changes...",
9696
"no.valid.changes.selected": "No valid changes selected for review",
9797
"reviewing.file": "file: {0}",

i18n/zh-cn.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"gemini.apiKey.missing": "Gemini API Key 未配置。是否现在配置?",
9090
"dashscope.apiKey.missing": "DashScope API Key 未配置。是否现在配置?",
9191
"doubao.apiKey.missing": "豆包 API Key 未配置。是否现在配置?",
92-
"reviewing.code": "正在进行代码评审...",
92+
"reviewing.code": "正在进行代码评审",
9393
"getting.file.changes": "正在获取文件变更...",
9494
"no.valid.changes.selected": "未选择有效的待评审变更",
9595
"reviewing.file": "评审文件:{0}",

src/ai/AIProviderFactory.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ZhipuAIProvider } from "./providers/ZhipuAIProvider";
88
import { DashScopeProvider } from "./providers/DashScopeProvider";
99
import { DoubaoProvider } from "./providers/DoubaoProvider";
1010
import { GeminiAIProvider } from "./providers/GeminiAIProvider";
11-
import { LocalizationManager } from "../utils/LocalizationManager";
11+
import { formatMessage } from "../utils/i18n/LocalizationManager";
1212

1313
/**
1414
* AI提供者工厂类,负责创建和管理不同AI服务提供者的实例
@@ -103,12 +103,7 @@ export class AIProviderFactory {
103103
provider = new GeminiAIProvider();
104104
break;
105105
default:
106-
throw new Error(
107-
LocalizationManager.getInstance().format(
108-
"provider.type.unknown",
109-
type
110-
)
111-
);
106+
throw new Error(formatMessage("provider.type.unknown", [type]));
112107
}
113108
this.providers.set(providerType, provider);
114109
this.providerTimestamps.set(providerType, Date.now());

src/ai/providers/BaseOpenAIProvider.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import {
1515
} from "../utils/generateHelper";
1616

1717
import { getWeeklyReportPrompt } from "../../prompt/weeklyReport";
18-
import { CodeReviewReportGenerator } from "../../utils/CodeReviewReportGenerator";
19-
import { LocalizationManager } from "../../utils/LocalizationManager";
18+
import { CodeReviewReportGenerator } from "../../utils/review/CodeReviewReportGenerator";
19+
import { formatMessage } from "../../utils/i18n/LocalizationManager";
2020

2121
/**
2222
* OpenAI提供者配置项接口
@@ -193,9 +193,9 @@ export abstract class BaseOpenAIProvider implements AIProvider {
193193
},
194194
};
195195
} catch (error) {
196-
const message = LocalizationManager.getInstance().format(
196+
const message = formatMessage(
197197
"codeReview.generation.failed",
198-
error instanceof Error ? error.message : String(error)
198+
[error instanceof Error ? error.message : String(error)]
199199
);
200200
throw new Error(message);
201201
}
@@ -244,9 +244,9 @@ export abstract class BaseOpenAIProvider implements AIProvider {
244244
};
245245
} catch (error) {
246246
throw new Error(
247-
LocalizationManager.getInstance().format(
247+
formatMessage(
248248
"weeklyReport.generation.failed",
249-
error instanceof Error ? error.message : String(error)
249+
[error instanceof Error ? error.message : String(error)]
250250
)
251251
);
252252
}

0 commit comments

Comments
 (0)