Skip to content

Commit

Permalink
fix(amazonq): /doc fix prompt to change folder in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Shesternyak committed Jan 22, 2025
1 parent e9e2d8b commit 20c164a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Amazon Q /doc: fix for user prompt to change folder in chat"
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendCodeResu
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendError
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendFolderConfirmationMessage
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendMonthlyLimitError
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendRetryChangeFolderMessage
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendSystemPrompt
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePlaceholder
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress
Expand Down Expand Up @@ -337,6 +338,31 @@ class DocController(
}
}

private suspend fun promptForRetryFolderSelection(tabId: String, message: String) {
messenger.sendRetryChangeFolderMessage(
tabId = tabId,
message = message,
followUps = listOf(
FollowUp(
icon = FollowUpIcons.Refresh,
pillText = message("amazonqDoc.prompt.folder.change"),
prompt = message("amazonqDoc.prompt.folder.change"),
status = FollowUpStatusType.Info,
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER
),
FollowUp(
icon = FollowUpIcons.Cancel,
pillText = message("general.cancel"),
prompt = message("general.cancel"),
status = FollowUpStatusType.Error,
type = FollowUpTypes.CANCEL_FOLDER_SELECTION
),
)
)

messenger.sendChatInputEnabledMessage(tabId, false)
}

override suspend fun processLinkClick(message: IncomingDocMessage.ClickedLink) {
BrowserUtil.browse(message.link)
}
Expand Down Expand Up @@ -914,11 +940,22 @@ class DocController(
val projectRoot = session.context.projectRoot

withContext(EDT) {
messenger.sendAnswer(
tabId = tabId,
messageType = DocMessageType.Answer,
message = message("amazonqDoc.prompt.choose_folder_to_continue")
)

val selectedFolder = selectFolder(context.project, currentSourceFolder)

// No folder was selected
if (selectedFolder == null) {
logger.info { "Cancelled dialog and not selected any folder" }
promptForRetryFolderSelection(
tabId,
message("amazonqDoc.prompt.canceled_source_folder_selection")
)

return@withContext
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ data class FolderConfirmationMessage(
type = "folderConfirmationMessage"
)

data class RetryChangeFolderMessage(
@JsonProperty("tabID") override val tabId: String,
val message: String,
val followUps: List<FollowUp>?,
) : UiMessage(
tabId = tabId,
type = "retryChangeFolderMessage"
)

// this should come from mynah?
data class ChatItemButton(
val id: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ suspend fun MessagePublisher.sendFolderConfirmationMessage(
)
}

suspend fun MessagePublisher.sendRetryChangeFolderMessage(
tabId: String,
message: String,
followUps: List<FollowUp>,
) {
this.publish(
RetryChangeFolderMessage(tabId = tabId, message = message, followUps = followUps)
)
}

suspend fun MessagePublisher.sendUpdatePromptProgress(tabId: String, progressField: ProgressField?) {
this.publish(
PromptProgressMessage(tabId, progressField)
Expand Down
20 changes: 20 additions & 0 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/docChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ export class Connector {
}
}

private processRetryChangeFolderMessage = async (messageData: any): Promise<void> => {
if (this.onChatAnswerReceived !== undefined) {
const answer: ChatItem = {
type: ChatItemType.ANSWER,
body: messageData.message ?? undefined,
messageId: messageData.messageID ?? messageData.triggerID ?? '',
followUp: {
text: '',
options: messageData.followUps,
},
}
this.onChatAnswerReceived(messageData.tabID, answer)
}
}

private processChatMessage = async (messageData: any): Promise<void> => {
if (this.onChatAnswerReceived !== undefined) {
const answer: ChatItem = {
Expand Down Expand Up @@ -263,6 +278,11 @@ export class Connector {
return
}

if (messageData.type === 'retryChangeFolderMessage') {
await this.processRetryChangeFolderMessage(messageData)
return
}

if (messageData.type === 'chatMessage') {
await this.processChatMessage(messageData)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ amazonqDoc.progress_message.generating=Generating documentation
amazonqDoc.progress_message.scanning=Scanning source files
amazonqDoc.progress_message.summarizing=Summarizing source files
amazonqDoc.progress_message.updating=Okay, I'm updating the README.
amazonqDoc.prompt.canceled_source_folder_selection=It looks like you didn't choose a folder. Choose a folder to continue.
amazonqDoc.prompt.choose_folder_to_continue=Choose a folder to continue
amazonqDoc.prompt.create=Create a README
amazonqDoc.prompt.create.confirmation=Create a README for this project?
amazonqDoc.prompt.folder.change=Change folder
Expand Down

0 comments on commit 20c164a

Please sign in to comment.