Skip to content

Commit 1007aff

Browse files
authored
fix(amazonq): Fix prompt file not opening in windows (#5750)
* Fix prompt file not opening in windows * Detekt * feedback * comment added
1 parent e260f78 commit 1007aff

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import software.aws.toolkits.jetbrains.utils.getCleanedContent
5959
import software.aws.toolkits.jetbrains.utils.notify
6060
import software.aws.toolkits.resources.message
6161
import java.io.File
62+
import java.net.URLDecoder
63+
import java.nio.charset.StandardCharsets
6264
import java.nio.file.Files
6365
import java.nio.file.Paths
6466
import java.util.UUID
@@ -147,19 +149,22 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
147149
return CompletableFuture.completedFuture(ShowDocumentResult(false))
148150
}
149151

152+
// The filepath sent by the server contains unicode characters which need to be
153+
// decoded for JB file handling APIs to be handle to handle file operations
154+
val fileToOpen = URLDecoder.decode(params.uri, StandardCharsets.UTF_8.name())
150155
if (params.external == true) {
151-
BrowserUtil.open(params.uri)
156+
BrowserUtil.open(fileToOpen)
152157
return CompletableFuture.completedFuture(ShowDocumentResult(true))
153158
}
154159

155160
ApplicationManager.getApplication().invokeLater {
156161
try {
157-
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(params.uri)
158-
?: throw IllegalArgumentException("Cannot find file: ${params.uri}")
162+
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(fileToOpen)
163+
?: throw IllegalArgumentException("Cannot find file: $fileToOpen")
159164

160165
FileEditorManager.getInstance(project).openFile(virtualFile, true)
161166
} catch (e: Exception) {
162-
LOG.warn { "Failed to show document: ${params.uri}" }
167+
LOG.warn { "Failed to show document: $fileToOpen" }
163168
}
164169
}
165170

0 commit comments

Comments
 (0)