From ba5282285d0b24a355c9ea7e106b3ca08f37806c Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Thu, 1 Aug 2024 15:40:07 +0200 Subject: [PATCH] Do not override content of the existing files --- .../com/sourcegraph/utils/CodyEditorUtil.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/sourcegraph/utils/CodyEditorUtil.kt b/src/main/kotlin/com/sourcegraph/utils/CodyEditorUtil.kt index db921914a5..312d6be0ba 100644 --- a/src/main/kotlin/com/sourcegraph/utils/CodyEditorUtil.kt +++ b/src/main/kotlin/com/sourcegraph/utils/CodyEditorUtil.kt @@ -28,7 +28,7 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.ex.temp.TempFileSystem import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.withScheme -import com.sourcegraph.cody.agent.protocol_extensions.* +import com.sourcegraph.cody.agent.protocol_extensions.toOffset import com.sourcegraph.cody.agent.protocol_generated.Range import com.sourcegraph.config.ConfigUtil import java.net.URI @@ -211,13 +211,16 @@ object CodyEditorUtil { if (!fileUri.toPath().exists()) { fileUri.toPath().parent?.createDirectories() fileUri.toPath().createFile() - } + val vf = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(fileUri.toPath()) - val vf = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(fileUri.toPath()) - content?.let { - WriteCommandAction.runWriteCommandAction(project) { vf?.setBinaryContent(it.toByteArray()) } + content?.let { + WriteCommandAction.runWriteCommandAction(project) { + vf?.setBinaryContent(it.toByteArray()) + } + } } - return vf + + return LocalFileSystem.getInstance().refreshAndFindFileByNioFile(fileUri.toPath()) } catch (e: URISyntaxException) { val fileName = uriString.substringAfterLast(':').trimStart('/', '\\') val fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName)