From a4f74fc80a67e27f9eac75a5e4f314c290e3704c Mon Sep 17 00:00:00 2001 From: qwjyh Date: Fri, 6 Oct 2023 17:56:04 +0900 Subject: [PATCH] new: nvim: add julials sysimage gen scripts for faster startup --- dotfiles/neovim/add_dependencies.jl | 15 +++++++++++ dotfiles/neovim/init.lua | 40 ++++++++++++++++++++++++++++- dotfiles/neovim/setup_julials.sh | 2 ++ dotfiles/neovim/update_julials.sh | 7 +++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 dotfiles/neovim/add_dependencies.jl create mode 100755 dotfiles/neovim/setup_julials.sh create mode 100755 dotfiles/neovim/update_julials.sh diff --git a/dotfiles/neovim/add_dependencies.jl b/dotfiles/neovim/add_dependencies.jl new file mode 100644 index 0000000..14b9fd4 --- /dev/null +++ b/dotfiles/neovim/add_dependencies.jl @@ -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 + diff --git a/dotfiles/neovim/init.lua b/dotfiles/neovim/init.lua index 22e44e5..949b4a5 100644 --- a/dotfiles/neovim/init.lua +++ b/dotfiles/neovim/init.lua @@ -464,6 +464,45 @@ lspconfig.lua_ls.setup { lspconfig.julials.setup { on_attach = on_attach, 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 lspconfig.satysfi_ls.setup { @@ -575,4 +614,3 @@ cmp.setup.cmdline(':', { } }) }) - diff --git a/dotfiles/neovim/setup_julials.sh b/dotfiles/neovim/setup_julials.sh new file mode 100755 index 0000000..f1aa150 --- /dev/null +++ b/dotfiles/neovim/setup_julials.sh @@ -0,0 +1,2 @@ +#!/usr/bin/bash -x +julia --project=~/.julia/environments/nvim-lspconfig ./add_dependencies.jl diff --git a/dotfiles/neovim/update_julials.sh b/dotfiles/neovim/update_julials.sh new file mode 100755 index 0000000..8dd5a78 --- /dev/null +++ b/dotfiles/neovim/update_julials.sh @@ -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()' +