Skip to content

Commit

Permalink
fix(elixirls): smarter detection of root_dir for umbrella apps
Browse files Browse the repository at this point in the history
  • Loading branch information
giddie committed Dec 11, 2023
1 parent 553c4e0 commit 99063b7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lua/lspconfig/server_configurations/elixirls.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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,
},
docs = {
Expand All @@ -31,9 +33,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}}',
},
},
}

0 comments on commit 99063b7

Please sign in to comment.