Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amazonq): /doc fix prompt to change folder in chat #5249

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description" : "Amazon Q /doc: fix for user prompt to change folder in chat"
"description" : "Amazon Q /doc: Prompt user to choose a folder if no folder was selected"

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
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 @@ -259,7 +260,7 @@
private suspend fun makeChanges(tabId: String) {
messenger.sendAnswer(
tabId = tabId,
message = message("amazonqDoc.edit.message"),

Check warning on line 263 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
messageType = DocMessageType.Answer
)

Expand Down Expand Up @@ -337,6 +338,31 @@
}
}

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"),
Fixed Show fixed Hide fixed
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 @@ -480,7 +506,7 @@
val message = createUserFacingErrorMessage("Failed to insert code changes: ${err.message}")
messenger.sendError(
tabId = tabId,
errMessage = message ?: message("amazonqFeatureDev.exception.insert_code_failed"),

Check warning on line 509 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
retries = retriesRemaining(session),
conversationId = session?.conversationIdUnsafe
)
Expand Down Expand Up @@ -511,7 +537,7 @@
followUp = listOf(
FollowUp(
pillText = message("amazonqDoc.prompt.create"),
prompt = message("amazonqDoc.prompt.create"),

Check warning on line 540 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
type = FollowUpTypes.CREATE_DOCUMENTATION,
),
FollowUp(
Expand Down Expand Up @@ -646,7 +672,7 @@
),
FollowUp(
pillText = message("general.reject"),
prompt = message("general.reject"),

Check warning on line 675 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
status = FollowUpStatusType.Error,
type = FollowUpTypes.REJECT_CHANGES,
icon = FollowUpIcons.Cancel,
Expand Down Expand Up @@ -886,7 +912,7 @@
val message = createUserFacingErrorMessage("Failed to retry request: ${err.message}")
messenger.sendError(
tabId = tabId,
errMessage = message ?: message("amazonqFeatureDev.exception.retry_request_failed"),

Check warning on line 915 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
retries = retriesRemaining(session),
conversationId = session?.conversationIdUnsafe,
)
Expand Down Expand Up @@ -914,11 +940,22 @@
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 Expand Up @@ -960,7 +997,7 @@

messenger.sendChatInputEnabledMessage(tabId, enabled = false)

messenger.sendUpdatePlaceholder(tabId = tabId, newPlaceholder = message("amazonqDoc.prompt.placeholder"))

Check warning on line 1000 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
}
}

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
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
Loading