Skip to content

fix(amazonq): Fix prompt file not opening in windows #5750

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

Merged
merged 5 commits into from
May 22, 2025
Merged
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
Expand Up @@ -59,6 +59,8 @@
import software.aws.toolkits.jetbrains.utils.notify
import software.aws.toolkits.resources.message
import java.io.File
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import java.util.UUID
Expand Down Expand Up @@ -147,19 +149,22 @@
return CompletableFuture.completedFuture(ShowDocumentResult(false))
}

// The filepath sent by the server contains unicode characters which need to be
// decoded for JB file handling APIs to be handle to handle file operations
val fileToOpen = URLDecoder.decode(params.uri, StandardCharsets.UTF_8.name())

Check warning on line 154 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L154 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

please include inline comment why

if (params.external == true) {
BrowserUtil.open(params.uri)
BrowserUtil.open(fileToOpen)

Check warning on line 156 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L156 was not covered by tests
return CompletableFuture.completedFuture(ShowDocumentResult(true))
}

ApplicationManager.getApplication().invokeLater {
try {
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(params.uri)
?: throw IllegalArgumentException("Cannot find file: ${params.uri}")
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(fileToOpen)
?: throw IllegalArgumentException("Cannot find file: $fileToOpen")

Check warning on line 163 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L163 was not covered by tests

FileEditorManager.getInstance(project).openFile(virtualFile, true)
} catch (e: Exception) {
LOG.warn { "Failed to show document: ${params.uri}" }
LOG.warn { "Failed to show document: $fileToOpen" }

Check warning on line 167 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L167 was not covered by tests
}
}

Expand Down
Loading