Skip to content

Commit 35cbe88

Browse files
📝 docs(typescript): 优化代码注释和类型声明
-【代码质量】完善多个核心模块的文档注释 -【代码结构】重构并规范化配置和常量定义 -【代码组织】优化 WeeklyReportPanel 类的注释和方法说明 -【代码维护】增加配置键和接口的详细类型声明
1 parent cc32d54 commit 35cbe88

File tree

6 files changed

+182
-26
lines changed

6 files changed

+182
-26
lines changed

src/config/generated/configKeys.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ export const CONFIG_KEYS = {
2828
"FEATURES_COMMITFORMAT_ENABLEMERGECOMMIT": "dish-ai-commit.features.commitFormat.enableMergeCommit",
2929
"FEATURES_COMMITFORMAT_ENABLEEMOJI": "dish-ai-commit.features.commitFormat.enableEmoji",
3030
"FEATURES_WEEKLYREPORT": "dish-ai-commit.features.weeklyReport",
31-
"FEATURES_WEEKLYREPORT_SYSTEMPROMPT": "dish-ai-commit.features.weeklyReport.systemPrompt"
31+
"FEATURES_WEEKLYREPORT_SYSTEMPROMPT": "dish-ai-commit.features.weeklyReport.systemPrompt",
32+
"FEATURES_CODEREVIEW": "dish-ai-commit.features.codeReview",
33+
"FEATURES_CODEREVIEW_ENABLED": "dish-ai-commit.features.codeReview.enabled",
34+
"FEATURES_CODEREVIEW_SYSTEMPROMPT": "dish-ai-commit.features.codeReview.systemPrompt"
3235
} as const;

src/constants.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import * as packageJson from "../package.json";
22

3+
/** 扩展的包名 */
34
export const EXTENSION_NAME = packageJson.name;
5+
6+
/** 扩展的显示名称 */
47
export const DISPLAY_NAME = packageJson.displayName;
58

6-
// 使用命名空间组织命令
9+
/**
10+
* 使用命名空间组织的命令常量
11+
* @namespace
12+
*/
713
export const COMMANDS = {
14+
/** Commit相关命令 */
815
COMMIT: {
16+
/** 生成commit信息的命令 */
917
GENERATE: packageJson.contributes.commands[0].command,
1018
},
19+
/** 模型相关命令 */
1120
MODEL: {
21+
/** 显示模型选择的命令 */
1222
SHOW: packageJson.contributes.commands[1].command,
1323
},
24+
/** 周报相关命令 */
1425
WEEKLY_REPORT: {
26+
/** 生成周报的命令 */
1527
GENERATE: packageJson.contributes.commands[2].command,
1628
},
29+
/** 代码审查相关命令 */
30+
CODE_REVIEW: {
31+
/** 执行代码审查的命令 */
32+
REVIEW: packageJson.contributes.commands[3].command,
33+
},
1734
} as const;
1835

19-
// 添加类型导出
36+
/** COMMANDS常量的TypeScript类型 */
2037
export type CommandType = typeof COMMANDS;

src/extension.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,39 @@ import { LocalizationManager } from "./utils/LocalizationManager";
77
import { NotificationHandler } from "./utils/NotificationHandler";
88
import { WeeklyReportPanel } from "./webview/WeeklyReportPanel";
99

10-
// This method is called when your extension is activated
11-
// Your extension is activated the very first time the command is executed
10+
/**
11+
* 在首次执行命令时激活扩展
12+
* @param {vscode.ExtensionContext} context - VS Code扩展上下文对象
13+
* @throws {Error} 如果扩展激活失败将抛出错误
14+
*/
1215
export function activate(context: vscode.ExtensionContext) {
1316
try {
17+
// 日志输出表示扩展已激活
1418
console.log('Extension "dish-ai-commit-gen" is now active!');
1519

16-
// 初始化本地化管理器(移除重复的初始化)
20+
// 初始化本地化管理器
1721
LocalizationManager.initialize(context);
1822

19-
// 初始化配置管理器并添加到订阅列表
23+
// 初始化配置管理器并注册到生命周期
2024
context.subscriptions.push(ConfigurationManager.getInstance());
25+
2126
console.log("注册命令");
22-
// 注册所有命令
27+
// 注册所有命令到VS Code
2328
registerCommands(context);
2429
} catch (e) {
2530
console.error("Error activating extension:", e);
26-
// 添加用户可见的错误提示
31+
// 向用户显示本地化的错误提示
2732
NotificationHandler.error(
2833
"extension.activation.failed",
2934
3000,
3035
e instanceof Error ? e.message : String(e)
3136
);
32-
throw e;
37+
throw e; // 重新抛出以便VS Code处理
3338
}
3439
}
3540

36-
// This method is called when your extension is deactivated
41+
/**
42+
* VS Code停用扩展时调用此方法
43+
* 目前无需清理操作
44+
*/
3745
export function deactivate() {}

