Skip to content

Commit 47706df

Browse files
committed
Add support for Amazon Q chat on remote 242+
1 parent b4433e7 commit 47706df

File tree

9 files changed

+88
-31
lines changed

9 files changed

+88
-31
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ toolkitVersion=3.24-SNAPSHOT
88
publishToken=
99
publishChannel=
1010

11-
ideProfileName=2024.1
11+
ideProfileName=2024.2
1212

1313
remoteRobotPort=8080
1414

plugins/amazonq/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
5+
import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware
56
import software.aws.toolkits.gradle.changelog.tasks.GeneratePluginChangeLog
67
import software.aws.toolkits.gradle.intellij.IdeFlavor
78
import software.aws.toolkits.gradle.intellij.IdeVersions
@@ -49,3 +50,16 @@ tasks.check {
4950
}
5051
}
5152
}
53+
54+
val runSplitIde by intellijPlatformTesting.runIde.registering {
55+
splitMode = true
56+
splitModeTarget = SplitModeAware.SplitModeTarget.BACKEND
57+
58+
plugins {
59+
localPlugin(provider { project(":plugin-core").tasks.buildPlugin.get().outputs.files.singleFile })
60+
}
61+
62+
prepareSandboxTask {
63+
dependsOn(provider { project(":plugin-core").tasks.buildPlugin })
64+
}
65+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQToolWindowFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class AmazonQToolWindowFactory : ToolWindowFactory, DumbAware {
124124
)
125125
}
126126

127-
override fun shouldBeAvailable(project: Project): Boolean = !isRunningOnRemoteBackend() && isQSupportedInThisVersion()
127+
override fun shouldBeAvailable(project: Project): Boolean = true
128128

