RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.14k stars 47 forks source link

LSP integration results in error #58

Closed RageKnify closed 3 years ago

RageKnify commented 3 years ago

I'm getting the following error when the cursor is over something that isn't meant to be highlighted (for example a space or an opening parenthesis): Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1111: bad argument #1 to 'ipairs' (table expected, got nil)

When using the plugin without the LSP integration it works fine. Might be related to latest neovim master, I'm on https://github.com/neovim/neovim/commit/84d08358b7c4af1d92c7d47edc2c7ae9594ffae4, the latest nightly as of right now.

(I'm on master for vim-illuminate, updated along with neovim)

garcia5 commented 3 years ago

Same issue here, on a freshly installed neovim --HEAD instance

RRethy commented 3 years ago

Can you paste your config?

garcia5 commented 3 years ago

I can try and create a more minimal reproducer as well a bit later. I'm using Ubuntu on WSL if that helps

RageKnify commented 3 years ago

Having the recommended setup and creating a new crate (with cargo new example) seems to be enough, just having the cursor over the fn of fn main() { triggers the error, I'll try to write a minimal init.vim.

RRethy commented 3 years ago

Can you checkout the branch issue58 and tell me what it prints in :messages. I don't have this error with a new rust repo.

RRethy commented 3 years ago

Also what's the latest commit you see on master for vim-illuminate?

RageKnify commented 3 years ago
if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

call plug#begin('~/.config/nvim/plugged')

Plug 'neovim/nvim-lspconfig'

Plug 'RRethy/vim-illuminate'

call plug#end()

lua require'lspconfig'.rust_analyzer.setup{ on_attach = require'illuminate'.on_attach }

This was enough, I created a new user to test it. I'm on commit238891e7b7e7d6c00289d1c52d230431a7a5e35e

I'll try the issue58 branch.

RageKnify commented 3 years ago

nil "textDocument/documentHighlight" nil 1 1 nil

nil "textDocument/documentHighlight" { {
    range = {
      end = {
        character = 7,
        line = 0
      },
      start = {
        character = 3,
        line = 0
      }
    }
  } } 1 1 nil

There's also this: nil "textDocument/documentHighlight" {} 1 1 nil

I think this is the output you wanted, neovim only gives me line by line, I need to press enter to get the next line.

RRethy commented 3 years ago

Let me know if master fixes it.

RageKnify commented 3 years ago

Yeah, seems to have fixed it ty for the quick fix!

RRethy commented 3 years ago

Awesome! Not sure why but for my testing I never got nil as the third param which was the cause of the error. I had a mistake in lua syntax, been coding too much python recently.

garcia5 commented 3 years ago

Fixed for me as well, ty for the quick fix!

RageKnify commented 3 years ago

Can you explain what the commit changed?

I haven't written lua (only some LSP config), but it looks like the code changed from if not X == Y then Z to if X != Y then Z, which seems like the same to me.

garcia5 commented 3 years ago

if (not X) == Y vs if not (X == Y) (I think)

RageKnify commented 3 years ago

if (not X) == Y vs if not (X == Y) (I think)

Yeah, sounds right, ty. I ran it in the REPL and got:

> if not 0 == 1 then print('entered') end
> if not (0 == 1) then print('entered') end
entered

In my example something crucial is:

Only nil and false are falsy

RRethy commented 3 years ago

https://www.lua.org/pil/3.5.html

Yea it's because not has higher associativity precedence than ==.