Skip to content

Commit 09b699c

Browse files
committed
add one more util call to oldUri in didRename
1 parent be696d8 commit 09b699c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandler.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ class WorkspaceServiceHandler(
104104
.filter { it.propertyName == VirtualFile.PROP_NAME }
105105
.mapNotNull { event ->
106106
val file = event.file.takeIf { shouldHandleFile(it) } ?: return@mapNotNull null
107-
val oldName = event.oldValue as? String ?: return@mapNotNull null
108107
if (event.newValue !is String) return@mapNotNull null
109108

110109
// Construct old and new URIs
111-
val parentPath = file.parent?.toNioPath() ?: return@mapNotNull null
112-
val oldUri = parentPath.resolve(oldName).toUri().toString()
110+
val parentFile = file.parent ?: return@mapNotNull null
111+
val oldUri = toUriString(parentFile)
113112
val newUri = toUriString(file)
114113

115114
FileRename().apply {

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandlerTest.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class WorkspaceServiceHandlerTest {
291291
val paramsSlot = slot<RenameFilesParams>()
292292
verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
293293
with(paramsSlot.captured.files[0]) {
294-
assertEquals("file:///test/$oldName", oldUri)
294+
assertEquals(normalizeFileUri("file:///test/$oldName"), oldUri)
295295
assertEquals(normalizeFileUri("file:///test/$newName"), newUri)
296296
}
297297
}
@@ -328,7 +328,7 @@ class WorkspaceServiceHandlerTest {
328328
val paramsSlot = slot<RenameFilesParams>()
329329
verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
330330
with(paramsSlot.captured.files[0]) {
331-
assertEquals("file:///test/oldDir", oldUri)
331+
assertEquals(normalizeFileUri("file:///test/oldDir"), oldUri)
332332
assertEquals(normalizeFileUri("file:///test/newDir"), newUri)
333333
}
334334
}
@@ -539,19 +539,28 @@ class WorkspaceServiceHandlerTest {
539539
newName: String,
540540
isDirectory: Boolean = false,
541541
): VFilePropertyChangeEvent {
542-
val file = mockk<VirtualFile>()
543-
val parent = mockk<VirtualFile>()
544542
val parentPath = mockk<Path>()
545543
val filePath = mockk<Path>()
546544

547-
every { file.parent } returns parent
548-
every { parent.toNioPath() } returns parentPath
549-
every { file.toNioPath() } returns filePath
550-
every { file.isDirectory } returns isDirectory
551-
every { file.path } returns "/test/$newName"
552-
every { file.url } returns "file:///test/$newName"
553-
every { file.fileSystem } returns mockk {
554-
every { protocol } returns "file"
545+
val parent = mockk<VirtualFile> {
546+
every { toNioPath() } returns parentPath
547+
every { this@mockk.isDirectory } returns isDirectory
548+
every { path } returns "/test/$oldName"
549+
every { url } returns "file:///test/$oldName"
550+
every { fileSystem } returns mockk {
551+
every { protocol } returns "file"
552+
}
553+
}
554+
555+
val file = mockk<VirtualFile> {
556+
every { toNioPath() } returns filePath
557+
every { this@mockk.parent } returns parent
558+
every { this@mockk.isDirectory } returns isDirectory
559+
every { path } returns "/test/$newName"
560+
every { url } returns "file:///test/$newName"
561+
every { fileSystem } returns mockk {
562+
every { protocol } returns "file"
563+
}
555564
}
556565

557566
every { parentPath.resolve(oldName) } returns mockk {

0 commit comments

Comments
 (0)