new: nvim: add julials sysimage gen scripts for faster startup

This commit is contained in:
qwjyh 2023-10-06 17:56:04 +09:00
parent 56b6f49a40
commit a4f74fc80a
4 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,15 @@
# Add dependencies to Language Server project
# TODO: automatically list up necessary packages
using Pkg
# add LanguageServer.jl
Pkg.add("LanguageServer")
# add dependencies of LanguageServer.jl
pkg_ls = Pkg.project().dependencies["LanguageServer"]
pkg_ls_deps = Pkg.dependencies()[pkg_ls].dependencies |> keys
foreach(Pkg.add, pkg_ls_deps)
# add extra dependencies
foreach(Pkg.add, ["Logging", "Sockets", "DataStructures"]) # these packages are manually collected

View file

@ -464,6 +464,45 @@ lspconfig.lua_ls.setup {
lspconfig.julials.setup { lspconfig.julials.setup {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
cmd = { "julia", "--startup-file=no", "--history-file=no", "-J",
os.getenv("HOME") .. "/.julia/environments/nvim-lspconfig/sys-ls.so",
-- use below 2 lines to collect script to be included in sysimage
'--trace-compile',
os.getenv("HOME") .. "/.julia/environments/nvim-lspconfig/tracecompile.jl",
"-e",
[[
# Load LanguageServer.jl: attempt to load from ~/.julia/environments/nvim-lspconfig
# with the regular load path as a fallback
ls_install_path = joinpath(
get(DEPOT_PATH, 1, joinpath(homedir(), ".julia")),
"environments", "nvim-lspconfig"
)
pushfirst!(LOAD_PATH, ls_install_path)
using LanguageServer
popfirst!(LOAD_PATH)
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
project_path = let
dirname(something(
## 1. Finds an explicitly set project (JULIA_PROJECT)
Base.load_path_expand((
p = get(ENV, "JULIA_PROJECT", nothing);
p === nothing ? nothing : isempty(p) ? nothing : p
)),
## 2. Look for a Project.toml file in the current working directory,
## or parent directories, with $HOME as an upper boundary
Base.current_project(),
## 3. First entry in the load path
get(Base.load_path(), 1, nothing),
## 4. Fallback to default global environment,
## this is more or less unreachable
Base.load_path_expand("@v#.#"),
))
end
@info "Running language server" VERSION pwd() project_path depot_path
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path)
server.runlinter = true
run(server)
]] }
} }
-- SATySFi -- SATySFi
lspconfig.satysfi_ls.setup { lspconfig.satysfi_ls.setup {
@ -575,4 +614,3 @@ cmp.setup.cmdline(':', {
} }
}) })
}) })

View file

@ -0,0 +1,2 @@
#!/usr/bin/bash -x
julia --project=~/.julia/environments/nvim-lspconfig ./add_dependencies.jl

View file

@ -0,0 +1,7 @@
#!/usr/bin/bash -x
cd ~/.julia/environments/nvim-lspconfig/ || return 1
julia --project=. -e 'using Pkg; Pkg.update()'
cat precompile_exec_head.jl tracecompile.jl > precompile_exec.jl
julia --project=. -e 'using PackageCompiler; create_sysimage(["LanguageServer"], sysimage_path="sys-ls.so", precompile_execution_file=["precompile_exec.jl"])'
julia --project=. -J sys-ls.so -e 'using Pkg; Pkg.precompile()'