Skip to content

Commit

Permalink
feat(julials): add JuliaActivateEnv to activate a julia environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Sep 24, 2024
1 parent dd32991 commit 5966b7f
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lua/lspconfig/server_configurations/julials.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
local util = require 'lspconfig.util'

local function activate_env(path)
local bufnr = vim.api.nvim_get_current_buf()
local julials_clients = util.get_lsp_clients { bufnr = bufnr, name = 'julials' }
if #julials_clients == 0 then
vim.notify(
'method julia/activateenvironment is not supported by any servers active on the current buffer',
vim.log.levels.WARN
)
return
end
local julia_project_files = { 'Project.toml', 'JuliaProject.toml' }
local function _activate_env(environment)
if environment then
for _, julials_client in ipairs(julials_clients) do
julials_client.notify('julia/activateenvironment', { envPath = environment })
end
vim.notify('Julia environment activated: \n`' .. environment .. '`', vim.log.levels.INFO)
end
end
if path then
path = vim.fs.normalize(path)
local found_env = false
for _, project_file in ipairs(julia_project_files) do
if util.path.exists(util.path.join(path, project_file)) then
found_env = true
break
end
end
if not found_env then
vim.notify('Path is not a julia environment: \n`' .. path .. '`', vim.log.levels.WARN)
return
end
_activate_env(path)
else
local depot_paths = vim.env.JULIA_DEPOT_PATH and vim.split(vim.env.JULIA_DEPOT_PATH, ':')
or { vim.fn.expand '~/.julia' }
local environments = {}
vim.list_extend(environments, vim.fs.find(julia_project_files, { type = 'file', upward = true, limit = math.huge }))
for _, depot_path in ipairs(depot_paths) do
local depot_env = util.path.join(vim.fs.normalize(depot_path), 'environments')
vim.list_extend(
environments,
vim.fs.find(function(name, env_path)
return vim.tbl_contains(julia_project_files, name) and string.sub(env_path, #depot_env + 1):match '^/[^/]*$'
end, { path = depot_env, type = 'file', limit = math.huge })
)
end
environments = vim.tbl_map(util.path.dirname, environments)
vim.ui.select(environments, { prompt = 'Select a Julia environment' }, _activate_env)
end
end

local cmd = {
'julia',
'--startup-file=no',
Expand Down Expand Up @@ -49,6 +101,14 @@ return {
end,
single_file_support = true,
},
commands = {
JuliaActivateEnv = {
activate_env,
description = 'Activate a Julia environment',
nargs = '?',
complete = 'file',
},
},
docs = {
description = [[
https://github.com/julia-vscode/julia-vscode
Expand All @@ -70,6 +130,9 @@ Julia project, you must make sure that the project is instantiated:
```sh
julia --project=/path/to/my/project -e 'using Pkg; Pkg.instantiate()'
```
Note: The julia programming language searches for global environments within the `environments/`
folder of `$JULIA_DEPOT_PATH` entries. By default this simply `~/.julia/environments`
]],
},
}

0 comments on commit 5966b7f

Please sign in to comment.