From c7a145f6ae50389caf1a9a72aa22cf98e7945f66 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Mon, 23 Sep 2024 12:29:06 -0400 Subject: [PATCH] feat(julials): add `JuliaActivateEnv` to activate a julia environment --- .../server_configurations/julials.lua | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lua/lspconfig/server_configurations/julials.lua b/lua/lspconfig/server_configurations/julials.lua index 44360c71ac..16384e2001 100644 --- a/lua/lspconfig/server_configurations/julials.lua +++ b/lua/lspconfig/server_configurations/julials.lua @@ -1,5 +1,34 @@ local util = require 'lspconfig.util' +local function activate_env() + local bufnr = vim.api.nvim_get_current_buf() + local julials_client = util.get_active_client_by_name(bufnr, 'julials') + if julials_client then + local julia_project_files = { 'Project.toml', 'JuliaProject.toml' } + local depot_envs = vim.fs.normalize(vim.env.JULIA_DEPOT_PATH or vim.fn.expand '~/.julia') .. '/environments' + local environments = {} + vim.list_extend(environments, vim.fs.find(julia_project_files, { type = 'file', upward = true, limit = math.huge })) + vim.list_extend( + environments, + vim.fs.find(function(name, path) + return vim.tbl_contains(julia_project_files, name) and string.sub(path, #depot_envs + 1):match '^/[^/]*$' + end, { path = depot_envs, type = 'file', limit = math.huge }) + ) + environments = vim.tbl_map(util.path.dirname, environments) + vim.ui.select(environments, { prompt = 'Select a Julia environment' }, function(environment) + if environment then + julials_client.notify('julia/activateenvironment', { envPath = environment }) + vim.notify('Julia environment activated: \n`' .. environment .. '`', vim.log.levels.INFO) + end + end) + else + vim.notify( + 'method julia/activateenvironment is not supported by any servers active on the current buffer', + vim.log.levels.WARN + ) + end +end + local cmd = { 'julia', '--startup-file=no', @@ -49,6 +78,14 @@ return { end, single_file_support = true, }, + commands = { + JuliaActivateEnv = { + function() + activate_env() + end, + description = 'Activate a Julia environment', + }, + }, docs = { description = [[ https://github.com/julia-vscode/julia-vscode