Skip to content

Commit 5141320

Browse files
authored
Fix creation of prompts not opening files in the editor (#5781)
There was a threading issue where since the file was opened in EDT and the result was sent back to the server on another thread, it returned the result before the file was opened. This PR makes it synchronous
1 parent 38e7369 commit 5141320

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,21 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
158158
// The filepath sent by the server contains unicode characters which need to be
159159
// decoded for JB file handling APIs to be handle to handle file operations
160160
val fileToOpen = URLDecoder.decode(params.uri, StandardCharsets.UTF_8.name())
161-
ApplicationManager.getApplication().invokeLater {
162-
try {
163-
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(fileToOpen)
164-
?: throw IllegalArgumentException("Cannot find file: $fileToOpen")
165-
166-
FileEditorManager.getInstance(project).openFile(virtualFile, true)
167-
} catch (e: Exception) {
168-
LOG.warn { "Failed to show document: $fileToOpen" }
169-
}
170-
}
161+
return CompletableFuture.supplyAsync(
162+
{
163+
try {
164+
val virtualFile = VirtualFileManager.getInstance().refreshAndFindFileByUrl(fileToOpen)
165+
?: throw IllegalArgumentException("Cannot find file: $fileToOpen")
171166

172-
return CompletableFuture.completedFuture(ShowDocumentResult(true))
167+
FileEditorManager.getInstance(project).openFile(virtualFile, true)
168+
ShowDocumentResult(true)
169+
} catch (e: Exception) {
170+
LOG.warn { "Failed to show document: $fileToOpen" }
171+
ShowDocumentResult(false)
172+
}
173+
},
174+
ApplicationManager.getApplication()::invokeLater
175+
)
173176
} catch (e: Exception) {
174177
LOG.warn { "Error showing document" }
175178
return CompletableFuture.completedFuture(ShowDocumentResult(false))

0 commit comments

Comments
 (0)