|  | 
| 4 | 4 | package software.aws.toolkits.jetbrains.services.amazonq.lsp | 
| 5 | 5 | 
 | 
| 6 | 6 | import com.intellij.notification.NotificationType | 
|  | 7 | +import com.intellij.openapi.application.ApplicationManager | 
|  | 8 | +import com.intellij.openapi.fileEditor.FileEditorManager | 
| 7 | 9 | import com.intellij.openapi.project.Project | 
|  | 10 | +import com.intellij.openapi.vfs.VirtualFileManager | 
| 8 | 11 | import migration.software.aws.toolkits.jetbrains.settings.AwsSettings | 
| 9 | 12 | import org.eclipse.lsp4j.ConfigurationParams | 
| 10 | 13 | import org.eclipse.lsp4j.MessageActionItem | 
| 11 | 14 | import org.eclipse.lsp4j.MessageParams | 
| 12 | 15 | import org.eclipse.lsp4j.MessageType | 
| 13 | 16 | import org.eclipse.lsp4j.ProgressParams | 
| 14 | 17 | import org.eclipse.lsp4j.PublishDiagnosticsParams | 
|  | 18 | +import org.eclipse.lsp4j.ShowDocumentParams | 
|  | 19 | +import org.eclipse.lsp4j.ShowDocumentResult | 
| 15 | 20 | import org.eclipse.lsp4j.ShowMessageRequestParams | 
|  | 21 | +import software.aws.toolkits.core.utils.getLogger | 
|  | 22 | +import software.aws.toolkits.core.utils.warn | 
| 16 | 23 | import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection | 
| 17 | 24 | import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager | 
| 18 | 25 | import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection | 
| @@ -56,6 +63,30 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC | 
| 56 | 63 |         showMessage(message) | 
| 57 | 64 |     } | 
| 58 | 65 | 
 | 
|  | 66 | +    override fun showDocument(params: ShowDocumentParams?): CompletableFuture<ShowDocumentResult> { | 
|  | 67 | +        try { | 
|  | 68 | +            if (params == null || params.uri.isNullOrEmpty()) { | 
|  | 69 | +                return CompletableFuture.completedFuture(ShowDocumentResult(false)) | 
|  | 70 | +            } | 
|  | 71 | + | 
|  | 72 | +            ApplicationManager.getApplication().invokeLater { | 
|  | 73 | +                try { | 
|  | 74 | +                    val virtualFile = VirtualFileManager.getInstance().findFileByUrl(params.uri) | 
|  | 75 | +                        ?: throw IllegalArgumentException("Cannot find file: ${params.uri}") | 
|  | 76 | + | 
|  | 77 | +                    FileEditorManager.getInstance(project).openFile(virtualFile, true) | 
|  | 78 | +                } catch (e: Exception) { | 
|  | 79 | +                    LOG.warn { "Failed to show document: ${params.uri}" } | 
|  | 80 | +                } | 
|  | 81 | +            } | 
|  | 82 | + | 
|  | 83 | +            return CompletableFuture.completedFuture(ShowDocumentResult(true)) | 
|  | 84 | +        } catch (e: Exception) { | 
|  | 85 | +            LOG.warn { "Error showing document" } | 
|  | 86 | +            return CompletableFuture.completedFuture(ShowDocumentResult(false)) | 
|  | 87 | +        } | 
|  | 88 | +    } | 
|  | 89 | + | 
| 59 | 90 |     override fun getConnectionMetadata(): CompletableFuture<ConnectionMetadata> = | 
| 60 | 91 |         CompletableFuture.supplyAsync { | 
| 61 | 92 |             val connection = ToolkitConnectionManager.getInstance(project) | 
| @@ -132,4 +163,8 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC | 
| 132 | 163 |             error("Cannot handle partial chat") | 
| 133 | 164 |         } | 
| 134 | 165 |     } | 
|  | 166 | + | 
|  | 167 | +    companion object { | 
|  | 168 | +        private val LOG = getLogger<AmazonQLanguageClientImpl>() | 
|  | 169 | +    } | 
| 135 | 170 | } | 
0 commit comments