From d29be376e64c23d6465ef3fb71aaf4bf4e8e0e68 Mon Sep 17 00:00:00 2001 From: Paul Gideon Dann Date: Tue, 12 Dec 2023 12:00:46 +0000 Subject: fix(elixirls): smarter detection of root_dir for umbrella apps (#2911) --- lua/lspconfig/server_configurations/elixirls.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/server_configurations/elixirls.lua b/lua/lspconfig/server_configurations/elixirls.lua index 62b8e168..3172f6a8 100644 --- a/lua/lspconfig/server_configurations/elixirls.lua +++ b/lua/lspconfig/server_configurations/elixirls.lua @@ -1,11 +1,14 @@ -local util = require 'lspconfig.util' - return { default_config = { filetypes = { 'elixir', 'eelixir', 'heex', 'surface' }, root_dir = function(fname) - return util.root_pattern 'mix.exs'(fname) or util.find_git_ancestor(fname) or vim.loop.os_homedir() + 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) + + return root_dir end, + single_file_support = true, }, docs = { description = [[ @@ -31,9 +34,11 @@ require'lspconfig'.elixirls.setup{ ... } ``` + +'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. ]], default_config = { - root_dir = [[util.find_git_ancestor(fname) or util.root_pattern 'mix.exs'(fname) or vim.loop.os_homedir()]], + root_dir = '{{see description above}}', }, }, } -- cgit v1.2.3-70-g09d2