Neovim + LanguageServer.jl

Here is the configuration for some capabilities of Julia’s LanguageServer.jl and Neovim’s built-in Language Server Protocol (LSP) client, and some instructions to install this setup.

I’m hoping people can try it with neovim and report issues if they come across it. The more people that use this, the better this functionality will get.

Capabilities

The .vimrc code corresponding to the capability is linked below the each screencapture.

Completion

vim.lsp.omnifunc

Documentation

vim.lsp.buf.hover

Jump to definition

vim.lsp.buf.definition

Linting

vim.lsp.util.show_line_diagnostics

References

vim.lsp.buf.references

Document symbols

vim.lsp.buf.document_symbol

Install

If you’d like to use this you will need the following:

  1. neovim v0.5.0
  2. neovim/nvim-lsp

The neovim/nvim-lsp repository contains language server configurations for a bunch of languages.
Once you have neovim/nvim-lsp installed with your favorite plugin manager, you can run :LspInstall julials.
That will download and install LanguageServer.jl and SymbolServer.jl into your global environment.
You may also want JuliaEditorSupport/julia-vim for syntax highlighting and other niceties.

At the moment you’ll have to make some changes to julials file. The changes required are in this PR: https://github.com/neovim/nvim-lsp/pull/258.

And, at the moment neovim v0.5.0 isn’t released yet. You’ll have to get the latest commit on master and build from source, or download a release from the nightly tag on github.
This also means that the lsp client is not stable yet.
And there may be bugs.

One such bug that I ran into is that LanguageServer.jl does not support textDocument/declaration and textDocument/typeDeclaration, but the neovim LSP client still sends the request if the user makes that request call.
This causes LanguageServer.jl to crash, and this looks like a silent failure from the user perspective.
This is resolved in this PR: https://github.com/neovim/neovim/pull/12421.
You can make the same changes locally to your runtime/lua/vim folder.

Here is a minimal .vimrc configuration that works with NVIM v0.5.0-539-g91e41c857.

set nocompatible
filetype off

if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
  silent !curl -fLo ~/.local/share/nvim/site/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('~/.local/share/nvim/plugged')

Plug 'JuliaEditorSupport/julia-vim'
Plug 'neovim/nvim-lsp'

call plug#end()

lua << EOF
    require'nvim_lsp'.julials.setup{}
EOF

autocmd Filetype julia setlocal omnifunc=v:lua.vim.lsp.omnifunc

nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K     <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gr    <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0    <cmd>lua vim.lsp.buf.document_symbol()<CR>

Once you have this, you should be able to open a .jl file and LanguageServer.jl will start up!
It may take some time for SymbolServer.jl to cache the symbols the first time you run it, so be prepared to wait for a while.
You can type :lua print(vim.lsp.get_log_path())<CR> in neovim to get the path to the language server log file.
When you see [ Info: Received new data from Julia Symbol Server. you should be good to go.

Originally posted over here: kdheepak - Neovim + LanguageServer.jl

17 Likes