DEV Community

Takehiro Adachi
Takehiro Adachi

Posted on

Using neovim's official LSP plugin

We all wan't LSP support when we write code even in dynamic typing language like Ruby. It's 2020 😉

The next neovim will support LSP out of the box, so I thought about giving it a try since the old plugin I was using wasn't supporting LSP's completionItem/resolve just like below

Before - autozimu/LanguageClient-neovim

Alt Text
no function documents.... :(

After - neovim/nvim-lsp(official LSP temporary plugin)

Alt Text
documents yay!


Updating Neovim

First you'll need to install the unreleased latest neovim(aka Nightly)
Here's the link for it, but if you're using Mac & homebrew, you can do it as below.

$ brew unlink neovim
$ brew install neovim --HEAD
$ nvim --version
NVIM v0.5.0-60c581b

Installing official LSP plugin

The official LSP support will be included inside the next 0.5 neovim release version, but it's a plugin ATM so you'll have to install after you install Nightly neovim

I use dein.vim for plugin management so it'll be as below

  call dein#add('neovim/nvim-lsp')

I use deoplete.nvim for autocomplete, so below is necessary in this case

  call dein#add('Shougo/deoplete.nvim')
  call dein#add('Shougo/deoplete-lsp')

Please note that neovim's default autocomplete supports nvim-lsp, so deoplete isn't required

Setting up nvim-lsp

This is the hard part for most plugins, but nvim-lsp configuration is really simple

All you have to do is add the following to you init.vim:

:lua << END

This is when you want to write typescript, if you want to write Ruby too, add the corresponding language server as below:

:lua << END

Don't forget to install the language server itself if you haven't

That's all! 😆


You also might want to set belows keybinds as well 😉

nnoremap <silent>gd    <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent><c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent>K     <cmd>lua vim.lsp.buf.hover()<CR>

Top comments (4)

philt profile image
Phil Thompson

Thanks for this. It might seem obvious to some but you also need to have TypeScript (npm install -g typescript) installed. Not so obvious if you're just writing JavaScript.

piotrnap profile image
Piotr Napierala

You sir, saved me hours of further digging into my problem with lsp. God bless you!

kukula profile image

Hi Takehiro,
Thnks for the article.
I've followed it but when I try to call definition I get this error:

E5108: Error executing lua ...EAD-d8e6a03/share/nvim/runtime/lua/vim/lsp/callbacks.lua:331: RPC[Error] code_name = MethodNotFound, message = "server doesn't support textDocument/declaration"
Enter fullscreen mode Exit fullscreen mode

:checkhealth says everything is OK. Could you please suggest how to debug/fix it?

take profile image
Takehiro Adachi



What kind of LSP are you using? 👀