-
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): root_dir priority: mix.exs > .git #2910
Conversation
If we're in a subdirectory of a git repo, and that subdirectory contains a mix.exs file, it makes sense to assume the subdirectory is the project root, rather than the git repo root.
Oops the |
If we revert, the server will fail to start at all for Mix projects in subdirectories of a git repo. That's the problem I wanted to solve. So how about this: look for a Even better would be to look for the closest Taking this further - why stop at a git repo boundary? Could it be sensible to simply look for the highest ancestor directory containing a |
The best way to detect this scenario would be something like: given an fname, we could traverse upwards to detect the first mix.exs and then check if there's another mix.exs 2 dirs above the first mix.exs. Not sure if this is a good approach for lspconfig, tough. Checking for the .git dir seems to me like a "good enough" approximation. |
Hmmm, I understood it now! It seems like a good compromise. That can work, however, I still think that the previous config was already working in all those scenarios we discussed. |
Here is my test directory structure:
Here is the LSP output:
Maybe you define |
Nope. My config is a pretty standard LazyVim config (https://github.com/georgeguimaraes/nvim-config) and as far as I know LazyVim doesn't change that. It seems that this particular warning you got was removed: Maybe you're running an old elixirls? |
I don't think so: https://github.com/elixir-lsp/elixir-ls/blob/master/apps/language_server/lib/language_server/server.ex#L1414 I'm on |
Hmm, then I can only guess that your debug level is different from mine. But regardless, I've tested again my config with the subdir. Elixirls here is running without a mix.exs, and that doesn't seem reasonable. So I think your way of detecting a mix.exs in the same dir as .git and then fallbacking to find mix.exs in the ancestors dirs is now the best compromise between umbrella, single app and subdir single app. |
That looks interesting. It certainly feels better to me to not assume anything about version control (git repo or not). I'm not sure about |
limit = 2 means that when the first 2 mix.exs are found, the search halts. So I guess that's already a sanity limit builtin, even for a deeply nested fname. and since it's using upwards, it will never detect a mix.exs from "another" directory like another subdir app or a child umbrella app that is not the one we're in. |
Ah! Sorry, I had rushed reading the function docs, and thought it was a limit on the search depth. But as a limit for number of results it makes total sense. And is actually a really nice solution 👍 |
@giddie not sure the best way to get that into the nice root_dir option from lspconfig. I won't have the time today to hack it. Do you see a way? Can you try it? |
PR is up: #2911 |
If we're in a subdirectory of a git repo, and that subdirectory contains a mix.exs file, it makes sense to assume the subdirectory is the project root, rather than the git repo root.