Skip to content

Commit 2129775

Browse files
authored
feat(amazonq): hook up showMessage/logMessage/showDocument correctly (#5720)
logMessage incorrectly piped everything through showMessage, and showDocument did not respect the `external` flag
1 parent 760f08f commit 2129775

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package software.aws.toolkits.jetbrains.services.amazonq.lsp
55

66
import com.intellij.diff.DiffContentFactory
77
import com.intellij.diff.requests.SimpleDiffRequest
8+
import com.intellij.ide.BrowserUtil
9+
import com.intellij.notification.NotificationType
810
import com.intellij.openapi.application.ApplicationManager
911
import com.intellij.openapi.fileChooser.FileChooserFactory
1012
import com.intellij.openapi.fileChooser.FileSaverDescriptor
@@ -48,6 +50,8 @@ import software.aws.toolkits.jetbrains.services.amazonq.lsp.util.TelemetryParsin
4850
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
4951
import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
5052
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
53+
import software.aws.toolkits.jetbrains.utils.getCleanedContent
54+
import software.aws.toolkits.jetbrains.utils.notify
5155
import software.aws.toolkits.resources.message
5256
import java.io.File
5357
import java.nio.file.Files
@@ -101,19 +105,12 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
101105

102106
override fun showMessage(messageParams: MessageParams) {
103107
val type = when (messageParams.type) {
104-
MessageType.Error -> Level.ERROR
105-
MessageType.Warning -> Level.WARN
106-
MessageType.Info, MessageType.Log -> Level.INFO
108+
MessageType.Error -> NotificationType.ERROR
109+
MessageType.Warning -> NotificationType.WARNING
110+
MessageType.Info, MessageType.Log -> NotificationType.INFORMATION
107111
}
108112

109-
if (type == Level.ERROR &&
110-
messageParams.message.lineSequence().firstOrNull()?.contains("NOTE: The AWS SDK for JavaScript (v2) is in maintenance mode.") == true
111-
) {
112-
LOG.info { "Suppressed Flare AWS JS SDK v2 EoL error message" }
113-
return
114-
}
115-
116-
LOG.atLevel(type).log(messageParams.message)
113+
notify(type, message("q.window.title"), getCleanedContent(messageParams.message, true), project, emptyList())
117114
}
118115

119116
override fun showMessageRequest(requestParams: ShowMessageRequestParams): CompletableFuture<MessageActionItem?>? {
@@ -123,15 +120,33 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
123120
}
124121

125122
override fun logMessage(message: MessageParams) {
126-
showMessage(message)
123+
val type = when (message.type) {
124+
MessageType.Error -> Level.ERROR
125+
MessageType.Warning -> Level.WARN
126+
MessageType.Info, MessageType.Log -> Level.INFO
127+
}
128+
129+
if (type == Level.ERROR &&
130+
message.message.lineSequence().firstOrNull()?.contains("NOTE: The AWS SDK for JavaScript (v2) is in maintenance mode.") == true
131+
) {
132+
LOG.info { "Suppressed Flare AWS JS SDK v2 EoL error message" }
133+
return
134+
}
135+
136+
LOG.atLevel(type).log(message.message)
127137
}
128138

129-
override fun showDocument(params: ShowDocumentParams?): CompletableFuture<ShowDocumentResult> {
139+
override fun showDocument(params: ShowDocumentParams): CompletableFuture<ShowDocumentResult> {
130140
try {
131-
if (params == null || params.uri.isNullOrEmpty()) {
141+
if (params.uri.isNullOrEmpty()) {
132142
return CompletableFuture.completedFuture(ShowDocumentResult(false))
133143
}
134144

145+
if (params.external == true) {
146+
BrowserUtil.open(params.uri)
147+
return CompletableFuture.completedFuture(ShowDocumentResult(true))
148+
}
149+
135150
ApplicationManager.getApplication().invokeLater {
136151
try {
137152
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(params.uri)

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/NotificationUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fun Throwable.notifyError(title: String = "", project: Project? = null, stripHtm
4242
)
4343
}
4444

45-
private fun notify(type: NotificationType, title: String, content: String = "", project: Project? = null, notificationActions: Collection<AnAction>) {
45+
fun notify(type: NotificationType, title: String, content: String = "", project: Project? = null, notificationActions: Collection<AnAction>) {
4646
val notification = Notification(GROUP_DISPLAY_ID, title, content, type)
4747
notificationActions.forEach {
4848
notification.addAction(if (it !is NotificationAction) createNotificationExpiringAction(it) else it)
@@ -182,4 +182,4 @@ fun createShowMoreInfoDialogAction(actionName: String?, title: String?, message:
182182
}
183183
}
184184

185-
private fun getCleanedContent(content: String, stripHtml: Boolean): String = if (stripHtml) StringUtil.stripHtml(content, true) else content
185+
fun getCleanedContent(content: String, stripHtml: Boolean): String = if (stripHtml) StringUtil.stripHtml(content, true) else content

0 commit comments

Comments
 (0)