Skip to content

Commit b0fab5e

Browse files
authored
fix(amazonq): Fix code generation error when cancelling /doc task (#5241)
* fix(amazonq): Fix code generation error when cancelling /doc task * fix isEmpty lint failure
1 parent effbebd commit b0fab5e

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "/doc: Fix code generation error when cancelling a documentation task"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class DocController(
226226
if (session.sessionState.token?.token !== null) {
227227
session.sessionState.token?.cancel()
228228
}
229+
230+
docGenerationTask.reset()
231+
newTask(message.tabId)
229232
}
230233

231234
private suspend fun updateDocumentation(tabId: String) {
@@ -490,6 +493,8 @@ class DocController(
490493
message = message("amazonqFeatureDev.chat_message.ask_for_new_task")
491494
)
492495

496+
messenger.sendUpdatePromptProgress(tabId, null)
497+
493498
messenger.sendUpdatePlaceholder(
494499
tabId = tabId,
495500
newPlaceholder = message("amazonqFeatureDev.placeholder.after_code_generation")
@@ -710,9 +715,11 @@ class DocController(
710715
else -> emptyList()
711716
}
712717

713-
processOpenDiff(
714-
message = IncomingDocMessage.OpenDiff(tabId = tabId, filePath = filePaths[0].zipFilePath, deleted = false)
715-
)
718+
if (filePaths.isNotEmpty()) {
719+
processOpenDiff(
720+
message = IncomingDocMessage.OpenDiff(tabId = tabId, filePath = filePaths[0].zipFilePath, deleted = false)
721+
)
722+
}
716723
} catch (err: Exception) {
717724
processErrorChatMessage(err, session, tabId)
718725

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocControllerExtensions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ suspend fun DocController.onCodeGeneration(session: DocSession, message: String,
4444

4545
session.send(sessionMessage) // Trigger code generation
4646

47+
if (session.sessionState.token
48+
?.token
49+
?.isCancellationRequested() == true
50+
) {
51+
return
52+
}
53+
4754
val state = session.sessionState
4855

4956
var filePaths: List<NewFileZipInfo> = emptyList()

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/session/DocGenerationState.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.controller.Mode
1717
import software.aws.toolkits.jetbrains.services.amazonqDoc.controller.docGenerationProgressMessage
1818
import software.aws.toolkits.jetbrains.services.amazonqDoc.docServiceError
1919
import software.aws.toolkits.jetbrains.services.amazonqDoc.inProgress
20-
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.DocMessageType
21-
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUp
22-
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUpTypes
23-
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendAnswer
2420
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendAnswerPart
2521
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress
2622
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeGenerationResult
@@ -114,24 +110,6 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, mo
114110

115111
repeat(pollCount) {
116112
if (token?.token?.isCancellationRequested() == true) {
117-
// This should be switched to newTask or something. Looks different than previously and may need to clean up previous run
118-
messenger.sendUpdatePromptProgress(tabId = tabID, null)
119-
messenger.sendAnswer(
120-
messageType = DocMessageType.SystemPrompt,
121-
tabId = tabID,
122-
followUp = listOf(
123-
FollowUp(
124-
pillText = message("amazonqDoc.prompt.create"),
125-
prompt = message("amazonqDoc.prompt.create"),
126-
type = FollowUpTypes.CREATE_DOCUMENTATION,
127-
),
128-
FollowUp(
129-
pillText = message("amazonqDoc.prompt.update"),
130-
prompt = message("amazonqDoc.prompt.update"),
131-
type = FollowUpTypes.UPDATE_DOCUMENTATION,
132-
)
133-
)
134-
)
135113
return CodeGenerationResult(emptyList(), emptyList(), emptyList())
136114
}
137115

0 commit comments

Comments
 (0)