mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 06:31:01 -07:00
fix(ide): prevent race condition when diff accepted through CLI (#7633)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user