# Neovim Native LSP with julials using PackageCompiled LanguageServer

**URL:** <https://discourse.julialang.org/t/neovim-native-lsp-with-julials-using-packagecompiled-languageserver/57659>\
**Category:** Tooling\
**Tags:** editors\
**Created:** [March 21, 2021, 3:22pm UTC](https://discourse.julialang.org/t/neovim-native-lsp-with-julials-using-packagecompiled-languageserver/57659 "2021-03-21T15:22:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ReneganRonin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/reneganronin/32/21738_2.png) [@ReneganRonin](https://discourse.julialang.org/u/ReneganRonin)\
**Post date:** [March 21, 2021, 3:22pm UTC](https://discourse.julialang.org/t/neovim-native-lsp-with-julials-using-packagecompiled-languageserver/57659/1 "2021-03-21T15:22:20Z")

</div>

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:

```nohighlight
" 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:

```julia
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:

```nohighlight
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](https://github.com/neovim/nvim-lspconfig). 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

---

<div class="post-metadata">

**Author:** ![sapo](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@sapo](https://discourse.julialang.org/u/sapo)\
**Post date:** [June 22, 2021, 7:54am UTC](https://discourse.julialang.org/t/neovim-native-lsp-with-julials-using-packagecompiled-languageserver/57659/2 "2021-06-22T07:54:50Z")

</div>

Hello,  
Thank you for your advice. However, I have no file file `tracecompilelsp.jl` in `LanguageServer` directories…
