Skip to content

Commit cd5b484

Browse files
committed
fix(amazonq): Fix code generation error when cancelling /doc task
1 parent 2e39dc0 commit cd5b484

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
@@ -239,6 +239,9 @@ class DocController(
239239
if (session.sessionState.token?.token !== null) {
240240
session.sessionState.token?.cancel()
241241
}
242+
243+
docGenerationTask.reset()
244+
newTask(message.tabId)
242245
}
243246

244247
private suspend fun updateDocumentation(tabId: String) {
@@ -588,6 +591,8 @@ class DocController(
588591
message = message("amazonqFeatureDev.chat_message.ask_for_new_task")
589592
)
590593

594+
messenger.sendUpdatePromptProgress(tabId, null)
595+
591596
messenger.sendUpdatePlaceholder(
592597
tabId = tabId,
593598
newPlaceholder = message("amazonqFeatureDev.placeholder.after_code_generation")
@@ -824,9 +829,11 @@ class DocController(
824829
else -> emptyList()
825830
}
826831

827-
processOpenDiff(
828-
message = IncomingDocMessage.OpenDiff(tabId = tabId, filePath = filePaths[0].zipFilePath, deleted = false)
829-
)
832+
if (!filePaths.isEmpty()) {
833+
processOpenDiff(
834+
message = IncomingDocMessage.OpenDiff(tabId = tabId, filePath = filePaths[0].zipFilePath, deleted = false)
835+
)
836+
}
830837
} catch (err: Exception) {
831838
processErrorChatMessage(err, session, tabId)
832839

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
@@ -144,24 +140,6 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, to
144140

145141
repeat(pollCount) {
146142
if (token?.token?.isCancellationRequested() == true) {
147-
// This should be switched to newTask or something. Looks different than previously and may need to clean up previous run
148-
messenger.sendUpdatePromptProgress(tabId = tabID, null)
149-
messenger.sendAnswer(
150-
messageType = DocMessageType.SystemPrompt,
151-
tabId = tabID,
152-
followUp = listOf(
153-
FollowUp(
154-
pillText = message("amazonqDoc.prompt.create"),
155-
prompt = message("amazonqDoc.prompt.create"),
156-
type = FollowUpTypes.CREATE_DOCUMENTATION,
157-
),
158-
FollowUp(
159-
pillText = message("amazonqDoc.prompt.update"),
160-
prompt = message("amazonqDoc.prompt.update"),
161-
type = FollowUpTypes.UPDATE_DOCUMENTATION,
162-
)
163-
)
164-
)
165143
return CodeGenerationResult(emptyList(), emptyList(), emptyList())
166144
}
167145

0 commit comments

Comments
 (0)