feat: util:root_pattern() search folder-first up #3651
+4
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
Edit:
Was making this PR based upon the code in master. I've seen all the discussions after.
Seems to work for me.
Feel free to close/reject if this does not make sense to you.
Thanks
This PR simplify and use the function provided by neovim to find a (set of) file(s) to find the root of the project, and solves the following bug:
Let assume the following (as an example, works with any project):
.stylua.toml
configuration file in your home folder (/home/mdedonno1337
).stylua.toml
configuration file in the current project.git
folder in your project (/home/mdedonno1337/lua_project/.git/
)The
root_pattern()
function will use the patterns to search for.stylua.toml
file first, folder up first, then, if not found, search for.git
folder, folder up first:This will wrongly find the file 2. first, and not the folder 5. as I would expect.
This patch uses the
vim.fs.find()
function, which will search pattern-first as follow:This will ensure that the folder matching the searched pattern will hit with the closest folder relative to the current file (i.e the smallest folder project).