Skip to content
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

fix(amazonq): Bug Fix for "Q: Send to Prompt" doesn't work in split panes on local or remote #5463

Merged
merged 6 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Fix Q: Send to Prompt option to work in split panes on local and remote."
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.intellij.ide.BrowserUtil
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
Expand Down Expand Up @@ -95,6 +97,7 @@
import software.aws.toolkits.jetbrains.services.cwc.messages.ChatMessageType
import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
import software.aws.toolkits.jetbrains.ui.feedback.TestGenFeedbackDialog
import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend
import software.aws.toolkits.jetbrains.utils.notifyError
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AmazonqTelemetry
Expand Down Expand Up @@ -1246,9 +1249,22 @@
message: IncomingCodeTestMessage.StartTestGen,
): ActiveFileInfo? {
try {
val fileEditorManager = FileEditorManager.getInstance(project)
val activeEditor = fileEditorManager.selectedEditor
val activeFile = fileEditorManager.selectedFiles.firstOrNull()
val (activeEditor, activeFile) = when {

Check warning on line 1252 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt#L1252

Added line #L1252 was not covered by tests
isRunningOnRemoteBackend() -> {
val editors = EditorFactory.getInstance().allEditors
val editor = editors.firstOrNull()

Check warning on line 1255 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt#L1254-L1255

Added lines #L1254 - L1255 were not covered by tests
val file = editor?.document?.let { document ->
FileDocumentManager.getInstance().getFile(document)

Check warning on line 1257 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt#L1257

Added line #L1257 was not covered by tests
}
Pair(editor, file)

Check warning on line 1259 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt#L1259

Added line #L1259 was not covered by tests
}
else -> {
val fileEditorManager = FileEditorManager.getInstance(project)
val editor = fileEditorManager.selectedEditor
val file = fileEditorManager.selectedFiles.firstOrNull()
Pair(editor, file)

Check warning on line 1265 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt#L1262-L1265

Added lines #L1262 - L1265 were not covered by tests
}
}
val projectRoot = project.basePath?.let { Path.of(it) }?.toFile()?.toVirtualFile() ?: run {
project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
import software.aws.toolkits.jetbrains.services.cwc.editor.context.file.util.LanguageExtractor
import software.aws.toolkits.jetbrains.services.cwc.editor.context.file.util.MatchPolicyExtractor
import software.aws.toolkits.jetbrains.utils.computeOnEdt
import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend

class FileContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter?, private val project: Project) {
private val languageExtractor: LanguageExtractor = LanguageExtractor()
suspend fun extract(): FileContext? {
val editorManager = FileEditorManager.getInstance(project)

Check warning on line 21 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L21 was not covered by tests

val editor = computeOnEdt {
FileEditorManager.getInstance(project).selectedTextEditorWithRemotes.firstOrNull()
when {

Check warning on line 24 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L24 was not covered by tests
isRunningOnRemoteBackend() -> editorManager.selectedTextEditorWithRemotes.firstOrNull()
else -> editorManager.selectedTextEditor
}

Check warning on line 27 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/file/FileContextExtractor.kt

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L26 - L27 were not covered by tests
} ?: return null

val fileLanguage = computeOnEdt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
import software.aws.toolkits.jetbrains.services.cwc.controller.ChatController
import software.aws.toolkits.jetbrains.services.cwc.editor.context.file.util.LanguageExtractor
import software.aws.toolkits.jetbrains.utils.computeOnEdt
import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend
import java.awt.Point
import kotlin.math.min

class FocusAreaContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter?, private val project: Project) {

private val languageExtractor: LanguageExtractor = LanguageExtractor()
suspend fun extract(): FocusAreaContext? {
val editorManager = FileEditorManager.getInstance(project)

Check warning on line 29 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L29 was not covered by tests
val editor = computeOnEdt {
FileEditorManager.getInstance(project).selectedTextEditorWithRemotes.firstOrNull()
when {

Check warning on line 31 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L31 was not covered by tests
isRunningOnRemoteBackend() -> editorManager.selectedTextEditorWithRemotes.firstOrNull()
else -> editorManager.selectedTextEditor
}

Check warning on line 34 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/editor/context/focusArea/FocusAreaContextExtractor.kt

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L33 - L34 were not covered by tests
} ?: return null

if (editor.document.text.isBlank()) return null
Expand Down
Loading