Skip to content

Commit 7adf253

Browse files
author
alpsla
committed
feat(snippets): add dynamic language detection for code blocks
✅ Tasks #1 & #2 Complete: Code Snippets + Fix Suggestions Changes: - Added getLanguageFromFile() helper method (lines 1641-1665) - Supports 20+ file extensions (Java, Python, JS/TS, Go, Rust, etc.) - Returns appropriate language for syntax highlighting - Updated code snippet display (line 1415) - Changed from hardcoded 'java' to dynamic language detection - Proper syntax highlighting for all supported languages - Updated fix suggestion display (line 1451) - Changed from hardcoded 'java' to dynamic language detection - Corrected code shows in proper language syntax Existing Features (Already Implemented): - ✅ Code snippets with file location (lines 1402-1419) - ✅ Fix suggestions with diff format (lines 1421-1463) - ✅ Before/After comparison with +/- diff syntax - ✅ Best practices recommendations - ✅ Clean-up of internal bug tracker references Language Support: - Java, Scala, Kotlin, Gradle - Python - JavaScript, JSX, TypeScript, TSX - Go, Rust, Ruby, PHP - C, C++, C#, Swift - YAML, JSON, XML, SQL, Bash Files Modified: - v9-grouped-report-formatter.ts: - Lines 1415, 1451: Dynamic language detection - Lines 1638-1665: getLanguageFromFile() method Time: ~15 minutes (code was already there, just needed helper method) Next: Copy remaining report sections (Business Impact, Education, PR Comment, Metadata)
1 parent e6f7398 commit 7adf253

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

packages/agents/src/two-branch/analyzers/v9-grouped-report-formatter.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,8 @@ ${qualityResult.categoryScores ? `
14121412

14131413
if (representative.snippet && representative.snippet !== 'N/A' && representative.snippet.trim().length > 0) {
14141414
section += `**Code**:\n\n`;
1415-
section += '```java\n';
1415+
const language = this.getLanguageFromFile(representative.file);
1416+
section += `\`\`\`${language}\n`;
14161417
section += representative.snippet;
14171418
section += '\n```\n\n';
14181419
}
@@ -1447,7 +1448,8 @@ ${qualityResult.categoryScores ? `
14471448
section += '\n```\n\n';
14481449
} else {
14491450
section += `**Recommended Code**:\n\n`;
1450-
section += '```java\n';
1451+
const language = this.getLanguageFromFile(representative.file);
1452+
section += `\`\`\`${language}\n`;
14511453
section += representative.fixSuggestion.correctedCode;
14521454
section += '\n```\n\n';
14531455
}
@@ -1633,6 +1635,35 @@ ${qualityResult.categoryScores ? `
16331635
return 'low';
16341636
}
16351637

1638+
/**
1639+
* Get programming language from file extension for syntax highlighting
1640+
*/
1641+
private getLanguageFromFile(file: string): string {
1642+
if (file.endsWith('.java')) return 'java';
1643+
if (file.endsWith('.scala')) return 'scala';
1644+
if (file.endsWith('.gradle')) return 'gradle';
1645+
if (file.endsWith('.kt') || file.endsWith('.kts')) return 'kotlin';
1646+
if (file.endsWith('.py')) return 'python';
1647+
if (file.endsWith('.js')) return 'javascript';
1648+
if (file.endsWith('.jsx')) return 'jsx';
1649+
if (file.endsWith('.ts')) return 'typescript';
1650+
if (file.endsWith('.tsx')) return 'tsx';
1651+
if (file.endsWith('.go')) return 'go';
1652+
if (file.endsWith('.rs')) return 'rust';
1653+
if (file.endsWith('.rb')) return 'ruby';
1654+
if (file.endsWith('.php')) return 'php';
1655+
if (file.endsWith('.c')) return 'c';
1656+
if (file.endsWith('.cpp') || file.endsWith('.cc') || file.endsWith('.cxx')) return 'cpp';
1657+
if (file.endsWith('.cs')) return 'csharp';
1658+
if (file.endsWith('.swift')) return 'swift';
1659+
if (file.endsWith('.sh')) return 'bash';
1660+
if (file.endsWith('.yml') || file.endsWith('.yaml')) return 'yaml';
1661+
if (file.endsWith('.json')) return 'json';
1662+
if (file.endsWith('.xml')) return 'xml';
1663+
if (file.endsWith('.sql')) return 'sql';
1664+
return 'text';
1665+
}
1666+
16361667
/**
16371668
* Determine if safe to auto-apply without review
16381669
*/

0 commit comments

Comments
 (0)