sourcegraph / jetbrains

Apache License 2.0
61 stars 19 forks source link

JetBrains: Crash occurred with "java.lang.IllegalArgumentException: Incorrect offsets: start=201; end=200" error #1475

Closed jay-fibi closed 2 months ago

jay-fibi commented 4 months ago

Cody Version

v5.5.10-nightly

IDE Information

IntelliJ IDEA 2023.3.3 (Community Edition) Build #IC-233.14015.106, built on January 25, 2024 Runtime version: 17.0.9+7-b1087.11 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 14.3 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 8 Metal Rendering is ON Registry: ide.experimental.ui=true Non-Bundled Plugins: idea.plugin.protoeditor (233.13135.65) DevKit (233.14015.152) gherkin (233.11799.165) cucumber-java (233.11799.196) PythonCore (233.14015.106) com.sourcegraph.jetbrains (5.5.10-nightly) Kotlin: 233.14015.106-IJ

Describe the bug

Platform: macOS

Steps to reproduce:

  1. Have Cody plugin installed in your JB IntelliJ IDEA editor
  2. Login to Cody with Pro user
  3. Open any source code file and select everything
  4. Right click to open context menu
  5. Choose "Code > Document Code"
  6. Click on "Edit & Retry" and choose another LLM which can generate longer document
  7. Click on "Show Diff" when the new document generated

Observed behavior:

Crash occurred with below stacktrace, Stacktrace:

java.lang.IllegalArgumentException: Incorrect offsets: start=201; end=200
    at com.intellij.openapi.util.TextRangeScalarUtil.toScalarRange(TextRangeScalarUtil.java:19)
    at com.intellij.openapi.editor.impl.IntervalTreeImpl$IntervalNode.<init>(IntervalTreeImpl.java:59)
    at com.intellij.openapi.editor.impl.RangeMarkerTree$RMNode.<init>(RangeMarkerTree.java:130)
    at com.intellij.openapi.editor.impl.RangeMarkerTree.createNewNode(RangeMarkerTree.java:103)
    at com.intellij.openapi.editor.impl.RangeMarkerTree.createNewNode(RangeMarkerTree.java:25)
    at com.intellij.openapi.editor.impl.IntervalTreeImpl.addInterval(IntervalTreeImpl.java:798)
    at com.intellij.openapi.editor.impl.RangeMarkerTree.addInterval(RangeMarkerTree.java:70)
    at com.intellij.openapi.editor.impl.DocumentImpl.registerRangeMarker(DocumentImpl.java:418)
    at com.intellij.openapi.editor.impl.RangeMarkerImpl.registerInTree(RangeMarkerImpl.java:69)
    at com.intellij.openapi.editor.impl.RangeMarkerImpl.<init>(RangeMarkerImpl.java:59)
    at com.intellij.openapi.editor.impl.RangeMarkerImpl.<init>(RangeMarkerImpl.java:35)
    at com.intellij.openapi.editor.impl.DocumentImpl.createRangeMarker(DocumentImpl.java:507)
    at com.intellij.openapi.editor.Document.createRangeMarker(Document.java:225)
    at com.sourcegraph.cody.edit.fixupActions.ReplaceUndoableAction.createBeforeMarker(ReplaceUndoableAction.kt:61)
    at com.sourcegraph.cody.edit.fixupActions.ReplaceUndoableAction.<init>(ReplaceUndoableAction.kt:17)
    at com.sourcegraph.cody.edit.fixupActions.ReplaceUndoableAction.<init>(ReplaceUndoableAction.kt:24)
    at com.sourcegraph.cody.edit.fixupActions.ReplaceUndoableAction.copyForDocument(ReplaceUndoableAction.kt:53)
    at com.sourcegraph.cody.edit.fixupActions.ReplaceUndoableAction.copyForDocument(ReplaceUndoableAction.kt:10)
    at com.sourcegraph.cody.edit.sessions.FixupSession.createDiffDocument(FixupSession.kt:399)
    at com.sourcegraph.cody.edit.EditShowDiffAction.getDiffRequestChain(EditShowDiffAction.kt:29)
    at com.intellij.diff.actions.BaseShowDiffAction.actionPerformed(BaseShowDiffAction.java:56)
    at com.sourcegraph.cody.edit.widget.LensAction.triggerAction(LensAction.kt:99)
    at com.sourcegraph.cody.edit.widget.LensAction.onClick(LensAction.kt:78)
    at com.sourcegraph.cody.edit.widget.LensWidgetGroup.handleMouseClick(LensWidgetGroup.kt:223)
    at com.sourcegraph.cody.edit.widget.LensWidgetGroup.access$handleMouseClick(LensWidgetGroup.kt:45)
    at com.sourcegraph.cody.edit.widget.LensWidgetGroup$mouseClickListener$1.mouseClicked(LensWidgetGroup.kt:60)
    at com.intellij.openapi.editor.impl.EditorImpl$MyMouseAdapter.runMouseClickedCommand(EditorImpl.java:4132)
    at com.intellij.openapi.editor.impl.EditorImpl$MyMouseAdapter.mouseReleased(EditorImpl.java:4053)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6657)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3385)
    at java.desktop/java.awt.Component.processEvent(Component.java:6422)
    at java.desktop/java.awt.Container.processEvent(Container.java:2266)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4969)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4583)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4524)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2809)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:794)
    at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
    at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:733)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:766)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:764)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:763)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:695)
    at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.kt:635)
    at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$10(IdeEventQueue.kt:580)
    at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:75)
    at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:67)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:580)
    at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:72)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:355)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:354)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:793)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:354)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:349)
    at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1014)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:114)
    at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1014)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:349)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:848)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:391)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at ...

