From 97d798f8e16a9aa620e11cc1de5de2153885fba8 Mon Sep 17 00:00:00 2001 From: C Tidd Date: Mon, 25 Nov 2024 19:08:52 -0800 Subject: [PATCH] fix(amazonq): Normalize generated file paths in feature dev. --- .../bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json | 4 ++++ .../amazonqFeatureDev/session/CodeGenerationState.kt | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json diff --git a/.changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json b/.changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json new file mode 100644 index 00000000000..aefce81abcf --- /dev/null +++ b/.changes/next-release/bugfix-fd7f4f61-241e-40a6-b92a-3e4fe7e832db.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Amazon Q /dev: Fix error when accepting changes if leading slash is present." +} diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt index 5b172e73c7d..f0aa2e8f41c 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt @@ -258,7 +258,8 @@ private suspend fun CodeGenerationState.generateCode( fun registerNewFiles(newFileContents: Map): List = newFileContents.map { NewFileZipInfo( - zipFilePath = it.key, + // Note: When managing file state, we normalize file paths returned from the agent in order to ensure they are handled as relative paths. + zipFilePath = it.key.removePrefix("/"), fileContent = it.value, rejected = false, changeApplied = false @@ -268,7 +269,8 @@ fun registerNewFiles(newFileContents: Map): List fun registerDeletedFiles(deletedFiles: List): List = deletedFiles.map { DeletedFileInfo( - zipFilePath = it, + // Note: When managing file state, we normalize file paths returned from the agent in order to ensure they are handled as relative paths. + zipFilePath = it.removePrefix("/"), rejected = false, changeApplied = false )