|
| 1 | +# GitHub Copilot 项目配置文档 |
| 2 | + |
| 3 | +本文档为 GitHub Copilot 提供项目上下文信息,帮助 AI 助手更好地理解项目结构和编码规范。 |
| 4 | + |
| 5 | +## 项目概览 |
| 6 | + |
| 7 | +**项目名称**: VSC Git Panel |
| 8 | +**项目类型**: Visual Studio Code 扩展 |
| 9 | +**主要功能**: Git 历史可视化和文件变更管理 |
| 10 | +**开发阶段**: WIP (Work In Progress) |
| 11 | + |
| 12 | +## 核心技术栈 |
| 13 | + |
| 14 | +### 语言与框架 |
| 15 | +- **主语言**: TypeScript (严格模式) |
| 16 | +- **前端框架**: Vue 3 + Composition API |
| 17 | +- **扩展框架**: reactive-vscode |
| 18 | +- **构建工具**: Vite + tsup |
| 19 | +- **包管理器**: pnpm |
| 20 | + |
| 21 | +### 关键依赖 |
| 22 | +```json |
| 23 | +{ |
| 24 | + "vue": "^3.5.13", |
| 25 | + "simple-git": "^3.27.0", |
| 26 | + "reactive-vscode": "^0.2.0", |
| 27 | + "dayjs": "^1.11.13", |
| 28 | + "vue-virtual-scroller": "^1.1.2" |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +## 编码规范 |
| 33 | + |
| 34 | +### TypeScript 风格 |
| 35 | +- 使用严格模式 (`strict: true`) |
| 36 | +- 启用 `strictNullChecks` |
| 37 | +- 目标版本: ES2017 |
| 38 | +- 模块系统: ESNext |
| 39 | + |
| 40 | +### Vue 组件规范 |
| 41 | +- 必须使用 `<script setup lang="ts">` 语法 |
| 42 | +- Props 使用 `defineProps<Type>()` 泛型语法 |
| 43 | +- 响应式数据优先使用 `ref()` 和 `computed()` |
| 44 | +- 组件文件名使用 PascalCase |
| 45 | + |
| 46 | +### 命名约定 |
| 47 | +- **文件名**: 组件用 PascalCase,工具用 camelCase |
| 48 | +- **变量名**: camelCase |
| 49 | +- **常量名**: UPPER_SNAKE_CASE |
| 50 | +- **类型名**: PascalCase |
| 51 | +- **接口名**: PascalCase (无 I 前缀) |
| 52 | + |
| 53 | +### 代码组织 |
| 54 | +- 按功能模块组织目录结构 |
| 55 | +- 每个模块有独立的 `index.ts` 作为入口 |
| 56 | +- 类型定义统一在 `types.ts` 文件中 |
| 57 | +- 常量定义在 `constant.ts` 文件中 |
| 58 | + |
| 59 | +## 项目结构上下文 |
| 60 | + |
| 61 | +### 核心模块说明 |
| 62 | + |
| 63 | +#### `/src/views/` |
| 64 | +- `history/`: Git 历史记录的 Vue 应用 |
| 65 | + - `App.vue`: 主应用入口 |
| 66 | + - `components/CommitTable/`: 提交表格组件 |
| 67 | +- `diff/`: 文件差异对比视图 |
| 68 | +- `webview.ts`: Webview 管理器 |
| 69 | + |
| 70 | +#### `/src/git/` |
| 71 | +- `GitChangeMonitor.ts`: Git 变更监控服务 |
| 72 | +- `types.ts`: Git 相关类型定义 |
| 73 | +- 提供 Git 操作的统一接口 |
| 74 | + |
| 75 | +#### `/src/commands/` |
| 76 | +- VS Code 命令定义和实现 |
| 77 | +- `clear.ts`, `diff.ts`, `refresh.ts` 等功能命令 |
| 78 | + |
| 79 | +#### `/src/storage.ts` |
| 80 | +- 使用 VS Code ExtensionContext 进行数据持久化 |
| 81 | +- 提供 commits 数据的 CRUD 操作 |
| 82 | + |
| 83 | +### 关键类型定义 |
| 84 | + |
| 85 | +```typescript |
| 86 | +interface Commit { |
| 87 | + hash: string |
| 88 | + date: string |
| 89 | + message: string |
| 90 | + author_name: string |
| 91 | + author_email: string |
| 92 | + refs?: string |
| 93 | + files?: Array<{ status: string, path: string }> |
| 94 | +} |
| 95 | + |
| 96 | +interface CommitGraph { |
| 97 | + operations: GitOperation[] |
| 98 | + branches: string[] |
| 99 | + logResult: { |
| 100 | + all: Commit[] |
| 101 | + total: number |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +### 常用模式 |
| 107 | + |
| 108 | +#### 1. 响应式扩展开发 |
| 109 | +```typescript |
| 110 | +const { activate, deactivate } = defineExtension(() => { |
| 111 | + // 扩展逻辑 |
| 112 | + useDisposable(new Disposable(() => { |
| 113 | + // 清理逻辑 |
| 114 | + })) |
| 115 | +}) |
| 116 | +``` |
| 117 | + |
| 118 | +#### 2. 单例服务 |
| 119 | +```typescript |
| 120 | +export const useStorage = createSingletonComposable(() => { |
| 121 | + // 服务逻辑 |
| 122 | + return { /* API */ } |
| 123 | +}) |
| 124 | +``` |
| 125 | + |
| 126 | +#### 3. Vue 组件通信 |
| 127 | +```typescript |
| 128 | +// 父子组件通信使用 props + emit |
| 129 | +const props = defineProps<{ commits: Commit[] }>() |
| 130 | +const emit = defineEmits<{ select: [hash: string] }>() |
| 131 | + |
| 132 | +// Webview 通信使用消息传递 |
| 133 | +vscode.postMessage({ command: WEBVIEW_CHANNEL.GET_HISTORY }) |
| 134 | +``` |
| 135 | + |
| 136 | +## VS Code 扩展特性 |
| 137 | + |
| 138 | +### 贡献点 (package.json) |
| 139 | +- **活动栏视图容器**: `git-panel` |
| 140 | +- **面板视图容器**: `git-panel` |
| 141 | +- **Webview 视图**: `git-panel.history` |
| 142 | +- **TreeView 视图**: `git-panel.changes` |
| 143 | + |
| 144 | +### 命令系统 |
| 145 | +- `git-panel.history`: 显示历史 |
| 146 | +- `git-panel.history.clear`: 清除选择 |
| 147 | +- `git-panel.history.refresh`: 刷新历史 |
| 148 | + |
| 149 | +### 配置系统 |
| 150 | +- 当前无自定义配置项 |
| 151 | +- 扩展配置在 `contributes.configuration` 中定义 |
| 152 | + |
| 153 | +## 性能优化策略 |
| 154 | + |
| 155 | +### 前端优化 |
| 156 | +- **虚拟滚动**: 使用 `vue-virtual-scroller` 处理大量提交数据 |
| 157 | +- **分页加载**: `ITEMS_PER_PAGE = 45` 的渐进式加载 |
| 158 | +- **计算属性缓存**: 使用 `computed()` 缓存复杂计算 |
| 159 | + |
| 160 | +### 后端优化 |
| 161 | +- **数据缓存**: 在 ExtensionContext 中缓存 Git 数据 |
| 162 | +- **增量更新**: 只更新变化的文件信息 |
| 163 | +- **错误边界**: 完善的错误处理和日志记录 |
| 164 | + |
| 165 | +## 开发上下文 |
| 166 | + |
| 167 | +### 构建系统 |
| 168 | +```bash |
| 169 | +# 开发模式 - 并行运行前端和后端构建 |
| 170 | +pnpm dev # concurrently "vite" "tsup --watch" |
| 171 | + |
| 172 | +# 生产构建 - 先构建前端再构建后端 |
| 173 | +pnpm build # vite build && tsup src/index.ts --external vscode |
| 174 | +``` |
| 175 | + |
| 176 | +### 调试配置 |
| 177 | +- VS Code 扩展主机模式调试 |
| 178 | +- Webview 开发者工具调试 |
| 179 | +- 支持热重载开发 |
| 180 | + |
| 181 | +### 测试策略 |
| 182 | +- 使用 vitest 进行单元测试 |
| 183 | +- 重点测试 Git 操作和数据转换逻辑 |
| 184 | +- UI 组件的快照测试 |
| 185 | + |
| 186 | +## 常见开发场景 |
| 187 | + |
| 188 | +### 1. 添加新的 Git 操作 |
| 189 | +1. 在 `/src/git/` 中定义接口 |
| 190 | +2. 实现 simple-git 调用 |
| 191 | +3. 添加类型定义 |
| 192 | +4. 更新存储逻辑 |
| 193 | + |
| 194 | +### 2. 添加新的 Vue 组件 |
| 195 | +1. 在 `/src/views/history/components/` 创建组件 |
| 196 | +2. 使用 `<script setup>` 语法 |
| 197 | +3. 接收 props 并定义 emit |
| 198 | +4. 使用 VS Code CSS 变量 |
| 199 | + |
| 200 | +### 3. 添加新的 VS Code 命令 |
| 201 | +1. 在 `package.json` 的 `contributes.commands` 注册 |
| 202 | +2. 在 `/src/commands/` 实现命令逻辑 |
| 203 | +3. 在 `/src/commands/index.ts` 中注册 |
| 204 | + |
| 205 | +### 4. 处理 Webview 通信 |
| 206 | +```typescript |
| 207 | +// 扩展端发送消息 |
| 208 | +panel.webview.postMessage({ |
| 209 | + command: CHANNEL.HISTORY, |
| 210 | + commits: commitData |
| 211 | +}) |
| 212 | + |
| 213 | +// Webview 端接收消息 |
| 214 | +window.addEventListener('message', (event) => { |
| 215 | + switch (event.data.command) { |
| 216 | + case CHANNEL.HISTORY: |
| 217 | + commits.value = event.data.commits |
| 218 | + break |
| 219 | + } |
| 220 | +}) |
| 221 | +``` |
| 222 | + |
| 223 | +## 错误处理模式 |
| 224 | + |
| 225 | +### 统一错误处理 |
| 226 | +```typescript |
| 227 | +try { |
| 228 | + const result = await gitOperation() |
| 229 | + return result |
| 230 | +} |
| 231 | +catch (error) { |
| 232 | + logger.error('Operation failed:', error) |
| 233 | + vscode.window.showErrorMessage(`操作失败: ${error.message}`) |
| 234 | + throw error |
| 235 | +} |
| 236 | +``` |
| 237 | + |
| 238 | +### 用户友好的错误提示 |
| 239 | +- 使用 `vscode.window.showErrorMessage` 显示错误 |
| 240 | +- 记录详细错误到日志 |
| 241 | +- 提供用户可理解的错误信息 |
| 242 | + |
| 243 | +## 注意事项 |
| 244 | + |
| 245 | +1. **避免使用 console**: 使用项目的 logger 工具 |
| 246 | +2. **类型安全**: 所有数据都应有明确的类型定义 |
| 247 | +3. **资源清理**: 确保 Disposable 资源正确清理 |
| 248 | +4. **性能考虑**: 大数据量时使用虚拟滚动 |
| 249 | +5. **VS Code 主题**: 始终使用 VS Code CSS 变量 |
| 250 | +6. **错误边界**: 关键操作都要有错误处理 |
| 251 | + |
| 252 | +--- |
| 253 | + |
| 254 | +*此文档用于为 GitHub Copilot 提供项目上下文,帮助生成符合项目规范的代码。* |
0 commit comments