Using neovim's official LSP plugin

take

Takehiro Adachi

Posted on June 3, 2020

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!

Steps

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
  require'nvim_lsp'.tsserver.setup{}
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
  require'nvim_lsp'.tsserver.setup{}
  require'nvim_lsp'.solargraph.setup{}
END

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

That's all! 😆

P.S.

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>
💖 💪 🙅 🚩
take
Takehiro Adachi

Posted on June 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related