Expected behavior

Crash should not occur while clicking on "Show Diff".

Additional context

Video link:

https://drive.google.com/file/d/1U3YYAb9OeQ6ww4glxcyt1hlrTe2A3a9z/view?usp=drive_link

mkondratek commented 4 months ago

The prompt used is:

Write a brief documentation comment for the selected code. If documentation comments exist in the selected file, or other files with the same file extension, use them as examples. Pay attention to the scope of the selected code (e.g. exported function/API vs implementation detail in a function), and use the idiomatic style for that type of code scope. Only generate the documentation for the selected code, do not generate the code. Do not enclose any other code or comments besides the documentation. Enclose only the documentation for the selected code and nothing else.

when I Edit & Retry with "write a docstring" it worked properly.


Btw I noticed one more problem: the presented range is wrong after Edit & Retry - (Main.java at 6:7): image

and that makes me thinking - maybe let's hide Edit & Retry for Document Code for now?

taylorsperry commented 3 months ago

I'm on a Mac so we should check that the error @jay-fibi reported isn't reproing on Windows.

I'm on main (commit 9a85ce8f09e07ff35db1e0a514af55e3ad777614) and don't see the crash/stacktrace reported above, but after I select all the code in a kotlin file, run Document, click Edit & Retry, switch the LLM, and click "Edit Code," the new documentation appears below the highlighted code and the code lens disappears. Loom.

When I switch to a typescript file and repeat the same behavior, after I click Edit & Retry and switch LLMs, the initial documentation disappears (as expected) but there's no new generated documentation or code lens. Loom.

I agree with @mkondratek that if we can isolate the Edit & Retry errors to only failing when they follow a Document command, an acceptable solution would be to just remove the Edit & Retry code lens after a Document command has been executed (user only has options to Accept, Undo, Show Diff).

The Document --> Edit & Retry --> Switch LLM flow seems to work as expected in VS Code, though on a typescript file I did notice some strange highlighting. Loom.

mkondratek commented 3 months ago

I tried the scenario and I am not able to reproduce it. Also, I have not seen java.lang.IllegalArgumentException: Incorrect offsets: start=201; end=200-like errors for a while.

We merged #1635 which was a significant improvement in the scope of the doc sync b/w the agent and the client. There were some other fixes too. Most likely it's gone.

@taylorsperry, imho we can close it