129129
private fun onConnectionChanged(project: Project, newConnection: ToolkitConnection?, toolWindow: ToolWindow) {
130130
val contentManager = toolWindow.contentManager

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/util/JcefBrowserUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package software.aws.toolkits.jetbrains.services.amazonq.util
66
import com.intellij.openapi.Disposable
77
import com.intellij.openapi.util.Disposer
88
import com.intellij.ui.jcef.JBCefApp
9-
import com.intellij.ui.jcef.JBCefBrowserBase
9+
import com.intellij.ui.jcef.JBCefBrowser
1010
import com.intellij.ui.jcef.JBCefBrowserBuilder
1111
import com.intellij.ui.jcef.JBCefClient
1212

13-
fun createBrowser(parent: Disposable): JBCefBrowserBase {
13+
fun createBrowser(parent: Disposable): JBCefBrowser {
1414
val client = JBCefApp.getInstance().createClient().apply {
1515
setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 5)
1616
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ package software.aws.toolkits.jetbrains.services.amazonq.webview
66
import com.intellij.openapi.Disposable
77
import com.intellij.openapi.util.Disposer
88
import com.intellij.ui.jcef.JBCefJSQuery
9-
import org.cef.CefApp
9+
import com.intellij.ui.jcef.executeJavaScript
10+
import kotlinx.coroutines.delay
11+
import kotlinx.coroutines.launch
12+
import software.aws.toolkits.jetbrains.core.coroutines.disposableCoroutineScope
1013
import software.aws.toolkits.jetbrains.services.amazonq.util.createBrowser
1114
import java.util.function.Function
1215

@@ -23,13 +26,13 @@ class Browser(parent: Disposable) : Disposable {
2326

2427
fun init(isCodeTransformAvailable: Boolean, isFeatureDevAvailable: Boolean) {
2528
// register the scheme handler to route http://mynah/ URIs to the resources/assets directory on classpath
26-
CefApp.getInstance()
27-
.registerSchemeHandlerFactory(
28-
"http",
29-
"mynah",
30-
AssetResourceHandler.AssetResourceHandlerFactory(),
31-
)
32-
29+
// CefApp.getInstance()
30+
// .registerSchemeHandlerFactory(
31+
// "http",
32+
// "mynah",
33+
// AssetResourceHandler.AssetResourceHandlerFactory(),
34+
// )
35+
println("aaaaaaaaa did a load")
3336
loadWebView(isCodeTransformAvailable, isFeatureDevAvailable)
3437
}
3538

@@ -51,6 +54,21 @@ class Browser(parent: Disposable) : Disposable {
5154
jcefBrowser.setProperty("state", "")
5255
// load the web app
5356
jcefBrowser.loadHTML(getWebviewHTML(isCodeTransformAvailable, isFeatureDevAvailable))
57+
disposableCoroutineScope(this).launch {
58+
while (true) {
59+
delay(5000)
60+
try {
61+
println("yy" + jcefBrowser.executeJavaScript("ideApi.postMessage('aaaaaaaaaaaaaaaaaaa')", 0))
62+
println(
63+
"yy" + jcefBrowser.executeJavaScript(
64+
"var state = false; setInterval(function() {document.body.innerHTML = !!state; state = !state;}, 1000)",
65+
0
66+
)
67+
)
68+
break
69+
} catch (_: Exception) {}
70+
}
71+
}
5472
}
5573

5674
/**
@@ -85,12 +103,13 @@ class Browser(parent: Disposable) : Disposable {
85103
$jsScripts
86104
</head>
87105
<body>
106+
loading
88107
</body>
89108
</html>
90109
""".trimIndent()
91110
}
92111

93112
companion object {
94-
private const val WEB_SCRIPT_URI = "http://mynah/js/mynah-ui.js"
113+
private const val WEB_SCRIPT_URI = "http://127.0.0.1:8000/js/mynah-ui.js"
95114
}
96115
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import kotlinx.coroutines.flow.merge
1515
import kotlinx.coroutines.flow.onEach
1616
import kotlinx.coroutines.launch
1717
import org.cef.browser.CefBrowser
18+
import software.aws.toolkits.core.utils.error
19+
import software.aws.toolkits.core.utils.getLogger
1820
import software.aws.toolkits.jetbrains.services.amazonq.apps.AppConnection
1921
import software.aws.toolkits.jetbrains.services.amazonq.commands.MessageSerializer
2022
import software.aws.toolkits.jetbrains.services.amazonq.util.command
@@ -36,16 +38,20 @@ class BrowserConnector(
3638
// Send browser messages to the outbound publisher
3739
addMessageHook(browser)
3840
.onEach { json ->
39-
val node = serializer.toNode(json)
40-
if (node.command == "ui-is-ready") {
41-
uiReady.complete(true)
42-
}
43-
val tabType = node.tabType ?: return@onEach
44-
connections.filter { connection -> connection.app.tabTypes.contains(tabType) }.forEach { connection ->
45-
launch {
46-
val message = serializer.deserialize(node, connection.messageTypeRegistry)
47-
connection.messagesFromUiToApp.publish(message)
41+
try {
42+
val node = serializer.toNode(json)
43+
if (node.command == "ui-is-ready") {
44+
uiReady.complete(true)
45+
}
46+
val tabType = node.tabType ?: return@onEach
47+
connections.filter { connection -> connection.app.tabTypes.contains(tabType) }.forEach { connection ->
48+
launch {
49+
val message = serializer.deserialize(node, connection.messageTypeRegistry)
50+
connection.messagesFromUiToApp.publish(message)
51+
}
4852
}
53+
} catch (e: Exception) {
54+
getLogger<BrowserConnector>().error(e) { "message hook err" }
4955
}
5056
}
5157
.launchIn(this)
@@ -76,6 +82,7 @@ class BrowserConnector(
7682

7783
private fun addMessageHook(browser: Browser) = callbackFlow {
7884
val handler = Function<String, Response> {
85+
println(it)
7986
trySend(it)
8087
null
8188
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
package software.aws.toolkits.jetbrains.services.cwc.editor.context.file
55

6+
import com.intellij.idea.AppMode
67
import com.intellij.openapi.application.runReadAction
8+
import com.intellij.openapi.client.ClientKind
9+
import com.intellij.openapi.client.sessions
10+
import com.intellij.openapi.components.service
711
import com.intellij.openapi.editor.Document
12+
import com.intellij.openapi.fileEditor.ClientFileEditorManager
813
import com.intellij.openapi.fileEditor.FileEditorManager
914
import com.intellij.openapi.project.Project
1015
import com.intellij.psi.PsiDocumentManager
@@ -17,9 +22,13 @@ import software.aws.toolkits.jetbrains.utils.computeOnEdt
1722
class FileContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter, private val project: Project) {
1823
private val languageExtractor: LanguageExtractor = LanguageExtractor()
1924
suspend fun extract(): FileContext? {
20-
val editor = computeOnEdt {
21-
FileEditorManager.getInstance(project).selectedTextEditor
22-
} ?: return null
25+
val editor = if (AppMode.isRemoteDevHost()) {
26+
project.sessions(ClientKind.REMOTE).firstOrNull()?.service<ClientFileEditorManager>()?.getSelectedTextEditor() ?: return null
27+
} else {
28+
computeOnEdt {
29+
FileEditorManager.getInstance(project).selectedTextEditor
30+
} ?: return null
31+
}
2332

2433
val fileLanguage = computeOnEdt {
2534
languageExtractor.extractLanguageNameFromCurrentFile(editor, project)

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33

44
package software.aws.toolkits.jetbrains.services.cwc.editor.context.focusArea
55

6+
import com.intellij.idea.AppMode
7+
import com.intellij.openapi.client.ClientKind
8+
import com.intellij.openapi.client.sessions
9+
import com.intellij.openapi.components.service
610
import com.intellij.openapi.editor.Editor
711
import com.intellij.openapi.editor.LogicalPosition
812
import com.intellij.openapi.editor.SelectionModel
13+
import com.intellij.openapi.fileEditor.ClientFileEditorManager
914
import com.intellij.openapi.fileEditor.FileEditorManager
1015
import com.intellij.openapi.project.Project
1116
import com.intellij.openapi.util.TextRange
@@ -24,10 +29,13 @@ class FocusAreaContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter
2429

2530
private val languageExtractor: LanguageExtractor = LanguageExtractor()
2631
suspend fun extract(): FocusAreaContext? {
27-
val editor = computeOnEdt {
28-
FileEditorManager.getInstance(project).selectedTextEditor
29-
} ?: return null
30-
32+
val editor = if (AppMode.isRemoteDevHost()) {
33+
project.sessions(ClientKind.REMOTE).firstOrNull()?.service<ClientFileEditorManager>()?.getSelectedTextEditor() ?: return null
34+
} else {
35+
computeOnEdt {
36+
FileEditorManager.getInstance(project).selectedTextEditor
37+
} ?: return null
38+
}
3139
if (editor.document.text.isBlank()) return null
3240

3341
// Get 10k characters around the cursor
@@ -108,7 +116,7 @@ class FocusAreaContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter
108116
languageExtractor.extractLanguageNameFromCurrentFile(editor, project)
109117
}
110118
val fileText = editor.document.text
111-
val fileName = FileEditorManager.getInstance(project).selectedFiles.first().name
119+
val fileName = editor.virtualFile.name
112120

113121
// Offset the selection range to the start of the trimmedFileText
114122
val selectionInsideTrimmedFileTextRange = codeSelectionRange.let {

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/RemoteEnvUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.intellij.openapi.util.BuildNumber
1111
/**
1212
* @return true if running in any type of remote environment
1313
*/
14-
fun isRunningOnRemoteBackend() = AppMode.isRemoteDevHost()
14+
fun isRunningOnRemoteBackend() = false
1515

1616
/**
1717
* @return true if running in a codecatalyst remote environment

0 commit comments

Comments
 (0)