Skip to content
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 'Slow operations are prohibited on EDT.' when Amazon Q is determining if a file supports inline suggestions (#4823)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.intellij.openapi.editor.event.EditorFactoryEvent
import com.intellij.openapi.editor.event.EditorFactoryListener
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.psi.PsiDocumentManager
import com.intellij.openapi.fileEditor.FileDocumentManager
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isCodeWhispererEnabled
import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatus
Expand All @@ -17,27 +17,26 @@
class CodeWhispererEditorListener : EditorFactoryListener {
override fun editorCreated(event: EditorFactoryEvent) {
val editor = (event.editor as? EditorImpl) ?: return
editor.project?.let { project ->
PsiDocumentManager.getInstance(project).getPsiFile(editor.document)?.programmingLanguage() ?. let { language ->
// If language is not supported by CodeWhisperer, no action needed
if (!language.isCodeCompletionSupported()) return
// If language is supported, install document listener for CodeWhisperer service
editor.document.addDocumentListener(
object : BulkAwareDocumentListener {
// TODO: Track only deletion changes within the current 5-min interval which will give
// the most accurate code percentage data.
override fun documentChanged(event: DocumentEvent) {
if (!isCodeWhispererEnabled(project)) return
CodeWhispererInvocationStatus.getInstance().documentChanged()
CodeWhispererCodeCoverageTracker.getInstance(project, language).apply {
activateTrackerIfNotActive()
documentChanged(event)
}
}
},
editor.disposable
)
}
}
val project = editor.project ?: return

val language = FileDocumentManager.getInstance().getFile(editor.document)?.programmingLanguage() ?: return
// If language is not supported by CodeWhisperer, no action needed
if (!language.isCodeCompletionSupported()) return
// If language is supported, install document listener for CodeWhisperer service
editor.document.addDocumentListener(
object : BulkAwareDocumentListener {

Check warning on line 27 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorListener.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorListener.kt#L26-L27

Added lines #L26 - L27 were not covered by tests
// TODO: Track only deletion changes within the current 5-min interval which will give
// the most accurate code percentage data.
override fun documentChanged(event: DocumentEvent) {
if (!isCodeWhispererEnabled(project)) return
CodeWhispererInvocationStatus.getInstance().documentChanged()
CodeWhispererCodeCoverageTracker.getInstance(project, language).apply {
activateTrackerIfNotActive()
documentChanged(event)
}
}

Check warning on line 37 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorListener.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorListener.kt#L32-L37

Added lines #L32 - L37 were not covered by tests
},
editor.disposable

Check warning on line 39 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorListener.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorListener.kt#L39

Added line #L39 was not covered by tests
)
}
}
Loading