Skip to content
kd
2 Jun 2020
Back to blog

Neovim + LanguageServer.jl

2 min read (262 words)

Table of contents

This is a showcase of some of the capabilities of Julia's LanguageServer.jl and Neovim's built-in Language Server Protocol (LSP) client, as well as the instructions to install this setup.

Capabilities

The .vimrc code corresponding to the capability is linked in the caption of 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. If you run into any issues, open an issue on https://github.com/neovim/neovim/issues.

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.


Citation

@online{krishnamurthy2020neovimlanguageserverjulia,
  author = {Dheepak Krishnamurthy},
  title = {Neovim + LanguageServer.jl},
  year = {2020},
  date = {2020-06-02},
  url = {https://kdheepak.com/blog/neovim-languageserver-julia/},
  langid = {en},
}

For attribution, please cite this work as:

Dheepak Krishnamurthy, "Neovim + LanguageServer.jl", June 2, 2020 https://kdheepak.com/blog/neovim-languageserver-julia/


Drawing in ASCII
Python 2 vs 3