Skip to content

Commit d65054c

Browse files
committed
fix: 修正cvb文件存盘格式错误
1 parent a85f0a8 commit d65054c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/cvbManager.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as iconv from 'iconv-lite'; // 编码转换库
55
import * as vscode from 'vscode';
66
import { generateFilenameFromRequest } from './deepseekApi';
77

8-
import { g_objLanguageMapping } from './languageMapping';
8+
import { getLanguageFromPath } from './languageMapping';
99

1010
// ================== CVB 核心类 ==================
1111
export class Cvb
@@ -56,8 +56,8 @@ export class Cvb
5656
// 将文件内容转换成字符串
5757
let filesStr = '';
5858
for (const filePath in this.m_recFiles) {
59-
// 这里假设文件内容不需要包裹代码块标记,如果需要,可自行添加
60-
filesStr += `## FILE:${filePath}\n${this.m_recFiles[filePath]}\n`;
59+
const strLang = getLanguageFromPath(filePath);
60+
filesStr += `## FILE:${filePath}\n\`\`\`${strLang}\n${this.m_recFiles[filePath]}\n\`\`\`\n`;
6161
}
6262

6363
// 重新组装整个 CVB 内容
@@ -655,8 +655,7 @@ function rebuildCvb(baseCvb: Cvb, mapFiles: Map<string, string>) : Cvb
655655

656656
for (const [strFilePath, strContent] of mapFiles)
657657
{
658-
const strExt: string = path.extname(strFilePath).slice(1).toLowerCase();
659-
const strLang: string = g_objLanguageMapping[strExt] || 'text';
658+
const strLang: string = getLanguageFromPath(strFilePath);
660659
strNewContent += `## FILE:${strFilePath}\n\`\`\`${strLang}\n${strContent}\n\`\`\`\n\n`;
661660
}
662661

@@ -798,8 +797,7 @@ export async function generateCvb(arrFilePaths: string[], strUserRequest: string
798797
try
799798
{
800799
const strFileContent = readFileWithEncoding(strFilePath);
801-
const strExt = path.extname(strFilePath).slice(1).toLowerCase();
802-
const strLang = g_objLanguageMapping[strExt] || 'text';
800+
const strLang = getLanguageFromPath(strFilePath);
803801
strCvbContent += `## FILE:${strFilePath}\n`;
804802
strCvbContent += '```' + strLang + '\n';
805803
strCvbContent += strFileContent + '\n';

src/languageMapping.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ export const g_objLanguageMapping: { [key: string]: string } = {
2222
'dart': 'dart', // Dart
2323
'md': 'markdown', // markdown
2424
'json':'json'
25-
};
25+
};
26+
27+
/**
28+
* 根据文件路径猜测编程语言
29+
* @param filePath 文件路径
30+
* @returns 语言名称字符串,未匹配时返回 'text'
31+
*/
32+
export function getLanguageFromPath(filePath: string): string {
33+
const strExt = filePath.split('.').pop()?.toLowerCase() || '';
34+
return g_objLanguageMapping[strExt] || 'text';
35+
}

0 commit comments

Comments
 (0)