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

feat: util:root_pattern() search folder-first up #3651

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdedonno1337
Copy link

@mdedonno1337 mdedonno1337 commented Mar 19, 2025

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

  • you are working in a lua project
  • you have a .stylua.toml configuration file in your home folder (/home/mdedonno1337)
  • you have NOT any .stylua.toml configuration file in the current project
  • you have a .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:

  1. /home/mdedonno1337/lua_project/.stylua.toml
  2. /home/mdedonno1337/.stylua.toml
  3. /home/.stylua.toml
  4. /.stylua.toml
  5. /home/mdedonno1337/lua_project/.git
  6. /home/mdedonno1337/.git
  7. ...

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:

  1. /home/mdedonno1337/lua_project/.stylua.toml
  2. /home/mdedonno1337/lua_project/.git
  3. /home/mdedonno1337/.stylua.toml
  4. /home/mdedonno1337/.git
  5. ...

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

@dundargoc
Copy link
Member

But that was intended though. You can't just revert a change and assume it's fine, you need to do the work of understanding why the change was made in the first place so we know why it's not relevant anymore, or if there is a better solution to the initial problem. If we don't do this then we risk just making changes back and forth without any clear long-term improvement.

I believe this is the PR where this change was made, and that PR references other issues that describe the problem in more detail.

@mdedonno1337
Copy link
Author

👍 I dont get it, but ok.
thanks for your time reading.
please feel free, as mentioned in the first post, to close the PR.
have a nice day!

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.

2 participants