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(lua-language-server): update root directory pattern #3322

Merged
merged 2 commits into from
Oct 1, 2024
Merged

fix(lua-language-server): update root directory pattern #3322

merged 2 commits into from
Oct 1, 2024

Conversation

pitkling
Copy link
Contributor

Fixes #3165 by returning the longer root path if both a .git- and a lua-ancestor are found (as suggested by @powerman).

I also removed the documentation of the default root_dir pattern (assuming that now it will reference the source code, as in many other server configurations), since the root pattern calculation is more involved than the documentation indicated.

@pitkling pitkling requested a review from glepnir as a code owner September 28, 2024 07:27
Comment on lines 22 to 28
local root_lua = util.root_pattern 'lua/'(fname)
local root_git = util.find_git_ancestor(fname)
if string.len(root_lua or '') >= string.len(root_git or '') then
return root_lua
else
return root_git
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
local root_lua = util.root_pattern 'lua/'(fname)
local root_git = util.find_git_ancestor(fname)
if string.len(root_lua or '') >= string.len(root_git or '') then
return root_lua
else
return root_git
end
local root_lua = util.root_pattern 'lua/'(fname) or ''
local root_git = util.find_git_ancestor(fname) or ''
return #root_lua >= #root_git and root_lua or root_git

Copy link
Contributor Author

Choose a reason for hiding this comment

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

P.S.: The failing check seems to be because of the commit message format. I'll squash the second commit when there's nothing else I should change.

Copy link
Member

Choose a reason for hiding this comment

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

Is there any use for the length check here? This should be a fallback priority issue. Shouldn't root_git continue to search only when root_lua fails to find it?

Copy link
Contributor Author

@pitkling pitkling Sep 28, 2024

Choose a reason for hiding this comment

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

To be honest, not sure. That's why I opened #3165 a while back to ask this. If root_git is only used if root_lua fails (which was the case before), the directory structure I outlined in #3165 detects the (in my case at least) wrong root directory. As I mentioned there, the directory layout I use and that causes the problem seems not that uncommon. But then I'm only developing in Lua occasionally, so maybe that is okay and intended.

Anyway, in case this change is ok, one question concerning your suggested code change: This would now return the empty string instead of nil if neither a lua nor git ancestor is detected. Is that consistent with what root_dir is supposed to return?

@justinmk
Copy link
Member

justinmk commented Oct 1, 2024

needs a rebase since #3330

pitkling and others added 2 commits October 1, 2024 16:06
Fixes #3165 by returning the longer root path if both a `.git`- and a `lua`-ancestor are found.
@pitkling
Copy link
Contributor Author

pitkling commented Oct 1, 2024

needs a rebase since #3330

@justinmk: Done, thanks for the heads up!

@justinmk
Copy link
Member

justinmk commented Oct 1, 2024

I also removed the documentation of the default root_dir pattern

That's fine for now. We should really just autogenerate the root_dir docs by copying the literal lua code that assigns root_dir, directly into the docs. Tracked in #2011 if anyone wants to help with that :)

@justinmk justinmk merged commit 814f02e into neovim:master Oct 1, 2024
7 of 8 checks passed
@folke
Copy link
Member

folke commented Oct 22, 2024

This change is not incorrect. For luals to work properly with lua/* its root directory should be the parent of the lua directory.

@folke
Copy link
Member

folke commented Oct 22, 2024

Nevermind, this change does make sense, but seems to break for some people.
See folke/lazydev.nvim#70

@folke
Copy link
Member

folke commented Oct 22, 2024

Fixed in #3391

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.

possibly unintuitive lua_ls root_dir detection logic
4 participants