Neovim + LanguageServer.jl

Instant startup with PackageCompiler

LanguageServer is somewhat slow to start so it is very useful to use a custom sysimage using PackageCompiler to reduce this time. On my machine I get the first response after 20+ seconds, but with a custom sysimage I can execute LS commands instantaneously.

Here is my setup:

  1. Modify init.vim to use a custom Julia executable (if it exist):

    lua << EOF
    require'lspconfig'.julials.setup{
        on_new_config = function(new_config, _)
            local julia = vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia")
            if require'lspconfig'.util.path.is_file(julia) then
                new_config.cmd[1] = julia
            end
        end
    }
    EOF
    
  2. Utilize this Makefile.

  3. Run make. This will set up a dummy project and launch nvim with julia recording everything that is compiled. Wait until the LanguageServer responds (there are a bunch of things in this dummy project that will result in warnings) and then run some LanguageServer commands, for example ::lua vim.lsp.buf.hover() to fetch documentation).

  4. Quit nvim.

  5. PackageCompiler will now build a custom languageserver.so sysimage.

  6. Profit.

16 Likes