Neovim Native LSP with julials using PackageCompiled LanguageServer

ReneganRonin
Sun, 21 Mar 2021 15:22:20 +0000
Tooling

I have successfully used a custom sysimage for LanguageServer for julials for neovim native lsp. The first thing I did is to create a precompilation statements file before I created the sysimage. Here is the following lsp config inside my init.vim for neovim to record the precompilation statements:

" LSP
lua << EOF
require'lspconfig'.rust_analyzer.setup({on_attach=require'completion'.on_attach})
require'lspconfig'.julials.setup({
      on_new_config = function(new_config,new_root_dir)
      server_path = "/home/tricks/.julia/packages/LanguageServer/y1ebo/src/"
      cmd = {
        "julia",
        "--project="..server_path,
        "--startup-file=no",
        "--history-file=no",
        "--trace-compile=/home/tricks/JuliaLS/tracecompilelsp.jl",
        "-e", [[
          using Pkg;
          Pkg.instantiate()
          using LanguageServer; using SymbolServer;
          depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
          project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))
          # Make sure that we only load packages from this environment specifically.
          @info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path
          server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
          server.runlinter = true;
          run(server);
        ]]
    };
    new_config.cmd = cmd
    on_attach=require'completion'.on_attach
    end
})
require('lspsaga.codeaction').code_action()
require('lspsaga.codeaction').range_code_action()
EOF

I waited for the julials client to run and then solved a bit of exercises from exercism and use some of the lsp’s functionality such as inline diagnostics and previewing definitions. I saved and exit neovim then started to create a sysimage as follows inside the JuliaREPL:

using PackageCompiler; create_sysimage([:LanguageServer,:SymbolServer], sysimage_path="./julials.so", precompile_statements_file="./tracecompilelsp.jl")

After it successfully created the sysimage, here is the new lsp config:

lua << EOF
require'lspconfig'.rust_analyzer.setup({on_attach=require'completion'.on_attach})
require'lspconfig'.julials.setup({
      on_new_config = function(new_config,new_root_dir)
      server_path = "/home/tricks/.julia/packages/LanguageServer/y1ebo/src/"
      cmd = {
        "julia",
        "--project="..server_path,
        "--startup-file=no",
        "--history-file=no",
        "--sysimage=/home/tricks/JuliaLS/julials.so",
        "--sysimage-native-code=yes",
        "-e", [[
          using Pkg;
          Pkg.instantiate()
          using LanguageServer; using SymbolServer;
          depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
          project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))
          # Make sure that we only load packages from this environment specifically.
          @info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path
          server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
          server.runlinter = true;
          run(server);
        ]]
    };
    new_config.cmd = cmd
    on_attach=require'completion'.on_attach
    end
})
require('lspsaga.codeaction').code_action()
require('lspsaga.codeaction').range_code_action()
EOF

Now julials can start from 3-5 minutes to the new 10-30 seconds (sometimes almost instantaneously). EDIT: the plugin i use for the lsp is from GitHub - neovim/nvim-lspconfig: Quickstart configs for Nvim LSP. If you wonder what the spec of my computer is, it is an ASUS X450MD which only has 4GB of RAM, Quad Core Intel Pentium N3530 and a very sad GPU Nvidia GeForce 820M

2 posts - 2 participants