mirror of
https://github.com/Gmaker689/ai-diff-preview.git
synced 2026-09-27 15:31:51 +08:00
v0.2.0: VSCode内置Diff + QuickPick总览 + EditRecord粒度 + Bug修复
新增: - VSCode内置Diff编辑器 (diffViewer.ts) 替代Webview,零保存提示 - EditRecord独立追踪: 每次Edit/Write不合并,支持逐次编辑Accept/Reject - QuickPick文件列表总览,含Accept All / Reject All - 智能Auto-Advance: Accept/Reject后自动推进,同文件多编辑智能停留 - 状态栏常驻显示 AI Diff,Diff模式下切换为操作按钮 修复: - Accept后同文件再编辑不触发选项 (pending-priority匹配) - Accept All / Reject All写入与状态顺序修复 - acceptFile/rejectFile改为先写入成功再标记状态 - 同文件多个FileChange孤儿编辑问题 变更: - ChangeSetManager重构为EditRecord[] + FileChange聚合 - HookHandler精简,QuickPick移入hookHandler - 移除InlineDecorator/CodeLens (主流程),ReviewPanel降级为备用 - package.json: publisher=YonHao Guo, repository, v0.2.0, 新配置项/快捷键 测试: 13/13通过 (7 diffEngine + 6 changeSetManager回归)
This commit is contained in:
+106
-49
@@ -1,70 +1,127 @@
|
||||
/**
|
||||
* 状态栏管理器 - 显示 Diff 状态信息
|
||||
* 状态栏管理器 — 常驻显示
|
||||
*
|
||||
* 始终在左侧状态栏显示 AI Diff 状态:
|
||||
* - 有 pending 变更: $(diff) AI Diff: N文件 M编辑 (黄色) — 点击打开文件列表
|
||||
* - Diff 活跃: 右侧额外显示 Accept/Reject 按钮
|
||||
* - 无变更: $(diff) AI Diff (暗色) — 点击打开文件列表
|
||||
*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { Snapshot } from '../models/types';
|
||||
import { STATUS_BAR_PRIORITY } from '../models/constants';
|
||||
import { ChangeSetManager } from '../snapshot/snapshotManager';
|
||||
import { DiffViewer, DiffSession } from './diffViewer';
|
||||
import { COMMANDS } from '../models/constants';
|
||||
|
||||
export class StatusBarManager {
|
||||
private statusBarItem: vscode.StatusBarItem;
|
||||
private chunkCountItem: vscode.StatusBarItem;
|
||||
/** ★ 常驻摘要按钮 */
|
||||
private summaryItem: vscode.StatusBarItem;
|
||||
/** Diff 模式 Accept 按钮 */
|
||||
private acceptBtn: vscode.StatusBarItem;
|
||||
/** Diff 模式 Reject 按钮 */
|
||||
private rejectBtn: vscode.StatusBarItem;
|
||||
/** Diff 模式 Accept All 按钮 */
|
||||
private acceptAllBtn: vscode.StatusBarItem;
|
||||
|
||||
constructor() {
|
||||
this.statusBarItem = vscode.window.createStatusBarItem(
|
||||
constructor(
|
||||
private changeSetManager: ChangeSetManager,
|
||||
private diffViewer: DiffViewer
|
||||
) {
|
||||
// ★ 常驻摘要 — 始终显示
|
||||
this.summaryItem = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Left,
|
||||
STATUS_BAR_PRIORITY.DIFF_STATUS
|
||||
100
|
||||
);
|
||||
this.summaryItem.command = COMMANDS.SHOW_DIFF_PANEL;
|
||||
this.summaryItem.text = '$(diff) AI Diff';
|
||||
this.summaryItem.tooltip = 'AI Diff — 点击查看变更列表';
|
||||
this.summaryItem.show();
|
||||
|
||||
this.chunkCountItem = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Left,
|
||||
STATUS_BAR_PRIORITY.CHUNK_COUNT
|
||||
// Accept 按钮
|
||||
this.acceptBtn = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Right,
|
||||
100
|
||||
);
|
||||
this.acceptBtn.command = 'aiDiffPreview.acceptCurrentDiff';
|
||||
|
||||
// Reject 按钮
|
||||
this.rejectBtn = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Right,
|
||||
99
|
||||
);
|
||||
this.rejectBtn.command = 'aiDiffPreview.rejectCurrentDiff';
|
||||
|
||||
// Accept All 按钮
|
||||
this.acceptAllBtn = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Right,
|
||||
98
|
||||
);
|
||||
this.acceptAllBtn.command = 'aiDiffPreview.acceptAllFromDiff';
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态栏
|
||||
*/
|
||||
update(snapshot: Snapshot): void {
|
||||
const pendingChunks = snapshot.chunks.filter(c => c.status === 'pending');
|
||||
const conflictChunks = snapshot.chunks.filter(c => c.status === 'conflict');
|
||||
enterDiffMode(session: DiffSession): void {
|
||||
const label = session.editId ? '编辑' : '文件';
|
||||
this.acceptBtn.text = `$(check) Accept 本次${label}变更`;
|
||||
this.acceptBtn.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
|
||||
this.acceptBtn.tooltip = `接受此${label}的变更并跳转到下一个`;
|
||||
this.acceptBtn.show();
|
||||
|
||||
// 更新主状态
|
||||
this.statusBarItem.text = '$(diff) AI Diff';
|
||||
this.statusBarItem.tooltip = 'AI Diff Preview 活跃';
|
||||
this.statusBarItem.show();
|
||||
this.rejectBtn.text = `$(close) Reject 本次${label}变更`;
|
||||
this.rejectBtn.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground');
|
||||
this.rejectBtn.tooltip = `拒绝此${label}的变更并跳转到下一个`;
|
||||
this.rejectBtn.show();
|
||||
|
||||
// 更新变更块数量
|
||||
if (pendingChunks.length > 0 || conflictChunks.length > 0) {
|
||||
this.chunkCountItem.text = `$(edit) ${pendingChunks.length} 个变更`;
|
||||
if (conflictChunks.length > 0) {
|
||||
this.chunkCountItem.text += ` (${conflictChunks.length} 个冲突)`;
|
||||
this.chunkCountItem.backgroundColor = new vscode.ThemeColor(
|
||||
'statusBarItem.warningBackground'
|
||||
);
|
||||
} else {
|
||||
this.chunkCountItem.backgroundColor = undefined;
|
||||
}
|
||||
this.chunkCountItem.tooltip = '点击查看变更详情';
|
||||
this.chunkCountItem.show();
|
||||
this.acceptAllBtn.text = '$(check-all) 接受此文件全部';
|
||||
this.acceptAllBtn.tooltip = '接受此文件的所有编辑';
|
||||
this.acceptAllBtn.show();
|
||||
}
|
||||
|
||||
exitDiffMode(): void {
|
||||
this.acceptBtn.hide();
|
||||
this.rejectBtn.hide();
|
||||
this.acceptAllBtn.hide();
|
||||
}
|
||||
|
||||
/** ★ 常驻刷新 */
|
||||
refresh(): void {
|
||||
const session = this.diffViewer.getActiveSession();
|
||||
if (session) {
|
||||
this.enterDiffMode(session);
|
||||
} else {
|
||||
this.chunkCountItem.hide();
|
||||
this.exitDiffMode();
|
||||
}
|
||||
|
||||
const set = this.changeSetManager.getCurrentSet();
|
||||
if (!set) {
|
||||
// ★ 无变更集也常驻显示
|
||||
this.summaryItem.text = '$(diff) AI Diff';
|
||||
this.summaryItem.tooltip = 'AI Diff — 等待变更';
|
||||
this.summaryItem.backgroundColor = undefined;
|
||||
this.summaryItem.show();
|
||||
return;
|
||||
}
|
||||
|
||||
const pendingFiles = set.changes.filter(c => c.status === 'pending');
|
||||
const totalEdits = pendingFiles.reduce(
|
||||
(sum, c) => sum + c.edits.filter(e => e.status === 'pending').length, 0
|
||||
);
|
||||
|
||||
if (pendingFiles.length === 0 && set.changes.length > 0) {
|
||||
this.summaryItem.text = '$(diff) AI Diff: 已完成';
|
||||
this.summaryItem.tooltip = '所有变更已处理';
|
||||
this.summaryItem.backgroundColor = undefined;
|
||||
} else if (pendingFiles.length > 0) {
|
||||
this.summaryItem.text = `$(diff) AI Diff: ${pendingFiles.length}文件 ${totalEdits}编辑`;
|
||||
this.summaryItem.tooltip = `点击查看变更列表\n${pendingFiles.map(c => `• ${c.filePath} (${c.edits.length}次)`).join('\n')}`;
|
||||
this.summaryItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
|
||||
}
|
||||
|
||||
this.summaryItem.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除状态栏
|
||||
*/
|
||||
clear(): void {
|
||||
this.statusBarItem.hide();
|
||||
this.chunkCountItem.hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放资源
|
||||
*/
|
||||
dispose(): void {
|
||||
this.statusBarItem.dispose();
|
||||
this.chunkCountItem.dispose();
|
||||
this.summaryItem.dispose();
|
||||
this.acceptBtn.dispose();
|
||||
this.rejectBtn.dispose();
|
||||
this.acceptAllBtn.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user