diff --git a/gradle.properties b/gradle.properties index fc15026f89..f3b33d3c68 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ toolkitVersion=3.28-SNAPSHOT publishToken= publishChannel= -ideProfileName=2024.1 +ideProfileName=2024.2 remoteRobotPort=8080 diff --git a/plugins/amazonq/build.gradle.kts b/plugins/amazonq/build.gradle.kts index f3caa6e678..304cac3a53 100644 --- a/plugins/amazonq/build.gradle.kts +++ b/plugins/amazonq/build.gradle.kts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType +import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware import software.aws.toolkits.gradle.changelog.tasks.GeneratePluginChangeLog import software.aws.toolkits.gradle.intellij.IdeFlavor import software.aws.toolkits.gradle.intellij.IdeVersions @@ -49,3 +50,16 @@ tasks.check { } } } + +val runSplitIde by intellijPlatformTesting.runIde.registering { + splitMode = true + splitModeTarget = SplitModeAware.SplitModeTarget.BACKEND + + plugins { + localPlugin(provider { project(":plugin-core").tasks.buildPlugin.get().outputs.files.singleFile }) + } + + prepareSandboxTask { + dependsOn(provider { project(":plugin-core").tasks.buildPlugin }) + } +} diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/util/JcefBrowserUtil.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/util/JcefBrowserUtil.kt index fd86513a86..7759e97e50 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/util/JcefBrowserUtil.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/util/JcefBrowserUtil.kt @@ -6,11 +6,11 @@ package software.aws.toolkits.jetbrains.services.amazonq.util import com.intellij.openapi.Disposable import com.intellij.openapi.util.Disposer import com.intellij.ui.jcef.JBCefApp -import com.intellij.ui.jcef.JBCefBrowserBase +import com.intellij.ui.jcef.JBCefBrowser import com.intellij.ui.jcef.JBCefBrowserBuilder import com.intellij.ui.jcef.JBCefClient -fun createBrowser(parent: Disposable): JBCefBrowserBase { +fun createBrowser(parent: Disposable): JBCefBrowser { val client = JBCefApp.getInstance().createClient().apply { setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 5) } diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt index 526c38a531..09f702855d 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt @@ -6,7 +6,10 @@ package software.aws.toolkits.jetbrains.services.amazonq.webview import com.intellij.openapi.Disposable import com.intellij.openapi.util.Disposer import com.intellij.ui.jcef.JBCefJSQuery -import org.cef.CefApp +import com.intellij.ui.jcef.executeJavaScript +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import software.aws.toolkits.jetbrains.core.coroutines.disposableCoroutineScope import software.aws.toolkits.jetbrains.services.amazonq.util.createBrowser import java.util.function.Function @@ -23,13 +26,13 @@ class Browser(parent: Disposable) : Disposable { fun init(isCodeTransformAvailable: Boolean, isFeatureDevAvailable: Boolean) { // register the scheme handler to route http://mynah/ URIs to the resources/assets directory on classpath - CefApp.getInstance() - .registerSchemeHandlerFactory( - "http", - "mynah", - AssetResourceHandler.AssetResourceHandlerFactory(), - ) - +// CefApp.getInstance() +// .registerSchemeHandlerFactory( +// "http", +// "mynah", +// AssetResourceHandler.AssetResourceHandlerFactory(), +// ) + println("aaaaaaaaa did a load") loadWebView(isCodeTransformAvailable, isFeatureDevAvailable) } @@ -51,6 +54,21 @@ class Browser(parent: Disposable) : Disposable { jcefBrowser.setProperty("state", "") // load the web app jcefBrowser.loadHTML(getWebviewHTML(isCodeTransformAvailable, isFeatureDevAvailable)) + disposableCoroutineScope(this).launch { + while (true) { + delay(5000) + try { + println("yy" + jcefBrowser.executeJavaScript("ideApi.postMessage('aaaaaaaaaaaaaaaaaaa')", 0)) + println( + "yy" + jcefBrowser.executeJavaScript( + "var state = false; setInterval(function() {document.body.innerHTML = !!state; state = !state;}, 1000)", + 0 + ) + ) + break + } catch (_: Exception) {} + } + } } /** @@ -85,12 +103,13 @@ class Browser(parent: Disposable) : Disposable { $jsScripts + loading """.trimIndent() } companion object { - private const val WEB_SCRIPT_URI = "http://mynah/js/mynah-ui.js" + private const val WEB_SCRIPT_URI = "http://127.0.0.1:8000/js/mynah-ui.js" } } diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt index 3a73dab617..3a0ec1ccea 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt @@ -15,6 +15,8 @@ import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.cef.browser.CefBrowser +import software.aws.toolkits.core.utils.error +import software.aws.toolkits.core.utils.getLogger import software.aws.toolkits.jetbrains.services.amazonq.apps.AppConnection import software.aws.toolkits.jetbrains.services.amazonq.commands.MessageSerializer import software.aws.toolkits.jetbrains.services.amazonq.util.command @@ -36,16 +38,20 @@ class BrowserConnector( // Send browser messages to the outbound publisher addMessageHook(browser) .onEach { json -> - val node = serializer.toNode(json) - if (node.command == "ui-is-ready") { - uiReady.complete(true) - } - val tabType = node.tabType ?: return@onEach - connections.filter { connection -> connection.app.tabTypes.contains(tabType) }.forEach { connection -> - launch { - val message = serializer.deserialize(node, connection.messageTypeRegistry) - connection.messagesFromUiToApp.publish(message) + try { + val node = serializer.toNode(json) + if (node.command == "ui-is-ready") { + uiReady.complete(true) + } + val tabType = node.tabType ?: return@onEach + connections.filter { connection -> connection.app.tabTypes.contains(tabType) }.forEach { connection -> + launch { + val message = serializer.deserialize(node, connection.messageTypeRegistry) + connection.messagesFromUiToApp.publish(message) + } } + } catch (e: Exception) { + getLogger().error(e) { "message hook err" } } } .launchIn(this) @@ -76,6 +82,7 @@ class BrowserConnector( private fun addMessageHook(browser: Browser) = callbackFlow { val handler = Function { + println(it) trySend(it) null } diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt index 1998c3fe32..7350825e7e 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt @@ -3,8 +3,13 @@ package software.aws.toolkits.jetbrains.services.cwc.editor.context.file +import com.intellij.idea.AppMode import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.client.ClientKind +import com.intellij.openapi.client.sessions +import com.intellij.openapi.components.service import com.intellij.openapi.editor.Document +import com.intellij.openapi.fileEditor.ClientFileEditorManager import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project import com.intellij.psi.PsiDocumentManager @@ -17,9 +22,13 @@ import software.aws.toolkits.jetbrains.utils.computeOnEdt class FileContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter, private val project: Project) { private val languageExtractor: LanguageExtractor = LanguageExtractor() suspend fun extract(): FileContext? { - val editor = computeOnEdt { - FileEditorManager.getInstance(project).selectedTextEditor - } ?: return null + val editor = if (AppMode.isRemoteDevHost()) { + project.sessions(ClientKind.REMOTE).firstOrNull()?.service()?.getSelectedTextEditor() ?: return null + } else { + computeOnEdt { + FileEditorManager.getInstance(project).selectedTextEditor + } ?: return null + } val fileLanguage = computeOnEdt { languageExtractor.extractLanguageNameFromCurrentFile(editor, project) diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt index ceadc7c41d..b172ac0a2f 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt @@ -3,9 +3,14 @@ package software.aws.toolkits.jetbrains.services.cwc.editor.context.focusArea +import com.intellij.idea.AppMode +import com.intellij.openapi.client.ClientKind +import com.intellij.openapi.client.sessions +import com.intellij.openapi.components.service import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.LogicalPosition import com.intellij.openapi.editor.SelectionModel +import com.intellij.openapi.fileEditor.ClientFileEditorManager import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.TextRange @@ -24,10 +29,13 @@ class FocusAreaContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter private val languageExtractor: LanguageExtractor = LanguageExtractor() suspend fun extract(): FocusAreaContext? { - val editor = computeOnEdt { - FileEditorManager.getInstance(project).selectedTextEditor - } ?: return null - + val editor = if (AppMode.isRemoteDevHost()) { + project.sessions(ClientKind.REMOTE).firstOrNull()?.service()?.getSelectedTextEditor() ?: return null + } else { + computeOnEdt { + FileEditorManager.getInstance(project).selectedTextEditor + } ?: return null + } if (editor.document.text.isBlank()) return null // Get 10k characters around the cursor @@ -108,7 +116,7 @@ class FocusAreaContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter languageExtractor.extractLanguageNameFromCurrentFile(editor, project) } val fileText = editor.document.text - val fileName = FileEditorManager.getInstance(project).selectedFiles.first().name + val fileName = editor.virtualFile.name // Offset the selection range to the start of the trimmedFileText val selectionInsideTrimmedFileTextRange = codeSelectionRange.let { diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/RemoteEnvUtils.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/RemoteEnvUtils.kt index b868718c21..6892d402cb 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/RemoteEnvUtils.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/RemoteEnvUtils.kt @@ -9,7 +9,7 @@ import com.intellij.ui.jcef.JBCefApp /** * @return true if running in any type of remote environment */ -fun isRunningOnRemoteBackend() = AppMode.isRemoteDevHost() +fun isRunningOnRemoteBackend() = false /** * @return true if running in a codecatalyst remote environment