diff --git a/src/core/tools/WriteToFileTool.ts b/src/core/tools/WriteToFileTool.ts index 24690f26ad..3bfee40000 100644 --- a/src/core/tools/WriteToFileTool.ts +++ b/src/core/tools/WriteToFileTool.ts @@ -330,11 +330,11 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> { const partialMessage = JSON.stringify(sharedMessageProps) await task.ask("tool", partialMessage, block.partial).catch(() => {}) - if (newContent) { - if (!task.diffViewProvider.isEditing) { - await task.diffViewProvider.open(relPath) - } + if (!task.diffViewProvider.isEditing) { + await task.diffViewProvider.open(relPath) + } + if (newContent) { await task.diffViewProvider.update( everyLineHasLineNumbers(newContent) ? stripLineNumbers(newContent) : newContent, false, diff --git a/src/core/tools/__tests__/writeToFileTool.spec.ts b/src/core/tools/__tests__/writeToFileTool.spec.ts index 714269795e..d300e02f36 100644 --- a/src/core/tools/__tests__/writeToFileTool.spec.ts +++ b/src/core/tools/__tests__/writeToFileTool.spec.ts @@ -354,10 +354,13 @@ describe("writeToFileTool", () => { expect(mockCline.diffViewProvider.open).not.toHaveBeenCalled() }) - it("returns early when content is undefined in partial block", async () => { + it("opens file even when content is undefined in partial block", async () => { await executeWriteFileTool({ content: undefined }, { isPartial: true }) - expect(mockCline.diffViewProvider.open).not.toHaveBeenCalled() + // File should be opened to create it, even if content is not yet available + expect(mockCline.diffViewProvider.open).toHaveBeenCalledWith(testFilePath) + // But update should not be called since there's no content + expect(mockCline.diffViewProvider.update).not.toHaveBeenCalled() }) it("streams content updates during partial execution", async () => {