-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
OK, the CI informs me I've broken some rules. I can see in CONTRIBUTING that I shouldn't be using these functions. Is this something to do with "single file mode" passing different input to this function, so it needs to be handled differently? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An idea to circumvent the dirname restriction:
@@ -4,7 +4,15 @@ 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() | |||
if not fname or fname == "" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need this check at all since we can trust there's a fname coming in.
|
||
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...?
There was a problem hiding this comment.
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 😕
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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 🥳
@glepnir Did you have a chance to review this? We'd appreciate your guidance here. |
end, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
end, | |
}, | |
end, | |
single_file_support = true, | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm you forget here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
Great work everyone! |
It seems now elixir_ls will read .vscode's settings.
If I have config in {
"elixirLS.projectDir": "app_stack_ex"
} It works for vscode and vscode elixir extension, but not work for elixir in neovim, because elixirls in neovim will try to append this value to the umbrella project path, will give error like: SolutionThe solution is to add another |
Should fix issues identified following merge of #2910