diff --git a/src/services/changeTracker.ts b/src/services/changeTracker.ts index c129322..d830704 100644 --- a/src/services/changeTracker.ts +++ b/src/services/changeTracker.ts @@ -143,7 +143,16 @@ class ChangeTrackerService { } const absolutePath = path.join(workspaceFolder.uri.fsPath, change.filePath); - await fs.promises.writeFile(absolutePath, change.newContent, 'utf-8'); + + // 如果是删除操作,删除文件 + if (change.changeType === 'delete') { + if (fs.existsSync(absolutePath)) { + await fs.promises.unlink(absolutePath); + } + } else { + // 创建或修改文件 + await fs.promises.writeFile(absolutePath, change.newContent, 'utf-8'); + } this.removeChange(changeId); return true; diff --git a/src/services/toolExecutor.ts b/src/services/toolExecutor.ts index b9ae30c..4e31a39 100644 --- a/src/services/toolExecutor.ts +++ b/src/services/toolExecutor.ts @@ -180,6 +180,13 @@ async function executeFileDelete(args: FileDeleteArgs): Promise { throw new Error(`不能删除目录,请指定文件路径: ${filePath}`); } + // 读取文件内容用于变更追踪 + const oldContent = fs.readFileSync(absolutePath, 'utf-8'); + + // 记录删除变更 + const relativePath = path.relative(workspacePath, absolutePath); + changeTracker.trackChange(relativePath, oldContent, ''); + // 删除文件 fs.unlinkSync(absolutePath); diff --git a/src/utils/diffRenderer.ts b/src/utils/diffRenderer.ts index 3dc3dba..f127dab 100644 --- a/src/utils/diffRenderer.ts +++ b/src/utils/diffRenderer.ts @@ -121,49 +121,68 @@ export function getDiffStyles(): string { return ` .diff-viewer { font-family: 'Consolas', 'Monaco', 'Courier New', monospace; - font-size: 12px; - line-height: 1.5; + font-size: 13px; + line-height: 1.6; background: var(--vscode-editor-background); border: 1px solid var(--vscode-panel-border); - border-radius: 4px; - overflow-x: auto; + border-radius: 6px; + overflow: hidden; } .diff-line { display: flex; align-items: center; - padding: 2px 0; + padding: 4px 0; white-space: pre; + transition: background 0.15s; + } + + .diff-line:hover { + background: var(--vscode-list-hoverBackground); } .diff-line-add { - background: rgba(40, 167, 69, 0.15); + background: rgba(40, 167, 69, 0.2); + border-left: 3px solid #28a745; + } + + .diff-line-add:hover { + background: rgba(40, 167, 69, 0.25); } .diff-line-remove { - background: rgba(220, 53, 69, 0.15); + background: rgba(220, 53, 69, 0.2); + border-left: 3px solid #dc3545; + } + + .diff-line-remove:hover { + background: rgba(220, 53, 69, 0.25); } .diff-line-context { background: transparent; + border-left: 3px solid transparent; } .line-num { display: inline-block; - width: 40px; + width: 45px; text-align: right; - padding: 0 8px; + padding: 0 10px; color: var(--vscode-editorLineNumber-foreground); user-select: none; flex-shrink: 0; + font-size: 11px; + opacity: 0.7; } .line-prefix { display: inline-block; - width: 20px; + width: 24px; text-align: center; font-weight: bold; flex-shrink: 0; + font-size: 14px; } .diff-line-add .line-prefix { @@ -176,7 +195,7 @@ export function getDiffStyles(): string { .line-content { flex: 1; - padding-right: 8px; + padding: 0 12px 0 8px; overflow-x: auto; } `; diff --git a/src/views/changePanel.ts b/src/views/changePanel.ts index 972d9f4..02ed68b 100644 --- a/src/views/changePanel.ts +++ b/src/views/changePanel.ts @@ -5,7 +5,7 @@ * 使用场景:对话结束后展示代码变更供用户审查 */ -import { getDiffStyles } from '../utils/diffRenderer'; +import { getDiffStyles } from "../utils/diffRenderer"; /** * 获取变更面板的 HTML 内容 @@ -13,15 +13,22 @@ import { getDiffStyles } from '../utils/diffRenderer'; export function getChangePanelContent(): string { return `