Skip to content
Dheepak Krishnamurthy edited this page Jul 5, 2020 · 24 revisions

Vim and Neovim are able to use the Julia LanguageServer via LanguageClient-neovim with completion from nvim-completion-manager.

The following is a basic minimal config (vimrc for Vim; init.vim for Neovim) using vim-plug:

call g:plug#begin()
  Plug 'JuliaEditorSupport/julia-vim'
  Plug 'autozimu/LanguageClient-neovim', {'branch': 'next', 'do': 'bash install.sh'}
  Plug 'roxma/nvim-completion-manager'  " optional
call g:plug#end()

" julia
let g:default_julia_version = '1.0'

" language server
let g:LanguageClient_autoStart = 1
let g:LanguageClient_serverCommands = {
\   'julia': ['julia', '--startup-file=no', '--history-file=no', '-e', '
\       using LanguageServer;
\       using Pkg;
\       import StaticLint;
\       import SymbolServer;
\       env_path = dirname(Pkg.Types.Context().env.project_file);
\       debug = false; 
\       
\       server = LanguageServer.LanguageServerInstance(stdin, stdout, debug, env_path, "");
\       server.runlinter = true;
\       run(server);
\   ']
\ }

nnoremap <silent> K :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>

Note:

  1. The LanguageServer, SymbolServer and StaticLint packages must be installed in Julia (1.x), i.e.

    julia> using Pkg
    julia> Pkg.add("LanguageServer")
    julia> Pkg.add("SymbolServer")
    julia> Pkg.add("StaticLint")
  2. If Julia (0.6 or greater) is not present in the PATH environment, either add the julia binary folder to PATH or directly reference the julia binary in g:LanguageClient_serverCommands, e.g. for macOS:

    let g:LanguageClient_serverCommands = {
    \   'julia': ['/Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia', ...
  3. See vim-plug for more details on installing/managing packages in Vim/Neovim

SpaceVim

SpaceVim have a layer to use LanguageServer.jl, the setup is automatic once you installed the Julia layer.

Neovim Built In LSP

Check out this thread on discourse: https://discourse.julialang.org/t/neovim-languageserver-jl/37286/7?u=kdheepak OR this blog post. This provides examples of using neovim's built in language server protocol and using deoplete with deoplete-lsp.

You can also see examples of using neovim, nvim-lsp, completion-nvim and diagnostic-nvim here:

https://github.com/kdheepak/dotfiles/blob/47a38e20ef4bef7a189927646eee3c91f911ffd7/vimrc

Here's the relevant pieces:

  1. Install the plugins
Plug 'nvim-lua/diagnostic-nvim'                                    | " better neovim built in lsp diagnostics
Plug 'nvim-lua/completion-nvim'                                    | " better neovim built in lsp completion
  1. Initialize
autocmd BufEnter * lua require'completion'.on_attach()

lua << EOF
    local nvim_lsp = require'nvim_lsp'
    local on_attach_vim = function()
        require'diagnostic'.on_attach()
    end
    nvim_lsp.julials.setup({on_attach=on_attach_vim})
EOF
  1. Configure
let g:diagnostic_auto_popup_while_jump = 0
let g:diagnostic_enable_virtual_text = 0
let g:diagnostic_enable_underline = 0
let g:completion_timer_cycle = 200 "default value is 80
Clone this wiki locally