Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elixirls): smarter detection of root_dir for umbrella apps #2911

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lua/lspconfig/server_configurations/elixirls.lua
Original file line number Diff line number Diff line change
@@ -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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this works?

local root_dir = util.root_pattern 'mix.exs'(maybe_umbrella_path) or util.root_pattern 'mix.exs'(child_or_root_path)

a bit redundant, but this way we're not using dirname and instead rely on the utils from lspconfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main issue is that I don't understand what the constraints are here. Why can't we use dirname? Does this mean we can't use vim.fs.find either? Can @glepnir offer any guidance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder this not work ?

  local result = vim.fs.find ('mix.exs', {upward = true, limit = math.huge, path = fname})
  return #result > 0 and result[#reuslt] or uv.cwd()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we need to return a directory path, right? Hence the use of dirname. Again, for me the question is really what functions we can and can't use, and why? What is different about this "single file mode"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no different. when single file mode enable it will use current dir as root.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just set single_file_mode = true and remove cwd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, where should I be setting this? A search in nvim-lspconfig reveals zero instances of single_file_mode, so I'm all out of clues.

BTW, the code in this PR works just fine for me. As far as I'm concerned, and unless I can understand the constraints better, the problem seems to be the CI...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion below led me to find lspconfig-single-file-support in the lspconfig help. IIUC, the idea here is that if root_dir returns nil, and single_file_support is on, then this mode will be used?

I don't really get how this helps with the issue of dirname being rejected by the CI, though 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup dirname ci can ignore just fix lint .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK; great. Then I think we're good to go 🥳

return root_dir
end,
single_file_support = true,
},
docs = {
description = [[
Expand All @@ -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}}',
},
},
}
Loading