ballerina-platform / lsp4intellij

This language client library provides language server protocol support for IntelliJ IDEA and other Jetbrains IDEs.
Apache License 2.0
428 stars 104 forks source link

Incorrect code completions on the start of the document #351

Closed ThemiraChathumina closed 3 months ago

ThemiraChathumina commented 3 months ago

Description:

When typing at the beginning of a document (offset 0), code completions fail to incorporate the initial characters typed. As a result, when a completion suggestion is accepted, it incorrectly appends to the text initially entered.

20240409090208online-video-cutter com-ezgif com-video-to-gif-converter

Also getting the following IDE error when inserting a suggestion that is not a code snippet.

java.lang.Throwable: Incorrect offsets: startOffset=9, endOffset=16, text length=9
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:161)
    at com.intellij.openapi.editor.impl.DocumentImpl.createRangeMarker(DocumentImpl.java:507)
    at com.intellij.openapi.editor.Document.createRangeMarker(Document.java:229)
    at com.intellij.codeInsight.template.impl.TemplateState.start(TemplateState.java:321)
    at com.intellij.codeInsight.template.impl.TemplateState.start(TemplateState.java:297)
    at com.intellij.codeInsight.template.impl.TemplateManagerImpl.lambda$startTemplate$2(TemplateManagerImpl.java:171)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:207)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:172)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:162)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:148)
    at com.intellij.codeInsight.template.impl.TemplateManagerImpl.startTemplate(TemplateManagerImpl.java:175)
    at com.intellij.codeInsight.template.impl.TemplateManagerImpl.startTemplate(TemplateManagerImpl.java:193)
    at com.intellij.codeInsight.template.impl.TemplateManagerImpl.startTemplate(TemplateManagerImpl.java:132)
    at org.wso2.lsp4intellij.editor.EditorEventManager.prepareAndRunSnippet(EditorEventManager.java:1018)
    at org.wso2.lsp4intellij.editor.EditorEventManager.lambda$addCompletionInsertHandlers$23(EditorEventManager.java:917)
    at com.intellij.codeInsight.lookup.LookupElementBuilder.handleInsert(LookupElementBuilder.java:397)
    at com.intellij.codeInsight.lookup.LookupElementDecorator.handleInsert(LookupElementDecorator.java:59)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$insertItem$14(CodeCompletionHandlerBase.java:690)
    at com.intellij.util.indexing.FileBasedIndex.lambda$ignoreDumbMode$0(FileBasedIndex.java:163)
    at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
    at com.intellij.util.indexing.FileBasedIndexEx.ignoreDumbMode(FileBasedIndexEx.java:574)
    at com.intellij.util.indexing.FileBasedIndex.ignoreDumbMode(FileBasedIndex.java:162)
    at com.intellij.util.indexing.DumbModeAccessType.ignoreDumbMode(DumbModeAccessType.java:43)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$insertItem$15(CodeCompletionHandlerBase.java:689)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:959)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.insertItem(CodeCompletionHandlerBase.java:673)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$doInsertItem$12(CodeCompletionHandlerBase.java:598)
    at com.intellij.openapi.editor.impl.CaretModelImpl.lambda$runForEachCaret$3(CaretModelImpl.java:312)
    at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:421)
    at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:321)
    at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:296)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.doInsertItem(CodeCompletionHandlerBase.java:588)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.insertItemHonorBlockSelection(CodeCompletionHandlerBase.java:548)
    at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lookupItemSelected(CodeCompletionHandlerBase.java:494)
    at com.intellij.codeInsight.completion.CompletionProgressIndicator.itemSelected(CompletionProgressIndicator.java:180)
    at com.intellij.codeInsight.completion.BaseCompletionLookupArranger.itemSelected(BaseCompletionLookupArranger.java:224)
    at com.intellij.codeInsight.lookup.impl.LookupImpl.fireItemSelected(LookupImpl.java:915)
    at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookupInWritableFile(LookupImpl.java:569)
    at com.intellij.codeInsight.lookup.impl.LookupImpl.lambda$finishLookup$5(LookupImpl.java:527)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:207)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:172)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:162)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:148)
    at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookup(LookupImpl.java:527)
    at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookup(LookupImpl.java:512)
    at com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction$Handler.lambda$doExecute$0(ChooseItemAction.java:72)
    at com.intellij.util.SlowOperations.lambda$allowSlowOperations$0(SlowOperations.java:77)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:64)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:76)
    at com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction$Handler.doExecute(ChooseItemAction.java:72)
    at com.intellij.openapi.editor.actionSystem.DynamicEditorActionHandler.doExecute(DynamicEditorActionHandler.java:52)
    at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$4(EditorActionHandler.java:199)
    at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:89)
    at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:198)
    at com.intellij.openapi.editor.actionSystem.EditorAction.lambda$actionPerformed$0(EditorAction.java:89)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:216)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:172)
    at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:98)
    at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:73)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performActionDumbAware$5(ActionUtil.java:273)
    at com.intellij.util.SlowOperations.lambda$allowSlowOperations$0(SlowOperations.java:77)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:68)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:76)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:273)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:616)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$processAction$3(IdeKeyEventDispatcher.java:676)
    at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:95)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:675)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:626)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:486)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:481)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:232)
    at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:889)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:833)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:449)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:808)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:781)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:502)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
NipunaRanasinghe commented 3 months ago

Closing with https://github.com/ballerina-platform/lsp4intellij/pull/352