intellij-lsp
intellij-lsp copied to clipboard
Auto-completion issue with TextEdit
When I try to auto-complete something, the text behind the cursor is overwritten.
But this happens only if the LSP server sends a TextEdit. (The problem does not occur if textEdit = null) Here is what comes back from the LSP server that causes the issue:
[
left = null
right = CompletionList [
isIncomplete = false
items = ArrayList (
CompletionItem [
label = "Integer64"
textEdit = TextEdit [
range = Range [
start = Position [
line = 1
character = 10
]
end = Position [
line = 1
character = 13
]
]
newText = "Integer64"
]
kind = Interface
sortText = "2)Integer64"
commitCharacters = ArrayList (
"."
)
data = {}
detail = null
documentation = null
deprecated = null
preselect = null
filterText = null
insertText = null
insertTextFormat = null
additionalTextEdits = null
command = null
]
)
]
]
So why is this happening with TextEdit?
your text edit contains range to insert text. this range captures ;\r\n
and insert Integer64 into it. Problem is on language server side, not the plugin. plugin does his stuff as required by the protocol
see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
your text edit contains range to insert text. this range captures
;\r\n
and insert Integer64 into it. Problem is on language server side, not the plugin. plugin does his stuff as required by the protocolsee https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
Thank you for your fast answer @nixel2007 !
One more question. We have been using the LSP server in VS Code for several years. The plugin has already been rolled out to the customer. Now we want to use the same LSP server for IntelliJ. Unfortunately we get the behavior described above.
In VS Code it works without problems for years. Since VS Code was created directly by Microsoft, it would be surprising if they do not follow their own specification.
In VS Code it works without problems for years. Since VS Code was created directly by Microsoft, it would be surprising if they do not follow their own specification.
Hm... it is interesting. Indeed if it works in vscode it should work in intellij. ok, lets wait for @gtache
your text edit contains range to insert text. this range captures
;\r\n
and insert Integer64 into it. Problem is on language server side, not the plugin. plugin does his stuff as required by the protocol
Hmm, looking at the video, counting chars to 'Int' is exactly 10. And protocol ranges are zero-based. So range 1:10-1:13 covers 'Int' not ';\r\n'
Please check again
I've debugged a similar issue today. It seems to be related how intellij tries to be smart about where to place the start of completion text. You may confirm if your completion is working without any predefined text.
The relevant code is in https://github.com/JetBrains/intellij-community/blob/22ab67318325e3ce280a87a2de83f517211f644c/platform/analysis-impl/src/com/intellij/codeInsight/completion/CompletionData.java#L176-L183
I hope this helps. I did not find a way to alter this behavior. Hopefully you'll find one.