aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
768 stars 226 forks source link

Click "insert at cursor" when the whole text selected in the file throw errors #5106

Open gusti-andika opened 1 week ago

gusti-andika commented 1 week ago

Describe the bug

When tried to insert at curser to file when whole its content is selected, toolkit throws ArrayIndexOutOfBoundException To reproduce Steps to reproduce the behavior: -

  1. Go to 'Amazon Q Chat Window'
  2. Open the file to apply the AI suggested code changes
  3. Select all text in the file
  4. From 'Amazon Q Chat Window' Click on 'Insert at Cursor' at suggested code changes
  5. Error thrown

Expected behavior The suggested changes by Amazon Q should be applied to the file replacing the currently selected content

Stacktrace Unhandled exception in [CoroutineName(software.aws.toolkits.jetbrains.services.cwc.App), com.intellij.util.concurrency.AppScheduledExecutorService$BackendThreadPoolExecutor@639dda70[Running, pool size = 5, active threads = 3, queued tasks = 0, completed tasks = 666169]]

java.lang.IndexOutOfBoundsException: Wrong offset: 667; documentLength: 0 at com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImpl.java:560) at software.aws.toolkits.jetbrains.services.cwc.controller.ChatController$processInsertCodeAtCursorPosition$2.invokeSuspend$lambda$1$lambda$0(ChatController.kt:226) at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$4(WriteCommandAction.java:341) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:147) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction$lambda$5(AnyThreadWriteThreadingSupport.kt:379) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:389) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:379) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:896) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:145) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:226) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:188) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:154) at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:121) at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:341) at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:329) at software.aws.toolkits.jetbrains.services.cwc.controller.ChatController$processInsertCodeAtCursorPosition$2.invokeSuspend$lambda$1(ChatController.kt:221) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction$lambda$5(AnyThreadWriteThreadingSupport.kt:379) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:389) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:379) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:896) at software.aws.toolkits.jetbrains.services.cwc.controller.ChatController$processInsertCodeAtCursorPosition$2.invokeSuspend(ChatController.kt:220) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at com.intellij.openapi.application.impl.DispatchedRunnable.run(DispatchedRunnable.kt:44) at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:236) at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:25) at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:218) at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:117) at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:43) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:781) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:728) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:750) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:675) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:573) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$18$lambda$17$lambda$16$lambda$15(IdeEventQueue.kt:355) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:857) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$18$lambda$17$lambda$16(IdeEventQueue.kt:354) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$2$lambda$1(IdeEventQueue.kt:1045) at com.intellij.openapi.application.WriteIntentReadAction.lambda$run$0(WriteIntentReadAction.java:24) at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:128) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteIntentReadAction(ApplicationImpl.java:916) at com.intellij.openapi.application.WriteIntentReadAction.compute(WriteIntentReadAction.java:55) at com.intellij.openapi.application.WriteIntentReadAction.run(WriteIntentReadAction.java:23) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$2(IdeEventQueue.kt:1045) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$3(IdeEventQueue.kt:1054) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:109) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1054) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$18(IdeEventQueue.kt:349) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:395) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [CoroutineName(software.aws.toolkits.jetbrains.services.cwc.App), StandaloneCoroutine{Cancelled}@4333d82, com.intellij.util.concurrency.AppScheduledExecutorService$BackendThreadPoolExecutor@639dda70[Running, pool size = 5, active threads = 2, queued tasks = 0, completed tasks = 667343]]

Your Environment