LanguageClient-neovim
LanguageClient-neovim copied to clipboard
LSP#position returns wrong position when called with omniComplete
Describe the bug
LSP#position() returns different values when called with omnicomplete compared to regular command.
Typing string and pressing <C-x><C-o> yields {"character": 0, "line": 4} (taken from the following logs) while :echo LSP#position() yields {"character": 5, "line": 4}
logs
01:52:00 INFO writer-None src/rpcclient.rs:215 => None {"jsonrpc":"2.0","method":"eval","params":["LSP#position()"],"id":47}
01:52:00 INFO reader-None src/rpcclient.rs:169 <= None {"id": 47, "jsonrpc": "2.0", "result": {"character": 0, "line": 4}}
Environment
- neovim version: v0.5.0-135-g90981f586
- This plugin version: 222e250
- This plugin's binary version: languageclient 0.1.156
- Minimal vimrc content: min-vimrc adapted for reason
- Language server link and version: reason language server v 1.7.7
To Reproduce
Steps to reproduce the behavior:
- create new empty reason project
npm init -y && npm i -D [email protected] && npx bsb -init . -theme basic-reason - Start vim,
nvim -u min-vimrc.vim - Edit file Demo.re by adding "string" on a new line
- stay in insert mode
- press
<C-x><C-o>to trigger omnicomplete - no completions are given because the character position is sent as 0
Current behavior
LSP#position() is giving character position as 0 when triggered from omnicomplete, but when called from normal mode it is giving the correct character position of 5
Expected behavior
Character position should be sent correctly, meaning that it should not be 0 for omnicomplete when it isn't 0 for normal mode
Additional context
I've noticed that the character position is always the position of the previous delimitating character, so in this case typing Pervasives.string would yield to correct results because the character position is 11 which doesn't cause problems with the language server. However I think it should not be 11 but 16, since that's where the cursor currently is.
I've also tried forcing a character position bigger than 0 by changing the LSP.vim that gets loaded by removing the - 1 from the function LSP#character. By doing so I was able to get the correct results, so I'm thinking that the faulty behaviour lies with LanguageClient, and not the language server.
I wasn't able to reproduce this. It offers me no completions for string but it's sending the right character number
This is what the omnicomplete function is receiving.
{
"bufnr": 4,
"character": 6,
"complete_position": 0,
"filename": "/Users/martin/dev/testreason/src/Demo.re",
"handle": false,
"languageId": "reason",
"line": 1,
"text": ["Js.log(\"Hello, BuckleScript and Reason!\");", "string", ""]
}