Neovim + LanguageServer.jl

@fredrikekre has updated the default nvim-lspconfig for Julia [julia] improvements to current project detection. by fredrikekre · Pull Request #1079 · neovim/nvim-lspconfig · GitHub, which should, hopefully :crossed_fingers:, work better out-of-the-box now for everyone.

1 Like

neovim/nvim-lspconfig#1153 is merged now so things should work out of the box if you:

  1. Install LanguageServer in the shared environment ~/.julia/environments/nvim-lspconfig:
    $ julia --project=~/.julia/environments/nvim-lspconfig -e 'using Pkg; Pkg.add("LanguageServer")'
    
  2. Enable it in init.lua:
    require'lspconfig'.julials.setup{}
    
    or init.vim:
    lua << EOF
    require'lspconfig'.julials.setup{}
    EOF
    
16 Likes

I’ve set up everything as @fredrikekre described. LSP takes up to 2 min to start working.

I keep getting these errors .cache/nvim/lsp.log:

Can anyone shed a light?

[ START ] 2021-09-04T19:55:02-0300 ] LSP logging initiated
[ START ] 2021-09-04T20:51:37-0300 ] LSP logging initiated
[ ERROR ] 2021-09-04T20:51:38-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	'┌ Info: Running language server\n│   VERSION = v"1.6.2"\n│   pwd() = "/home/storopoli/Desktop"\n│   project_path = "/home/storopoli/.julia/environments/v1.6"\n└   depot_path = ""\n'
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Cloud was unable to cache Qt5Base_jll in the past, we won't try to retrieve it again.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for JuliaInterpreter.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for FuzzyCompletions.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for OpenBLAS_jll.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for IndirectArrays.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for LibSSH2_jll.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Cloud was unable to cache Wayland_jll in the past, we won't try to retrieve it again.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for LoweredCodeUtils.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for TableOperations.\n"
[ ERROR ] 2021-09-04T20:51:51-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for MeshIO.\n"
[ ERROR ] 2021-09-04T20:51:53-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for SentinelArrays.\n"
[ ERROR ] 2021-09-04T20:51:53-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for GR_jll.\n"
[ ERROR ] 2021-09-04T20:51:53-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Couldn't retrieve cache file for PNGFiles.\n"
[ ERROR ] 2021-09-04T20:52:00-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: SentinelArrays not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:04-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: LibSSH2_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:07-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: LoweredCodeUtils not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:07-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: JuliaInterpreter not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:10-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: TableOperations not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:10-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: OpenBLAS_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:11-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: GR_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:12-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: PNGFiles not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:13-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: FuzzyCompletions not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:14-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: MeshIO not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-04T20:52:15-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Received new data from Julia Symbol Server.\n"

Does it work after those 2 minutes though? That log looks perfectly normal.

Yes it does. Perfectly though!

Is that the expected behavior? What is going on in the log? Why so many errors?

1 Like

There are only info and warning messages there (although they are printed to stderr, so looks like nvim prepends ERROR).

2 Likes

I’ve also set everything up following @fredrikekre 's instructions and things work without too much effort. But like @Storopoli my LSP takes upwards of 2 min to work at all. I’ve also looked at the logs and get pretty much the same thing. I include a small excerpt below:

[ ERROR ] 2021-09-22T11:53:19-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: LibSSH2_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:53:19-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: MbedTLS_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:53:22-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: LoweredCodeUtils not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:53:37-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: Rmath not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:53:54-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: MKL_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:53:54-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: OpenBLAS_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:54:02-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: XSLT_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:54:45-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: Lz4_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:54:49-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"┌ Warning: ZeroMQ_jll not stored on disc\n└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192\n"
[ ERROR ] 2021-09-22T11:54:57-0500 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"julia"	"stderr"	"[ Info: Received new data from Julia Symbol Server.\n"

The thing is, this happens every time I load a Julia file. It’s not just the first compilation, it takes minutes every single time to start up. I really hope there is a fix for this otherwise I don’t think I can use LSP yet

1 Like

When I run this setup my LS only picks up the packages installed in the language server environment instead of looking for the packages installed in the environment I’m developing in. Is this intentional and is everyone else seeing the same thing?

No, that seems weird. Are you on the latest version of nvim-lspconfig?

I am, but i also recently migrated my nvim configuration to pure Lua script so i could very well have messed something up in my settings. I will continue to dig into it but good to know that it’s working as i hoped. I’ll ping back when i locate the issue. :slightly_smiling_face:

1 Like

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

I’m getting an error when I use your Makefile:

If I comment these lines:

  -- 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
  --     print(julia)
  --     new_config.cmd[1] = julia
  --   end
  -- end,

I don’t get the above error. This is the contents of nvim-lspconfig/bin/julia:

#!/bin/bash
JULIA=/Users/USER/Applications/Julia-nightly.app/Contents/Resources/julia/bin/julia --startup-file=no
if [[ ${JULIA_TRACE_COMPILE} = "1" ]]; then
    exec ${JULIA} --trace-compile=/Users/USER/.julia/environments/nvim-lspconfig/packagecompiler/precompile_statements.jl "$@"
elif [[ -f /Users/USER/.julia/environments/nvim-lspconfig/languageserver.dylib ]]; then
    exec ${JULIA} --sysimage=/Users/USER/.julia/environments/nvim-lspconfig/languageserver.dylib "$@"
