-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-【新功能】 - 实现 CodeReviewReportGenerator 类,支持生成 Markdown 格式的代码审查报告 - 增强多个工具类的文档注释和类型定义 - 优化 DiffSplitter 和 DiffSimplifier 的差异处理逻辑 -【代码优化】 - 完善 LocalizationManager 的错误处理和资源加载机制 - 改进 DateUtils 的日期范围计算方法 - 增强 ProgressHandler 和 NotificationHandler 的类型安全性 -【功能增强】 - 增加 webview 相关工具函数 - 扩展差异文本处理的配置选项 - 优化本地化资源管理机制
- Loading branch information
1 parent
79801c4
commit d9da1b3
Showing
8 changed files
with
286 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { CodeReviewResult, CodeReviewIssue } from "../ai/types"; | ||
|
||
/** | ||
* 代码审查报告生成器,将代码审查结果转换为格式化的 Markdown 文档 | ||
*/ | ||
export class CodeReviewReportGenerator { | ||
/** | ||
* 不同严重程度对应的 emoji 图标 | ||
* @private | ||
*/ | ||
private static readonly severityEmoji = { | ||
NOTE: "💡", // 提示 | ||
WARNING: "⚠️", // 警告 | ||
ERROR: "🚨", // 错误 | ||
}; | ||
|
||
/** | ||
* 生成完整的 Markdown 格式代码审查报告 | ||
* @param {CodeReviewResult} review - 代码审查结果对象 | ||
* @returns {string} 格式化的 Markdown 文本 | ||
*/ | ||
static generateMarkdownReport(review: CodeReviewResult): string { | ||
// 按文件分组整理问题 | ||
const sections = this.groupIssuesByFile(review.issues); | ||
|
||
// 生成报告各部分 | ||
let markdown = this.generateHeader(review.summary); | ||
markdown += this.generateDetailedFindings(sections); | ||
|
||
return markdown; | ||
} | ||
|
||
/** | ||
* 将问题按文件路径分组 | ||
* @private | ||
* @param {CodeReviewIssue[]} issues - 问题列表 | ||
* @returns {Record<string, CodeReviewIssue[]>} 按文件分组的问题 | ||
*/ | ||
private static groupIssuesByFile( | ||
issues: CodeReviewIssue[] | ||
): Record<string, CodeReviewIssue[]> { | ||
return issues.reduce((acc, issue) => { | ||
if (!acc[issue.filePath]) { | ||
acc[issue.filePath] = []; | ||
} | ||
acc[issue.filePath].push(issue); | ||
return acc; | ||
}, {} as Record<string, CodeReviewIssue[]>); | ||
} | ||
|
||
/** | ||
* 生成报告头部,包含总体摘要 | ||
* @private | ||
* @param {string} summary - 审查总结 | ||
* @returns {string} Markdown 格式的报告头部 | ||
*/ | ||
private static generateHeader(summary: string): string { | ||
return `# Code Review Report\n\n## Summary\n\n${summary}\n\n`; | ||
} | ||
|
||
/** | ||
* 生成详细问题列表 | ||
* @private | ||
* @param {Record<string, CodeReviewIssue[]>} sections - 按文件分组的问题 | ||
* @returns {string} Markdown 格式的详细问题列表 | ||
*/ | ||
private static generateDetailedFindings( | ||
sections: Record<string, CodeReviewIssue[]> | ||
): string { | ||
let markdown = `## Detailed Findings\n\n`; | ||
|
||
// 遍历每个文件的问题 | ||
for (const [filePath, issues] of Object.entries(sections)) { | ||
markdown += `### ${filePath}\n\n`; | ||
|
||
for (const issue of issues) { | ||
markdown += this.generateIssueSection(issue); | ||
} | ||
} | ||
|
||
return markdown; | ||
} | ||
|
||
/** | ||
* 生成单个问题的描述部分 | ||
* @private | ||
* @param {CodeReviewIssue} issue - 单个问题对象 | ||
* @returns {string} Markdown 格式的问题描述 | ||
*/ | ||
private static generateIssueSection(issue: CodeReviewIssue): string { | ||
// 生成问题标题,包含严重程度和行号 | ||
let section = `#### ${this.severityEmoji[issue.severity]} ${ | ||
issue.severity | ||
}: Line ${issue.startLine}${issue.endLine ? `-${issue.endLine}` : ""}\n\n`; | ||
|
||
// 添加问题描述和建议 | ||
section += `**Issue:** ${issue.description}\n\n`; | ||
section += `**Suggestion:** ${issue.suggestion}\n\n`; | ||
|
||
// 如果有代码示例,添加代码块 | ||
if (issue.code) { | ||
section += "```typescript\n" + issue.code + "\n```\n\n"; | ||
} | ||
|
||
// 如果有相关文档,添加链接 | ||
if (issue.documentation) { | ||
section += `📚 [Documentation](${issue.documentation})\n\n`; | ||
} | ||
|
||
section += `---\n\n`; | ||
return section; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.