src/scripts/updateConfig.ts

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* 配置更新脚本模块
3+
* @module updateConfig
4+
*/
5+
16
import * as fs from "fs";
27
import * as path from "path";
38
import {
@@ -7,10 +12,21 @@ import {
712
generateConfigKeys,
813
} from "../config/ConfigSchema";
914

15+
/**
16+
* 更新所有配置文件
17+
* 包括更新 package.json 中的配置属性和生成配置键常量文件
18+
* @returns {Promise<void>} 更新完成的 Promise
19+
* @throws {Error} 如果配置更新过程中发生错误
20+
*/
1021
async function updateAllConfigs() {
22+
/** 扩展名称常量 */
1123
const EXTENSION_NAME = "dish-ai-commit";
1224

13-
// 更新 package.json
25+
/**
26+
* 更新 package.json 中的配置属性
27+
* @returns {Promise<void>} 更新完成的 Promise
28+
* @throws {Error} 如果文件读写过程中发生错误
29+
*/
1430
async function updatePackageJson() {
1531
const packagePath = path.join(process.cwd(), "package.json");
1632
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"));
@@ -25,20 +41,26 @@ async function updateAllConfigs() {
2541
pkg.contributes.configuration.properties = {};
2642
const properties = pkg.contributes.configuration.properties;
2743

28-
// 递归遍历 CONFIG_SCHEMA 生成配置
44+
/**
45+
* 递归遍历配置模式对象,生成 VSCode 配置属性
46+
* @param {ConfigObject} obj - 配置对象
47+
* @param {string} [currentPath=""] - 当前配置路径
48+
*/
2949
function traverse(obj: ConfigObject, currentPath: string = "") {
3050
for (const [key, value] of Object.entries(obj)) {
51+
// 构建完整的配置键路径
3152
const fullPath = currentPath ? `${currentPath}.${key}` : key;
3253
const configKey = `${EXTENSION_NAME}.${fullPath}`;
3354

3455
if (isConfigValue(value)) {
56+
// 构建基础配置属性对象
3557
const configProperty: Record<string, any> = {
3658
type: value.type,
3759
default: value.default,
3860
description: value.description,
3961
};
4062

41-
// 只有字符串类型的配置才可能有枚举值和枚举描述
63+
// 处理字符串类型特有的枚举配置
4264
if (value.type === "string") {
4365
if ("enum" in value) {
4466
configProperty.enum = value.enum;
@@ -48,13 +70,14 @@ async function updateAllConfigs() {
4870
}
4971
}
5072

51-
// 添加作用域设置
73+
// 添加配置作用域
5274
if ("scope" in value) {
5375
configProperty.scope = value.scope;
5476
}
5577

5678
properties[configKey] = configProperty;
5779
} else if (typeof value === "object") {
80+
// 递归处理嵌套对象
5881
traverse(value as ConfigObject, fullPath);
5982
}
6083
}
@@ -65,8 +88,14 @@ async function updateAllConfigs() {
6588
console.log("✅ package.json updated successfully");
6689
}
6790

68-
// 更新配置键常量
91+
/**
92+
* 更新配置键常量文件
93+
* 生成 TypeScript 常量定义文件
94+
* @returns {Promise<void>} 更新完成的 Promise
95+
* @throws {Error} 如果文件写入失败
96+
*/
6997
async function updateConfigKeys() {
98+
// 生成配置键对象
7099
const keys = generateConfigKeys(CONFIG_SCHEMA);
71100
const content = `// This file is auto-generated, do not edit manually
72101
export const CONFIG_KEYS = ${JSON.stringify(keys, null, 2)} as const;
@@ -76,7 +105,7 @@ export const CONFIG_KEYS = ${JSON.stringify(keys, null, 2)} as const;
76105
"src/config/generated/configKeys.ts"
77106
);
78107

79-
// 确保目录存在
108+
// 确保目标目录存在
80109
const dir = path.dirname(configKeysPath);
81110
if (!fs.existsSync(dir)) {
82111
fs.mkdirSync(dir, { recursive: true });
@@ -87,6 +116,7 @@ export const CONFIG_KEYS = ${JSON.stringify(keys, null, 2)} as const;
87116
}
88117

89118
try {
119+
// 并行执行两个更新任务
90120
await Promise.all([updatePackageJson(), updateConfigKeys()]);
91121

92122
console.log("🎉 All configurations updated successfully!");

src/types/weeklyReport.ts

+30
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
1+
/**
2+
* 周报配置接口
3+
* @interface Config
4+
*/
15
export interface Config {
6+
/** 总工作时长(小时) */
27
totalHours: number;
8+
/** 总工作天数 */
39
totalDays: number;
10+
/** 最小计算单位(小时) */
411
minUnit: number;
512
}
613

14+
/**
15+
* Jira问题接口
16+
* @interface JiraIssue
17+
*/
718
export interface JiraIssue {
19+
/** Jira问题的唯一标识符 */
820
key: string;
21+
/** 问题标题 */
922
title: string;
23+
/** 关联用户列表 */
1024
linkUsers?: string[];
25+
/** 优先级 */
1126
priority?: string;
27+
/** 问题描述 */
1228
description?: string;
1329
}
1430

31+
/**
32+
* 工作项接口
33+
* @interface WorkItem
34+
*/
1535
export interface WorkItem {
36+
/** 工作内容 */
1637
content: string;
38+
/** 工作耗时 */
1739
time: string;
40+
/** 工作描述 */
1841
description: string;
1942
}
2043

44+
/**
45+
* 代码仓库接口
46+
* @interface Repository
47+
*/
2148
export interface Repository {
49+
/** 仓库类型: git或svn */
2250
type: 'git' | 'svn';
51+
/** 仓库路径 */
2352
path: string;
53+
/** 仓库作者 */
2454
author?: string;
2555
}

0 commit comments

Comments
 (0)