feat(vscode-ide-companion/extension): relay diff accept/cancel events to chat webview

Added functionality to relay diff accepted/cancelled events from the IDE to the chat webview
so users get immediate feedback when they accept or cancel diffs in the Claude Code style.
This commit is contained in:
yiliang114
2025-12-05 02:45:44 +08:00
parent 2d844d11df
commit 8203f6582f
5 changed files with 78 additions and 15 deletions

View File

@@ -5,6 +5,7 @@
*/
import * as vscode from 'vscode';
import * as path from 'node:path';
import { IDEServer } from './ide-server.js';
import semver from 'semver';
import { DiffContentProvider, DiffManager } from './diff-manager.js';
@@ -166,6 +167,45 @@ export async function activate(context: vscode.ExtensionContext) {
createWebViewProvider,
);
// Relay diff accept/cancel events to the chat webview as assistant notices
// so the user sees immediate feedback in the chat thread (Claude Code style).
context.subscriptions.push(
diffManager.onDidChange((notification) => {
try {
const method = (notification as { method?: string }).method;
if (method !== 'ide/diffAccepted' && method !== 'ide/diffClosed') {
return;
}
const params = (
notification as unknown as {
params?: { filePath?: string };
}
).params;
const filePath = params?.filePath ?? '';
const fileBase = filePath ? path.basename(filePath) : '';
const text =
method === 'ide/diffAccepted'
? `Accepted changes${fileBase ? ` to ${fileBase}` : ''}.`
: `Cancelled changes${fileBase ? ` to ${fileBase}` : ''}.`;
for (const provider of webViewProviders) {
const panel = provider.getPanel();
panel?.webview.postMessage({
type: 'message',
data: {
role: 'assistant',
content: text,
timestamp: Date.now(),
},
});
}
} catch (e) {
console.warn('[Extension] Failed to relay diff event to chat:', e);
}
}),
);
context.subscriptions.push(
vscode.workspace.onDidCloseTextDocument((doc) => {
if (doc.uri.scheme === DIFF_SCHEME) {