LanguageClient-neovim icon indicating copy to clipboard operation
LanguageClient-neovim copied to clipboard

LSP#position returns wrong position when called with omniComplete

Open hesxenon opened this issue 5 years ago • 1 comments

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

To Reproduce

Steps to reproduce the behavior:

  1. create new empty reason project npm init -y && npm i -D [email protected] && npx bsb -init . -theme basic-reason
  2. Start vim, nvim -u min-vimrc.vim
  3. Edit file Demo.re by adding "string" on a new line
  4. stay in insert mode
  5. press <C-x><C-o> to trigger omnicomplete
  6. 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.

hesxenon avatar Mar 04 '20 01:03 hesxenon

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", ""]
}

martskins avatar Nov 10 '20 22:11 martskins