aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-06-01 12:26:55 +0200
committerGitHub <noreply@github.com>2022-06-01 12:26:55 +0200
commit05517e10fd0e0c0fda184905e9e687bed150f83b (patch)
tree3fabaf2f45042baaaa704e7d50257f9667ae6755 /lua
parentrun autogen_metadata.lua (diff)
downloadmason-05517e10fd0e0c0fda184905e9e687bed150f83b.tar
mason-05517e10fd0e0c0fda184905e9e687bed150f83b.tar.gz
mason-05517e10fd0e0c0fda184905e9e687bed150f83b.tar.bz2
mason-05517e10fd0e0c0fda184905e9e687bed150f83b.tar.lz
mason-05517e10fd0e0c0fda184905e9e687bed150f83b.tar.xz
mason-05517e10fd0e0c0fda184905e9e687bed150f83b.tar.zst
mason-05517e10fd0e0c0fda184905e9e687bed150f83b.zip
fix(julials): improve environment detection and set JULIA_LOAD_PATH (#740)
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/servers/julials/README.md9
-rw-r--r--lua/nvim-lsp-installer/servers/julials/init.lua70
2 files changed, 59 insertions, 20 deletions
diff --git a/lua/nvim-lsp-installer/servers/julials/README.md b/lua/nvim-lsp-installer/servers/julials/README.md
new file mode 100644
index 00000000..18e6880d
--- /dev/null
+++ b/lua/nvim-lsp-installer/servers/julials/README.md
@@ -0,0 +1,9 @@
+# julials
+
+## Configuring the Julia Environment
+
+The Julia Environment will be identified in the following order:
+
+1) user configuration (`lspconfig.julials.setup { julia_env_path = "/my/env" }`)
+2) if the `Project.toml` & `Manifest.toml` (or `JuliaProject.toml` & `JuliaManifest.toml`) files exists in the current project working directory, the current project working directory is used as the environment
+3) the result of `Pkg.Types.Context().env.project_file`
diff --git a/lua/nvim-lsp-installer/servers/julials/init.lua b/lua/nvim-lsp-installer/servers/julials/init.lua
index 2e5cc0bd..85f59303 100644
--- a/lua/nvim-lsp-installer/servers/julials/init.lua
+++ b/lua/nvim-lsp-installer/servers/julials/init.lua
@@ -2,23 +2,26 @@ local server = require "nvim-lsp-installer.server"
local path = require "nvim-lsp-installer.core.path"
local std = require "nvim-lsp-installer.core.managers.std"
local github = require "nvim-lsp-installer.core.managers.github"
+local platform = require "nvim-lsp-installer.core.platform"
+local fs = require "nvim-lsp-installer.core.fs"
+local _ = require "nvim-lsp-installer.core.functional"
return function(name, root_dir)
local server_script = [[
-using LanguageServer, SymbolServer
-
-maybe_dirname = x -> x !== nothing ? dirname(x) : nothing
+using LanguageServer, SymbolServer, Pkg
OLD_DEPOT_PATH = ARGS[1]
SYMBOLSTORE_PATH = ARGS[2]
+ENV_PATH = ARGS[3]
-runserver(stdin,
- stdout,
- something(maybe_dirname(Base.current_project(pwd())),
- maybe_dirname(Base.load_path_expand("@v#.#"))),
- OLD_DEPOT_PATH,
- nothing,
- SYMBOLSTORE_PATH)
+runserver(
+ stdin,
+ stdout,
+ ENV_PATH,
+ OLD_DEPOT_PATH,
+ nothing,
+ SYMBOLSTORE_PATH
+)
]]
return server.Server:new {
@@ -54,18 +57,45 @@ runserver(stdin,
ctx.fs:write_file("nvim-lsp.jl", server_script)
end,
default_options = {
- cmd = {
- "julia",
- "--startup-file=no",
- "--history-file=no",
- "--depwarn=no",
- ("--project=%s"):format(path.concat { root_dir, "scripts", "environments", "languageserver" }),
- path.concat { root_dir, "nvim-lsp.jl" },
- vim.env.JULIA_DEPOT_PATH or "",
- path.concat { root_dir, "symbolstorev5" },
- },
+ on_new_config = function(config, new_root_dir)
+ local env_path = config.julia_env_path and vim.fn.expand(config.julia_env_path)
+ if not env_path then
+ local file_exists = _.compose(fs.sync.file_exists, path.concat, _.concat { new_root_dir })
+ if file_exists { "Project.toml" } and file_exists { "Manifest.toml" } then
+ env_path = new_root_dir
+ elseif file_exists { "JuliaProject.toml" } and file_exists { "JuliaManifest.toml" } then
+ env_path = new_root_dir
+ end
+ end
+
+ if not env_path then
+ local ok, env = pcall(vim.fn.system, {
+ "julia",
+ "--startup-file=no",
+ "--history-file=no",
+ "-e",
+ "using Pkg; print(dirname(Pkg.Types.Context().env.project_file))",
+ })
+ if ok then
+ env_path = env
+ end
+ end
+
+ config.cmd = {
+ "julia",
+ "--startup-file=no",
+ "--history-file=no",
+ "--depwarn=no",
+ ("--project=%s"):format(path.concat { root_dir, "scripts", "environments", "languageserver" }),
+ path.concat { root_dir, "nvim-lsp.jl" },
+ vim.env.JULIA_DEPOT_PATH or "",
+ path.concat { root_dir, "symbolstorev5" },
+ env_path,
+ }
+ end,
cmd_env = {
JULIA_DEPOT_PATH = path.concat { root_dir, "lsdepot" },
+ JULIA_LOAD_PATH = platform.is.win and ";" or ":",
},
},
}