Skip to content

Commit a969aab

Browse files
committed
fix: failing unit test and detekt failure
1 parent c72abfb commit a969aab

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandler.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import com.intellij.openapi.editor.event.DocumentEvent
1010
import com.intellij.openapi.editor.event.DocumentListener
1111
import com.intellij.openapi.fileEditor.FileDocumentManager
1212
import com.intellij.openapi.fileEditor.FileDocumentManagerListener
13+
import com.intellij.openapi.fileEditor.FileEditor
1314
import com.intellij.openapi.fileEditor.FileEditorManager
1415
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
1516
import com.intellij.openapi.fileEditor.FileEditorManagerListener
17+
import com.intellij.openapi.fileEditor.TextEditor
1618
import com.intellij.openapi.project.Project
1719
import com.intellij.openapi.util.Key
1820
import com.intellij.openapi.vfs.VirtualFile
@@ -170,11 +172,12 @@ class TextDocumentServiceHandler(
170172
}
171173

172174
override fun selectionChanged(event: FileEditorManagerEvent) {
173-
handleActiveEditorChange(event.newEditor?.let { FileEditorManager.getInstance(project).selectedTextEditor })
175+
handleActiveEditorChange(event.newEditor)
174176
}
175177

176-
private fun handleActiveEditorChange(editor: com.intellij.openapi.editor.Editor?) {
177-
val editor = FileEditorManager.getInstance(project).selectedTextEditor
178+
private fun handleActiveEditorChange(fileEditor: FileEditor?) {
179+
// Extract text editor if it's a TextEditor, otherwise null
180+
val editor = (fileEditor as? TextEditor)?.editor
178181
val textDocumentIdentifier = editor?.let { TextDocumentIdentifier(toUriString(it.virtualFile)) }
179182
val cursorState = editor?.let { getCursorState(it) }
180183

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImplTest.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import software.aws.toolkits.core.utils.test.aString
3333
import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
3434
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
3535
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
36+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.ChatCommunicationManager
3637
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.credentials.ConnectionMetadata
3738
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.credentials.SsoProfileData
3839
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererCustomization
@@ -47,7 +48,14 @@ import kotlin.random.nextInt
4748
@ExtendWith(ApplicationExtension::class)
4849
class AmazonQLanguageClientImplTest {
4950
private val project: Project = mockk(relaxed = true)
50-
private val sut = AmazonQLanguageClientImpl(project)
51+
private val mockChatManager = mockk<ChatCommunicationManager>(relaxed = true)
52+
private val sut: AmazonQLanguageClientImpl
53+
54+
init {
55+
// Mock the ChatCommunicationManager service
56+
every { project.service<ChatCommunicationManager>() } returns mockChatManager
57+
sut = AmazonQLanguageClientImpl(project)
58+
}
5159

5260
@Test
5361
fun `telemetryEvent handles basic event with name and data`() {

0 commit comments

Comments
 (0)