-
Notifications
You must be signed in to change notification settings - Fork 251
Add support for Amazon Q chat on remote 242+ #4825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Conflicts: plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQToolWindowFactory.kt plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt
…rains into rli/remote-chat-wip
Qodana Community for JVM12 new problems were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QDJVMC found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
...src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt
Fixed
Show fixed
Hide fixed
...src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt
Fixed
Show fixed
Hide fixed
...src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt
Fixed
Show fixed
Hide fixed
...src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt
Fixed
Show fixed
Hide fixed
...src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt
Fixed
Show fixed
Hide fixed
) : CefRequestHandlerAdapter() { | ||
private val myResources: MutableMap<String, () -> CefResourceHandler?> = HashMap() | ||
|
||
private val REJECTING_RESOURCE_HANDLER: CefResourceHandler = object : CefResourceHandlerAdapter() { |
Check notice
Code scanning / QDJVMC
Private property naming convention Note
} | ||
} | ||
|
||
private val RESOURCE_REQUEST_HANDLER = resourceHandlerWrapper { path -> |
Check notice
Code scanning / QDJVMC
Private property naming convention Note
private val headers: Map<String, String> = mapOf(), | ||
) : CefResourceHandler, Disposable { | ||
init { | ||
Disposer.register(parent, this) |
Check notice
Code scanning / QDJVMC
Leaking 'this' in constructor Note
private fun streamHandler(path: String, stream: InputStream) = | ||
JBCefStreamResourceHandler( | ||
stream, | ||
if (path.endsWith(".wasm") == true) "application/wasm" else URLConnection.getFileNameMap().getContentTypeFor(path), |
Check notice
Code scanning / QDJVMC
Boolean expression can be simplified Note
} | ||
} | ||
|
||
fun addResource(path: String, stream: InputStream?) = |
Check warning
Code scanning / QDJVMC
Unused symbol Warning
@@ -122,7 +122,7 @@ | |||
|
|||
ApplicationManager.getApplication().invokeAndWait { | |||
selectionRange = ApplicationManager.getApplication().runReadAction<Range?> { | |||
val editor = FileEditorManager.getInstance(project).selectedTextEditor | |||
val editor = FileEditorManager.getInstance(project).selectedTextEditorWithRemotes.firstOrNull() |
Check warning
Code scanning / QDJVMC
Unstable API Usage Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this api also work in local ?
@@ -194,7 +194,7 @@ | |||
|
|||
withContext(EDT) { | |||
broadcastQEvent(QFeatureEvent.STARTS_EDITING) | |||
val editor: Editor = FileEditorManager.getInstance(context.project).selectedTextEditor ?: return@withContext | |||
val editor: Editor = FileEditorManager.getInstance(context.project).selectedTextEditorWithRemotes.firstOrNull() ?: return@withContext |
Check warning
Code scanning / QDJVMC
Unstable API Usage Warning
@@ -219,7 +219,7 @@ | |||
override suspend fun processInsertCodeAtCursorPosition(message: IncomingCwcMessage.InsertCodeAtCursorPosition) { | |||
broadcastQEvent(QFeatureEvent.STARTS_EDITING) | |||
withContext(EDT) { | |||
val editor: Editor = FileEditorManager.getInstance(context.project).selectedTextEditor ?: return@withContext | |||
val editor: Editor = FileEditorManager.getInstance(context.project).selectedTextEditorWithRemotes.firstOrNull() ?: return@withContext |
Check warning
Code scanning / QDJVMC
Unstable API Usage Warning
@@ -18,7 +18,7 @@ | |||
private val languageExtractor: LanguageExtractor = LanguageExtractor() | |||
suspend fun extract(): FileContext? { | |||
val editor = computeOnEdt { | |||
FileEditorManager.getInstance(project).selectedTextEditor | |||
FileEditorManager.getInstance(project).selectedTextEditorWithRemotes.firstOrNull() |
Check warning
Code scanning / QDJVMC
Unstable API Usage Warning
@@ -26,7 +26,7 @@ | |||
private val languageExtractor: LanguageExtractor = LanguageExtractor() | |||
suspend fun extract(): FocusAreaContext? { | |||
val editor = computeOnEdt { | |||
FileEditorManager.getInstance(project).selectedTextEditor | |||
FileEditorManager.getInstance(project).selectedTextEditorWithRemotes.firstOrNull() |
Check warning
Code scanning / QDJVMC
Unstable API Usage Warning
@@ -18,7 +18,7 @@ | |||
private var selectionListener: InlineChatSelectionListener? = null | |||
|
|||
init { | |||
val editor = project.let { FileEditorManager.getInstance(it).selectedTextEditor } | |||
val editor = project.let { FileEditorManager.getInstance(it).selectedTextEditorWithRemotes.firstOrNull() } |
Check warning
Code scanning / QDJVMC
Unstable API Usage Warning
Conflicts: plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt
Confirmed Windows Local works after the latest change (at least, log in + asking a basic chat question) |
gradle.properties
Outdated
@@ -2,7 +2,7 @@ | |||
# SPDX-License-Identifier: Apache-2.0 | |||
|
|||
# Toolkit Version | |||
toolkitVersion=3.58-SNAPSHOT | |||
toolkitVersion=3.58-SNAPSHOT-ASBX_TEST_0228 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we revert this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably revert this for now--this is for differentiating the build, and we may need to re-add it (or something equivalent) whenever we ship a new test build.
QWebviewBrowser::class.java.getResourceAsStream("/webview/assets/js/getStart.js") | ||
) | ||
|
||
jcefBrowser.loadURL(assetHandler.createResource("content.html", getWebviewHTML(webScriptUri, query))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we assign the file names to consts
val project = e.getRequiredData(CommonDataKeys.PROJECT) | ||
UiTelemetry.click(project, "q_openChat") | ||
ToolWindowManager.getInstance(project).getToolWindow(AMAZON_Q_WINDOW_ID)?.activate(null, true) | ||
if (e.getData(runScanKey) == true) { | ||
AmazonQToolWindow.openScanTab(project) | ||
} | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
e.presentation.isEnabled = e.getData(CommonDataKeys.PROJECT) != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the situation when this option is shown and project is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the action is not available if the project is null
|
||
init { | ||
assetRequestHandler.addWildcardHandler("mynah") { path -> | ||
val asset = path.replaceFirst("mynah/", "/mynah-ui/assets/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up later
@@ -334,15 +322,18 @@ class ToolkitWebviewBrowser(val project: Project, private val parentDisposable: | |||
} | |||
|
|||
override fun loadWebView(query: JBCefJSQuery) { | |||
jcefBrowser.loadHTML(getWebviewHTML(webScriptUri, query)) | |||
val webScriptUri = assetHandler.createResource( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated code, maybe could be converted to a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the classloader is important so it might become more complicated
* @param myProtocol The protocol to handle (e.g., "http", "file"). | ||
* @param myAuthority The authority of the requests (e.g., "localhost", "mydomain"). | ||
*/ | ||
open class JBCefLocalRequestHandler( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be used directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a straight copy from jetbrains so we should keep it slim to make it easy to copy over any changes later
Conflicts: plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt
Before merging to main, can we add a changelog? |
@manodnyab We're planning on turning this into a feature branch |
This enables webviews to work over thin client instances by working around
registerSchemeHandlerFactory
being a no-op as described in IJPL-170861.Open issues:This should only be enabled on remote if 242+registerSchemeHandlerFactory
not working correctly -- need further evaluationFQN WASM code doesn't seem to be invoked properlydouble check thatFileEditorManager.getInstance(project).selectedFiles.first().name
andeditor.virtualFile.name
are equivalentShould we just doFileEditorManager#selectedTextEditorWithRemotes
? that is what inline suggestions is usingconsolidate on decision. ChatController/FeatureDevControllerprocessInsertCodeAtCursorPosition
need to be migrated tooFigure out why error inFocusAreaContextExtractor
is not surfaced anywhereLicense
I confirm that my contribution is made under the terms of the Apache 2.0 license.