Skip to content

Commit

Permalink
Fix Generate Unit Test on Windows (#1478)
Browse files Browse the repository at this point in the history
Fixes #1436.

Btw it fixes an issue with an error when closing a file that's content
is being generated.


## Test plan
1. `Generate Unit Test` on both Windows and macOs
  • Loading branch information
mkondratek committed May 15, 2024
1 parent f3b4993 commit 619bf08
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 47 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ kotlin.stdlib.default.dependency=false
nodeBinaries.commit=8755ae4c05fd476cd23f2972049111ba436c86d4
nodeBinaries.version=v20.12.2
cody.autocomplete.enableFormatting=true
cody.commit=38885b4bd403acfca984afbe45cd50b600319ca1
cody.commit=bcbd5ee0dfc2dcb5f126ca0388cadeabf8b92875
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class CodyAgentService(private val project: Project) : Disposable {
}

agent.client.onOpenUntitledDocument = Function { params ->
// We always get a file which does not start with file:// there.
// They start with untitled:// which is VSCode-specific way
// to say that files does not exist on the disk yet.
val uri = URI.create(params.uri).withScheme("file")
if (CodyEditorUtil.createFileIfNeeded(project, uri, params.content) == null)
return@Function false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.sourcegraph.cody.agent.protocol
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.vfs.VirtualFile
import com.sourcegraph.cody.agent.protocol.util.Rfc3986UriEncoder
import java.nio.file.FileSystems
import java.util.Locale

class ProtocolTextDocument
private constructor(
Expand Down Expand Up @@ -47,8 +48,13 @@ private constructor(
return ProtocolTextDocument(uriFor(file), text, selection)
}

fun uriFor(file: VirtualFile): String {
return Rfc3986UriEncoder.encode(file.url)
private fun uriFor(file: VirtualFile): String {
val uri = FileSystems.getDefault().getPath(file.path).toUri().toString()
return uri.replace(Regex("file:///(\\w):/")) {
val driveLetter =
it.groups[1]?.value?.lowercase(Locale.getDefault()) ?: return@replace it.value
"file:///$driveLetter%3A/"
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ abstract class FixupSession(
val future = group.show(range)
// Make sure the lens is visible.
ApplicationManager.getApplication().invokeLater {
val logicalPosition = LogicalPosition(range.start.line, range.start.character)
editor.scrollingModel.scrollTo(logicalPosition, ScrollType.CENTER)
if (!editor.isDisposed) {
val logicalPosition = LogicalPosition(range.start.line, range.start.character)
editor.scrollingModel.scrollTo(logicalPosition, ScrollType.CENTER)
}
}
if (!ApplicationManager.getApplication().isDispatchThread) { // integration test
future.get()
Expand Down

This file was deleted.

0 comments on commit 619bf08

Please sign in to comment.