Skip to content

Commit cdfdef2

Browse files
committed
detekt and pr feedback
1 parent 897e3a4 commit cdfdef2

File tree

8 files changed

+34
-39
lines changed

8 files changed

+34
-39
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWi
2020
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory
2121
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
2222
import software.aws.toolkits.jetbrains.services.cwc.inline.InlineChatController
23-
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
2423
import java.lang.management.ManagementFactory
2524
import java.time.Duration
2625
import java.util.concurrent.atomic.AtomicBoolean

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import software.aws.toolkits.core.utils.warn
1414
import software.aws.toolkits.jetbrains.services.amazonq.webview.FqnWebviewAdapter
1515
import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.CodeNames
1616
import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.CodeNamesImpl
17+
import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.FullyQualifiedNames
1718
import software.aws.toolkits.jetbrains.services.cwc.controller.ChatController
1819
import software.aws.toolkits.jetbrains.services.cwc.editor.context.file.util.LanguageExtractor
1920
import software.aws.toolkits.jetbrains.utils.computeOnEdt
@@ -140,9 +141,8 @@ class FocusAreaContextExtractor(private val fqnWebviewAdapter: FqnWebviewAdapter
140141
val requestString = ChatController.objectMapper.writeValueAsString(extractNamesRequest)
141142

142143
codeNames = try {
143-
val namesString = fqnWebviewAdapter?.let { it.extractNames(requestString) }
144-
?: """{"simpleNames": [], "fullyQualifiedNames": {"used": []}}"""
145-
ChatController.objectMapper.readValue(namesString, CodeNamesImpl::class.java)
144+
fqnWebviewAdapter?.let { ChatController.objectMapper.readValue(it.extractNames(requestString), CodeNamesImpl::class.java)
145+
} ?: CodeNamesImpl(simpleNames = emptyList(), fullyQualifiedNames = FullyQualifiedNames(used = emptyList()))
146146
} catch (e: Exception) {
147147
getLogger<FocusAreaContextExtractor>().warn(e) { "Failed to extract names from file" }
148148
null

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatController.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import com.intellij.openapi.components.service
1717
import com.intellij.openapi.editor.Document
1818
import com.intellij.openapi.editor.Editor
1919
import com.intellij.openapi.editor.RangeMarker
20+
import com.intellij.openapi.editor.event.CaretEvent
21+
import com.intellij.openapi.editor.event.CaretListener
2022
import com.intellij.openapi.editor.markup.HighlighterLayer
2123
import com.intellij.openapi.editor.markup.HighlighterTargetArea
2224
import com.intellij.openapi.editor.markup.RangeHighlighter
@@ -81,11 +83,11 @@ class InlineChatController(
8183
private var metrics: InlineChatMetrics? = null
8284
private var canPopupAbort = AtomicBoolean(true)
8385
private var currentSelectionRange: RangeMarker? = null
86+
private val listener = InlineChatFileListener(project, this)
8487

8588
init {
86-
InlineChatFileListener(project, this).apply {
87-
project.messageBus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, this)
88-
}
89+
Disposer.register(this, listener)
90+
project.messageBus.connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener)
8991
}
9092

9193
data class InlineChatMetrics(
@@ -151,7 +153,7 @@ class InlineChatController(
151153
metrics = null
152154
}
153155

154-
private fun undoChanges () {
156+
private fun undoChanges() {
155157
scope.launch(EDT) {
156158
while (partialUndoActions.isNotEmpty()) {
157159
val action = partialUndoActions.pop()
@@ -203,10 +205,20 @@ class InlineChatController(
203205
submitHandler = popupSubmitHandler, cancelHandler = { popupCancelHandler(editor) }
204206
).createPopup(editor, scope)
205207
addPopupListeners(currentPopup!!, editor)
208+
val caretListener = createCaretListener(editor)
209+
editor.caretModel.addCaretListener(caretListener)
206210
Disposer.register(this, currentPopup!!)
207211
canPopupAbort.set(true)
208212
}
209213

214+
private fun createCaretListener(editor: Editor): CaretListener = object : CaretListener {
215+
override fun caretPositionChanged(event: CaretEvent) {
216+
disposePopup(false)
217+
218+
editor.caretModel.removeCaretListener(this)
219+
}
220+
}
221+
210222
private fun removeSelection(editor: Editor) {
211223
scope.launch(EDT) {
212224
val selectionModel = editor.selectionModel
@@ -588,8 +600,8 @@ class InlineChatController(
588600
triggerId,
589601
requestData,
590602
sessionInfo,
591-
false,
592-
true
603+
shouldAddIndexInProgressMessage = false,
604+
isInlineChat = true
593605
)
594606
.catch { e ->
595607
logger.warn { "Error in inline chat request: ${e.message}" }
@@ -618,7 +630,7 @@ class InlineChatController(
618630
try {
619631
processChatDiff(selectedCode, finalMessage, editor, selectionRange!!)
620632
} catch (e: Exception) {
621-
logger.warn {"error precessing chat diff in editor: ${e.stackTraceToString()}" }
633+
logger.warn { "error precessing chat diff in editor: ${e.stackTraceToString()}" }
622634
errorMessage = "Error processing request; please try again."
623635
}
624636
}
@@ -631,7 +643,7 @@ class InlineChatController(
631643
codeIntent = true, responseStartLatency = firstResponseLatency, responseEndLatency = lastResponseLatency
632644
)
633645
}
634-
if(errorMessage.isNotEmpty()) {
646+
if (errorMessage.isNotEmpty()) {
635647
undoChanges()
636648
}
637649
return errorMessage

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatEditorHint.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.codeInsight.hint.HintManagerImpl
77
import com.intellij.codeInsight.hint.HintUtil
88
import com.intellij.openapi.editor.Editor
99
import com.intellij.openapi.editor.VisualPosition
10+
import com.intellij.openapi.keymap.KeymapUtil
1011
import com.intellij.openapi.util.SystemInfo
1112
import com.intellij.ui.LightweightHint
1213
import com.intellij.ui.SimpleColoredText
@@ -66,13 +67,14 @@ class InlineChatEditorHint {
6667

6768
coloredText.appendToComponent(component)
6869
val shortcutComponent = HintUtil.createInformationComponent()
69-
if (!SystemInfo.isWindows) {
70+
val shortCut = KeymapUtil.getShortcutText("aws.toolkit.jetbrains.core.services.cwc.inline.openChat")
71+
if (!SystemInfo.isWindows && shortCut == "⌃I") {
7072
val shortCutIcon = AwsIcons.Resources.InlineChat.AWS_Q_INLINECHAT_SHORTCUT
7173
shortcutComponent.isIconOnTheRight = true
7274
shortcutComponent.icon = shortCutIcon
7375
} else {
7476
val shortcutText =
75-
SimpleColoredText(message("amazonqInlineChat.hint.windows.shortCut"), SimpleTextAttributes.REGULAR_ATTRIBUTES)
77+
SimpleColoredText(shortCut, SimpleTextAttributes.REGULAR_ATTRIBUTES)
7678
shortcutText.appendToComponent(shortcutComponent)
7779
}
7880

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatPopupPanel.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class InlineChatPopupPanel(private val parentDisposable: Disposable) : JPanel()
6161
font = font.deriveFont(popupButtonFontSize)
6262
}
6363

64-
6564
private val inputPanel = JPanel(BorderLayout()).apply {
6665
border = BorderFactory.createEmptyBorder(10, 10, 5, 10)
6766
}
@@ -152,7 +151,6 @@ class InlineChatPopupPanel(private val parentDisposable: Disposable) : JPanel()
152151
revalidate()
153152
}
154153

155-
156154
fun setLabel(text: String) {
157155
textLabel.text = text
158156
textField.isEnabled = false

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/OpenChatInputAction.kt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,11 @@ import com.intellij.openapi.editor.event.CaretEvent
1111
import com.intellij.openapi.editor.event.CaretListener
1212

1313
class OpenChatInputAction : AnAction() {
14-
private var inlineChatController: InlineChatController? = null
15-
private var caretListener: CaretListener? = null
1614
override fun actionPerformed(e: AnActionEvent) {
1715
val editor = e.getRequiredData(CommonDataKeys.EDITOR)
18-
val project = editor.project
16+
val project = editor.project ?: return
1917

20-
if (editor == null || project == null) return
21-
inlineChatController = InlineChatController.getInstance(project)
22-
inlineChatController?.initPopup(editor)
23-
24-
caretListener = createCaretListener(editor)
25-
editor.caretModel.addCaretListener(caretListener!!)
26-
}
27-
28-
private fun createCaretListener(editor: Editor): CaretListener = object : CaretListener {
29-
override fun caretPositionChanged(event: CaretEvent) {
30-
inlineChatController?.disposePopup(false)
31-
32-
editor.caretModel.removeCaretListener(this)
33-
caretListener = null
34-
inlineChatController = null
35-
}
18+
val inlineChatController = InlineChatController.getInstance(project)
19+
inlineChatController.initPopup(editor)
3620
}
3721
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/listeners/InlineChatFileListener.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package software.aws.toolkits.jetbrains.services.cwc.inline.listeners
55

6+
import com.intellij.openapi.Disposable
67
import com.intellij.openapi.editor.Editor
78
import com.intellij.openapi.fileEditor.FileEditorManager
89
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
@@ -12,7 +13,7 @@ import com.intellij.openapi.project.Project
1213
import com.intellij.openapi.util.Disposer
1314
import software.aws.toolkits.jetbrains.services.cwc.inline.InlineChatController
1415

15-
class InlineChatFileListener(project: Project, private val controller: InlineChatController) : FileEditorManagerListener {
16+
class InlineChatFileListener(project: Project, private val controller: InlineChatController) : FileEditorManagerListener, Disposable {
1617
private var currentEditor: Editor? = null
1718
private var selectionListener: InlineChatSelectionListener? = null
1819

@@ -37,6 +38,7 @@ class InlineChatFileListener(project: Project, private val controller: InlineCha
3738
private fun setupListenersForEditor(editor: Editor) {
3839
selectionListener = InlineChatSelectionListener().also { listener ->
3940
editor.selectionModel.addSelectionListener(listener)
41+
Disposer.register(this, listener)
4042
}
4143
}
4244

@@ -48,7 +50,7 @@ class InlineChatFileListener(project: Project, private val controller: InlineCha
4850
selectionListener = null
4951
}
5052

51-
fun dispose() {
53+
override fun dispose() {
5254
currentEditor?.let { removeListenersFromCurrentEditor(it) }
5355
currentEditor = null
5456
}

plugins/core/jetbrains-community/src/icons/AwsIcons.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ object AwsIcons {
129129
object InlineChat {
130130
@JvmField val CONFIRM = load("/icons/resources/inlinechat/amazonq_inline_chat_confirm_icon.svg")
131131

132-
@JvmField val CANCEL = load("/icons/resources/inlinechat/amazonq_inline_chat_cancel_icon.svg")
133-
134132
@JvmField val REJECT = load("/icons/resources/inlinechat/amazonq_inline_chat_reject.svg")
135133

136134
@JvmField val AWS_Q_INLINECHAT_SHORTCUT = load("/icons/resources/inlinechat/amazonq_inline_chat_shortcut.svg")

0 commit comments

Comments
 (0)