else
    exec ${JULIA} "$@"
fi

I had to add the --startup-file=no flag. Any idea what might be going on?

1 Like

Strange. My snippet to replace the julia executable should only swap https://github.com/neovim/nvim-lspconfig/blob/9ca394ec3a9305a6c30018ee6f731c9b23a4b25e/lua/lspconfig/julials.lua#L5 and --startup-file=no should still be there: https://github.com/neovim/nvim-lspconfig/blob/9ca394ec3a9305a6c30018ee6f731c9b23a4b25e/lua/lspconfig/julials.lua#L6

@fredrikekre it seems that your Makefile is not working anymore with Julia 1.7 :cry:
I’m guessing the issue is actually PackageCompiler.jl. I get an error when trying to create the image:

ERROR: failed process: Process(`/opt/julia-1.7.0/bin/julia --color=auto --startup-file=no --cpu-target=native -O3 --sysimage=/opt/julia-1.7.0/lib/julia/sys.so --project=/home/davibarreira/.julia/environments/nvim-lspconfig --output-o=/tmp/jl_w7PlW2.o /tmp/jl_NrvF7t`, ProcessExited(1)) [1]
1 Like

Works perfectly fine for me on both Linux and macOS with Julia 1.7. I made some updates to it (current version is here), but that was only to make it work on macOS, it worked before that change on Linux for me.

Works fine for me as well. I installed LanguageServer#master in the .julia/environments/nvim-lspconfig environment (many features and fixes are missing in the latest release from July) and otherwise followed @fredrikekre’s instructions.

I keep getting this error :frowning:

⠸ [00m:14s] PackageCompiler: compiling incremental system imageSystemError: opening file "/home/davibarreira/.julia/environments/nvim-lspconfig/packagecompiler/precompile_statements.jl": No such file or directory
Stacktrace:
⡆ [00m:14s] PackageCompiler: compiling incremental system imageString, errno::Int32; extrainfo::Nothing)
    @ Base ./error.jl:174
  [2] #systemerror#68
    @ ./error.jl:173 [inlined]
  [3] systemerror
    @ ./error.jl:173 [inlined]
  [4] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Nothing, append::Nothing)
    @ Base ./iostream.jl:293
  [5] open
    @ ./iostream.jl:282 [inlined]
  [6] #eachline#390
    @ ./io.jl:1014 [inlined]
  [7] eachline(filename::String)
    @ Base ./io.jl:1014
  [8] top-level scope
    @ /tmp/jl_GltfQx:73
  [9] eval(m::Module, e::Any)
    @ Core ./boot.jl:373
 [10] top-level scope
    @ /tmp/jl_GltfQx:61
in expression starting at /tmp/jl_GltfQx:61
⠋ [00m:15s] PackageCompiler: compiling incremental system image
ERROR: failed process: Process(`/opt/julia-1.7.0/bin/julia --color=auto --startup-file=no --cpu-target=native -O3 --sysimage=/opt/julia-1.7.0/lib/julia/sys.so --project=/home/davibarreira/.julia/environments/nvim-lspconfig --output-o=/tmp/jl_Lok4MU.o /tmp/jl_GltfQx`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:531 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base ./process.jl:446
 [3] run
   @ ./process.jl:444 [inlined]
 [4] #14
   @ ~/.julia/packages/PackageCompiler/tdgyo/ext/TerminalSpinners.jl:157 [inlined]
 [5] spin(f::PackageCompiler.var"#14#15"{Cmd}, s::PackageCompiler.TerminalSpinners.Spinner{Base.TTY})
   @ PackageCompiler.TerminalSpinners ~/.julia/packages/PackageCompiler/tdgyo/ext/TerminalSpinners.jl:164
 [6] macro expansion
   @ ~/.julia/packages/PackageCompiler/tdgyo/ext/TerminalSpinners.jl:157 [inlined]
 [7] create_sysimg_object_file(object_file::String, packages::Vector{String}, packages_sysimg::Set{Base.PkgId}; project::String, base_sysimage::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, cpu_target::String, script::Nothing, sysimage_build_args::Cmd, extra_precompiles::String)
   @ PackageCompiler ~/.julia/packages/PackageCompiler/tdgyo/src/PackageCompiler.jl:356
 [8] create_sysimage(packages::Symbol; sysimage_path::String, project::String, precompile_execution_file::Vector{String}, precompile_statements_file::String, incremental::Bool, filter_stdlibs::Bool, cpu_target::String, script::Nothing, sysimage_build_args::Cmd, include_transitive_dependencies::Bool, base_sysimage::Nothing, julia_init_c_file::Nothing, version::Nothing, soname::Nothing, compat_level::String, extra_precompiles::String)
   @ PackageCompiler ~/.julia/packages/PackageCompiler/tdgyo/src/PackageCompiler.jl:507
 [9] top-level scope
   @ none:1
make: *** [Makefile:6: languageserver.so] Error 1

@devmotion , the Lsp works, but not the sysimage script in the Makefile. Did you also follow the instructions for creating the image sys?

Yes, I did. I actually followed these instructions, seems unfortunately I copied the wrong link in my comment above.

My julia setup is brand new, since I just changed to 1.7. It had worked before, with my previous version :confused: