mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -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.
|
* Closes an open diff view for a specific file.
|
||||||
*/
|
*/
|
||||||
async closeDiff(filePath: string) {
|
async closeDiff(filePath: string, suppressNotification = false) {
|
||||||
let uriToClose: vscode.Uri | undefined;
|
let uriToClose: vscode.Uri | undefined;
|
||||||
for (const [uriString, diffInfo] of this.diffDocuments.entries()) {
|
for (const [uriString, diffInfo] of this.diffDocuments.entries()) {
|
||||||
if (diffInfo.originalFilePath === filePath) {
|
if (diffInfo.originalFilePath === filePath) {
|
||||||
@@ -145,6 +145,7 @@ export class DiffManager {
|
|||||||
const rightDoc = await vscode.workspace.openTextDocument(uriToClose);
|
const rightDoc = await vscode.workspace.openTextDocument(uriToClose);
|
||||||
const modifiedContent = rightDoc.getText();
|
const modifiedContent = rightDoc.getText();
|
||||||
await this.closeDiffEditor(uriToClose);
|
await this.closeDiffEditor(uriToClose);
|
||||||
|
if (!suppressNotification) {
|
||||||
this.onDidChangeEmitter.fire(
|
this.onDidChangeEmitter.fire(
|
||||||
IdeDiffClosedNotificationSchema.parse({
|
IdeDiffClosedNotificationSchema.parse({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
@@ -155,6 +156,7 @@ export class DiffManager {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return modifiedContent;
|
return modifiedContent;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -356,10 +356,20 @@ const createMcpServer = (diffManager: DiffManager) => {
|
|||||||
description: '(IDE Tool) Close an open diff view for a specific file.',
|
description: '(IDE Tool) Close an open diff view for a specific file.',
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
filePath: z.string(),
|
filePath: z.string(),
|
||||||
|
suppressNotification: z.boolean().optional(),
|
||||||
}).shape,
|
}).shape,
|
||||||
},
|
},
|
||||||
async ({ filePath }: { filePath: string }) => {
|
async ({
|
||||||
const content = await diffManager.closeDiff(filePath);
|
filePath,
|
||||||
|
suppressNotification,
|
||||||
|
}: {
|
||||||
|
filePath: string;
|
||||||
|
suppressNotification?: boolean;
|
||||||
|
}) => {
|
||||||
|
const content = await diffManager.closeDiff(
|
||||||
|
filePath,
|
||||||
|
suppressNotification,
|
||||||
|
);
|
||||||
const response = { content: content ?? undefined };
|
const response = { content: content ?? undefined };
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
|
|||||||
Reference in New Issue
Block a user