|
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 |
16 | 22 | import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection |
17 | 23 | import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager |
18 | 24 | import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection |
@@ -56,6 +62,30 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC |
56 | 62 | showMessage(message) |
57 | 63 | } |
58 | 64 |
|
| 65 | + override fun showDocument(params: ShowDocumentParams?): CompletableFuture<ShowDocumentResult> { |
| 66 | + try { |
| 67 | + if (params == null || params.uri.isNullOrEmpty()) { |
| 68 | + return CompletableFuture.completedFuture(ShowDocumentResult(false)) |
| 69 | + } |
| 70 | + |
| 71 | + ApplicationManager.getApplication().invokeLater { |
| 72 | + try { |
| 73 | + val virtualFile = VirtualFileManager.getInstance().findFileByUrl(params.uri) |
| 74 | + ?: throw IllegalArgumentException("Cannot find file: ${params.uri}") |
| 75 | + |
| 76 | + FileEditorManager.getInstance(project).openFile(virtualFile, true) |
| 77 | + } catch (e: Exception) { |
| 78 | + LOG.warn("Failed to show document: ${params.uri}") |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + return CompletableFuture.completedFuture(ShowDocumentResult(true)) |
| 83 | + } catch (e: Exception) { |
| 84 | + LOG.warn("Error showing document") |
| 85 | + return CompletableFuture.completedFuture(ShowDocumentResult(false)) |
| 86 | + } |
| 87 | + } |
| 88 | + |
59 | 89 | override fun getConnectionMetadata(): CompletableFuture<ConnectionMetadata> = |
60 | 90 | CompletableFuture.supplyAsync { |
61 | 91 | val connection = ToolkitConnectionManager.getInstance(project) |
@@ -145,4 +175,8 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC |
145 | 175 | error("Cannot handle partial chat") |
146 | 176 | } |
147 | 177 | } |
| 178 | + |
| 179 | + companion object { |
| 180 | + private val LOG = getLogger<AmazonQLanguageClientImpl>() |
| 181 | + } |
148 | 182 | } |
0 commit comments