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

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

merged 1 commit into from
Dec 12, 2023

Conversation

giddie
Copy link
Contributor

@giddie giddie commented Nov 22, 2023

Should fix issues identified following merge of #2910

@giddie
Copy link
Contributor Author

giddie commented Nov 22, 2023

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?

Copy link
Contributor

@georgeguimaraes georgeguimaraes left a 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
Copy link
Contributor

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)
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 🥳

@georgeguimaraes
Copy link
Contributor

@glepnir Did you have a chance to review this? We'd appreciate your guidance here.

Comment on lines 16 to 12
end,
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
end,
},
end,
single_file_support = true,
},

Copy link
Member

Choose a reason for hiding this comment

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

emm you forget here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@glepnir glepnir merged commit d29be37 into neovim:master Dec 12, 2023
8 of 9 checks passed
@georgeguimaraes
Copy link
Contributor

Great work everyone!

@towry
Copy link

towry commented Aug 21, 2024

It seems now elixir_ls will read .vscode's settings.

-- project_root (dir contains elixir and python projects)
  - .vscode/settings.json
  - app_stack_ex # (umbrella project)
  -- apps
  ---- sub_app/mix.exs
  -- mix.exs

If I have config in .vscode/settings.json:

{
  "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: app_stack_ex/app_stack_ex project not exists.

Solution

The solution is to add another .vscode/settings to the app_stack_ex folder, with projectDir set to .. Now it works for both vscode and elixirls in neovim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants