-
Notifications
You must be signed in to change notification settings - Fork 75
Negative position value in textDocument/hover request #381
Description
- 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.
- Open a
.tex
file (and possibly confirm that the texlab language server is connected to buffer) - Type something that triggers completion, for example
\begin{
- 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: latex-lsp/texlab#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:
completion-nvim/lua/completion/hover.lua
Lines 352 to 360 in d62fff8
local row, col = unpack(api.nvim_win_get_cursor(0)) | |
row = row - 1 | |
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1] | |
col = vim.str_utfindex(line, col) | |
local params = { | |
textDocument = vim.lsp.util.make_text_document_params(); | |
position = { line = row; character = col-string.len(item.word); } | |
} | |
vim.lsp.buf_request(bufnr, 'textDocument/hover', params, handler_function) |
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!