completion-nvim icon indicating copy to clipboard operation
completion-nvim copied to clipboard

Negative position value in textDocument/hover request

Open yochem opened this issue 3 years ago • 0 comments

  • [x] Please read through this section before posting a bug report.

My testing minimal init.vim Post your init.vim to help me reproduce this issue

vim.cmd('packadd packer.nvim')
require('packer').startup(function(use)
    use 'wbthomason/packer.nvim'
    use 'neovim/nvim-lspconfig'
    use 'nvim-lua/completion-nvim'
end)

vim.cmd [[au BufRead,BufNewFile *.tex setlocal filetype=tex]]
require'lspconfig'.texlab.setup{on_attach=require'completion'.on_attach}

vim.cmd[[au Filetype lua setl omnifunc=v:lua.vim.lsp.omnifunc]]
vim.cmd[[inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"]]
vim.cmd[[inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"]]

vim.cmd[[set completeopt=menuone,noinsert]]

How to reproduce Detailed step to reproduce this issue.

  1. Open a .tex file (and possibly confirm that the texlab language server is connected to buffer)
  2. Type something that triggers completion, for example \begin{
  3. The language server crashes

Expected behavior A clear and concise description of what you expected to happen.

The language server should not crash.

Okay, I've had quite some struggles with this. At first, I thought this was a bug in texlab because only that language server crashed emmediately after the completion pop up comes. I opened an issue on its repository: https://github.com/latex-lsp/texlab/issues/450. Turns out the language servers receives the following request:

{"method": "textDocument/hover", "jsonrpc": "2.0", "id": 6, "params": {"textDocument": {"uri": "file:///Users/yochem/Documents/thesis/paper/discussion.tex"}, "position": {"character": -2, "line": 14}}}

In this, params..textDocument.position.character has a value of -2. This should not be the case (character can not be negative). While going through my configs, it turned out to be that completeopt without noselect causes this! The -2 value is set somewhere around here:

https://github.com/nvim-lua/completion-nvim/blob/d62fff879b29fa1ce915887a75305af0fff57d32/lua/completion/hover.lua#L352-L360

At least, that is where the request comes from.

So, TL;DR, language server quits after receiving bad value for position due to completeopt being 'menuone,noinsert'. It works as expected when noselect is added to compleopt.

I'm on the latest nvim (well, updated 5 hours ago) and latest completion-nvim.

Let me know if I could provide more information, happy to help!

yochem avatar Jun 27 '21 21:06 yochem