carlrobertoh / CodeGPT

The leading open-source AI copilot for JetBrains. Connect to any model in any environment, and customize your coding experience in any way you like.
https://codegpt.ee
Apache License 2.0
1.09k stars 230 forks source link

Got exception in WebStorm: InvalidStateException #583

Open sshakil opened 5 months ago

sshakil commented 5 months ago

What happened?

Got exception in WebStorm: InvalidStateException

Relevant log output or stack trace

com.intellij.openapi.editor.ex.util.LexerEditorHighlighter$InvalidStateException: com.intellij.openapi.editor.ex.util.LexerEditorHighlighter(com.intellij.lang.javascript.JavaScriptHighlightingLexer): Error updating  after DocumentEventImpl[myOffset=113, myOldLength=0, myNewLength=4].
    at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.documentChanged(LexerEditorHighlighter.java:334)
    at com.intellij.openapi.editor.impl.DocumentImpl.lambda$changedUpdate$1(DocumentImpl.java:913)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeNonCancelableSection$2(CoreProgressManager.java:228)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:685)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:641)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$3(CoreProgressManager.java:236)
    at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:236)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:227)
    at com.intellij.openapi.editor.impl.DocumentImpl.changedUpdate(DocumentImpl.java:910)
    at com.intellij.openapi.editor.impl.DocumentImpl.updateText(DocumentImpl.java:814)
    at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:654)
    at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:591)
    at ee.carlrobert.codegpt.util.EditorUtil.updateEditorDocument$lambda$2$lambda$1$lambda$0(EditorUtil.kt:53)
    at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$4(WriteCommandAction.java:338)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$1(WriteCommandAction.java:144)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:975)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.lambda$doRunWriteCommandAction$2(WriteCommandAction.java:142)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:225)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:187)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.doRunWriteCommandAction(WriteCommandAction.java:151)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:118)
    at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:338)
    at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:326)
    at ee.carlrobert.codegpt.util.EditorUtil.updateEditorDocument$lambda$2$lambda$1(EditorUtil.kt:52)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:975)
    at ee.carlrobert.codegpt.util.EditorUtil.updateEditorDocument$lambda$2(EditorUtil.kt:51)
    at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
    at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
    at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:843)
    at com.intellij.openapi.application.impl.ApplicationImpl$4.run(ApplicationImpl.java:463)
    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.openapi.application.impl.ApplicationImpl.runWithImplicitRead(ApplicationImpl.java:1436)
    at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:82)
    at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:124)
    at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:44)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:792)
    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.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:761)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:695)
    at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$12(IdeEventQueue.kt:589)
    at com.intellij.openapi.application.impl.RwLockHolder.runWithoutImplicitRead(RwLockHolder.kt:44)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:589)
    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:106)
    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 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)
Caused by: java.lang.IllegalStateException: Unexpected termination offset for lexer com.intellij.lang.javascript.JavaScriptHighlightingLexer@4615a7b8
    at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.doSetText(LexerEditorHighlighter.java:451)
    at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.setText(LexerEditorHighlighter.java:410)
    at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.incrementalUpdate(LexerEditorHighlighter.java:165)
    at com.intellij.openapi.editor.ex.util.LexerEditorHighlighter.documentChanged(LexerEditorHighlighter.java:326)
    ... 66 more

Steps to reproduce

Prompt that led to exception, with DBRX selected in the dropdown in the Chat window, DBRX selected as the Chat model in CodeGPT Providers preferences and Code Llama selected as the model.

"implementation for this.isInteger, take into account the method comment."

Code file containing the isInteger empty method:

// You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. // // The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer's value set to its depth. // // Return the sum of each integer in nestedList multiplied by its depth. // // // // Example 1: // // // Input: nestedList = [[1,1],2,[1,1]] // Output: 10 // Explanation: Four 1's at depth 2, one 2 at depth 1. 12 + 12 + 21 + 12 + 12 = 10. // Example 2: // // // Input: nestedList = [1,[4,[6]]] // Output: 27 // Explanation: One 1 at depth 1, one 4 at depth 2, and one 6 at depth 3. 11 + 42 + 63 = 27. // Example 3: // // Input: nestedList = [0] // Output: 0 // // // Constraints: // // 1 <= nestedList.length <= 50 // The values of the integers in the nested list is in the range [-100, 100]. // The maximum depth of any integer is less than or equal to 50.

/**

/**

/**

this.setInteger = function(value) { }

/ Set this NestedInteger to hold a nested list and adds a nested integer elem to it. @return {void} / this.add = function(elem) { }

/ Return the nested list that this NestedInteger holds, if it holds a nested list Return null if this NestedInteger holds a single integer @return {NestedInteger[]} / this.getList = function() { }

/* @param {NestedInteger[]} nestedList @return {number} / var depthSum = function(nestedList) {

};

console.assert(depthSum([[1,1],2,[1,1]]) === 10 , [[1,1],2,[1,1]])

CodeGPT version

2.7.1-233

Operating System

macOS

sshakil commented 5 months ago

Tried deleting ~/Library/Caches/JetBrains/WebStorm2023.3/plugins and reinstalling CodeGPT but still reproducible

sshakil commented 5 months ago

Removed some "options" config xml files in the webstorm directory structures, reinstalled CodeGPT and exception is gone, as hoped. Leaving open if you'd like to investigate.

sshakil commented 5 months ago

Ok, I think I know why it's happening. If the JSDoc is malformed like it is in the above file, then the lexer breaks, kind of as expected

carlrobertoh commented 4 months ago

Thank you for reporting this issue. I will try to look into it soon.