-
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(lua-language-server): update root directory pattern #3322
Conversation
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 |
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.
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 |
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.
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.
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.
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?
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.
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?
needs a rebase since #3330 |
Fixes #3165 by returning the longer root path if both a `.git`- and a `lua`-ancestor are found.
Co-authored-by: glepnir <[email protected]>
That's fine for now. We should really just autogenerate the root_dir docs by copying the literal lua code that assigns |
This change is not incorrect. For luals to work properly with |
Nevermind, this change does make sense, but seems to break for some people. |
Fixed in #3391 |
Fixes #3165 by returning the longer root path if both a
.git
- and alua
-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.