From 6ab566968c183f767f8d0fc3dc82d86d6250a49e Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Thu, 7 Aug 2025 09:15:21 +0200 Subject: [PATCH] feat: add LSP for Elixir --- lsp/elixir.lua | 22 ++++++++++++++++++++++ lua/weeheavy/prefs.lua | 1 + 2 files changed, 23 insertions(+) create mode 100644 lsp/elixir.lua diff --git a/lsp/elixir.lua b/lsp/elixir.lua new file mode 100644 index 0000000..0ad17c4 --- /dev/null +++ b/lsp/elixir.lua @@ -0,0 +1,22 @@ +---@type vim.lsp.Config +--- 'root_dir' is chosen like this: +--- if two or more directories containing `mix.exs` were found when searching +--- directories upward, the second one (higher up) is chosen, with the +--- assumption that it is the root of an umbrella app. Otherwise the directory +--- containing the single mix.exs that was found is chosen. +return { + -- cmd when installing with Mason + -- Had to install elixir and asdf (homebrew) + -- Then ran `mix local.hex` to upgrade Hex + cmd = { vim.env.HOME .. "/.local/share/nvim/mason/packages/elixir-ls/language_server.sh" }, + -- cmd = { "/Users/oliver.ladner/.local/share/nvim/mason/packages/elixir-ls/language_server.sh" }, + filetypes = { "elixir", "eelixir", "heex", "surface" }, + root_dir = function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + local matches = vim.fs.find({ "mix.exs" }, { upward = true, limit = 2, path = fname }) + local child_or_root_path, maybe_umbrella_path = unpack(matches) + local root_dir = vim.fs.dirname(maybe_umbrella_path or child_or_root_path) + + on_dir(root_dir) + end, +} diff --git a/lua/weeheavy/prefs.lua b/lua/weeheavy/prefs.lua index 09f8651..dcb5caa 100644 --- a/lua/weeheavy/prefs.lua +++ b/lua/weeheavy/prefs.lua @@ -13,6 +13,7 @@ vim.lsp.enable({ "bicep", "proselint", "python", + "elixir", }) -- Set highlight on search