Skip to content

Commit 3b08777

Browse files
committed
fix: 调整压缩细节
1 parent 027a2f9 commit 3b08777

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/cvbManager.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class Cvb {
2727
return this.m_recMetadata;
2828
}
2929

30+
public getMetaData(key: string) : string | null {
31+
return this.m_recMetadata[key];
32+
}
33+
3034
public setMetaData(strKey: string, strValue: string): void {
3135
this.m_recMetadata[strKey] = strValue;
3236
}
@@ -595,6 +599,13 @@ TCVB 格式规范:
595599
// ================== 合并函数 ==================
596600

597601
export function mergeCvb(baseCvb: Cvb, tcvb: TCVB): Cvb {
602+
603+
if (baseCvb.getMetaData("compressFrom")) {
604+
const orignalPath = baseCvb.getMetaData("compressFrom") || "";
605+
const cvbContent = fs.readFileSync(orignalPath, 'utf-8');
606+
baseCvb = new Cvb(cvbContent);
607+
}
608+
598609
// 先将 baseCvb 中的所有文件内容存入 Map
599610
const mapMergedFiles: Map<string, string> = new Map<string, string>(
600611
Object.entries(baseCvb.getFiles())
@@ -861,6 +872,7 @@ ${userRequest}
861872
1. 提取出关键信息的代码块,这些代码块帮助理解用户请求中的核心上下文。比如在重构任务中,需要关注相关的函数、变量及其上下级调用等。
862873
2. 需要被处理的内容(如重构代码),应该被提取出来。
863874
3. 确定有必要作为“锚点”的代码段,以便后续处理时可以方便地替换。
875+
4. 如果不确定是否相关的代码,就先当不相关处理,也就是丢弃这部分代码
864876
865877
例如:
866878
假设给定代码如下:
@@ -913,7 +925,6 @@ function func2() {
913925
compressedFiles[filePath] = compressedContent;
914926
} else {
915927
// 如果 API 调用失败,保留原始内容
916-
compressedFiles[filePath] = fileContent;
917928
}
918929
}
919930

src/siderBar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ async function compressThisCvb(filePath: string) {
402402
return;
403403
}
404404

405-
newCvb.setMetaData("comressFrom", filePath);
405+
if (!newCvb.getMetaData("compressFrom")) {
406+
newCvb.setMetaData("compressFrom", filePath);
407+
}
408+
406409
filePath = getCompressedFileName(filePath);
407410

408411
fs.writeFileSync(filePath, newCvb.toString(), 'utf-8');

0 commit comments

Comments
 (0)