fix(ide): prevent race condition when diff accepted through CLI (#7633)

This commit is contained in:
Shreya Keshive
2025-09-02 21:24:44 -07:00
committed by GitHub
parent cb255a1619
commit c9bd3ecf6a
2 changed files with 25 additions and 13 deletions

View File

@@ -132,7 +132,7 @@ export class DiffManager {
/**
* Closes an open diff view for a specific file.
*/
async closeDiff(filePath: string) {
async closeDiff(filePath: string, suppressNotification = false) {
let uriToClose: vscode.Uri | undefined;
for (const [uriString, diffInfo] of this.diffDocuments.entries()) {
if (diffInfo.originalFilePath === filePath) {
@@ -145,16 +145,18 @@ export class DiffManager {
const rightDoc = await vscode.workspace.openTextDocument(uriToClose);
const modifiedContent = rightDoc.getText();
await this.closeDiffEditor(uriToClose);
this.onDidChangeEmitter.fire(
IdeDiffClosedNotificationSchema.parse({
jsonrpc: '2.0',
method: 'ide/diffClosed',
params: {
filePath,
content: modifiedContent,
},
}),
);
if (!suppressNotification) {
this.onDidChangeEmitter.fire(
IdeDiffClosedNotificationSchema.parse({
jsonrpc: '2.0',
method: 'ide/diffClosed',
params: {
filePath,
content: modifiedContent,
},
}),
);
}
return modifiedContent;
}
return;

View File

@@ -356,10 +356,20 @@ const createMcpServer = (diffManager: DiffManager) => {
description: '(IDE Tool) Close an open diff view for a specific file.',
inputSchema: z.object({
filePath: z.string(),
suppressNotification: z.boolean().optional(),
}).shape,
},
async ({ filePath }: { filePath: string }) => {
const content = await diffManager.closeDiff(filePath);
async ({
filePath,
suppressNotification,
}: {
filePath: string;
suppressNotification?: boolean;
}) => {
const content = await diffManager.closeDiff(
filePath,
suppressNotification,
);
const response = { content: content ?? undefined };
return {
content: [