-
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: util.root_pattern prioritises pattern order #2885
fix: util.root_pattern prioritises pattern order #2885
Conversation
or util.root_pattern '*.csproj'(startpath) | ||
or util.root_pattern '*.fsproj'(startpath) | ||
or util.root_pattern '.git'(startpath) | ||
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.
why can't the fix be done in util.root_pattern
instead of special-cased for csharp?
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.
Yeah there's no reason why not. I agree that having the special case is weird. Will put something together and we can take a look.
d5c1af3
to
9284887
Compare
@justinmk would you mind taking another look? I've updated Previously, the function did this:
I have switched the two loops around so that it now does the following:
There is a slight performance hit because instead of traversing parent directories once, it now traverses parent directories On the plus side though this resolves the issue not only for |
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.
Thanks for the clear explanation!
- should mention "in order" in the doc for root_pattern
nvim-lspconfig/doc/lspconfig.txt
Lines 371 to 374 in 0a0682d
- `util.root_pattern`: function which takes multiple arguments, each corresponding to a different root pattern against which the contents of the current directory are matched using |vim.fn.glob()| while traversing up the filesystem. - @glepnir any objections? this might accidentally change behavior of existing configs, but they can be updated.
After this change if a config has root_pattern {'package.json', '.git'}
then parents are traversed until package.json
is found, a random .git
won't incorrectly define the workspace. If someone wants .git
to be higher precedence, then the root_pattern should be changed to {'.git', 'package.json'}
otoh , does make it impossible to define root markers with "equal precedence"? e.g. nvim-lspconfig/lua/lspconfig/server_configurations/tsserver.lua Lines 15 to 18 in 90a28fd
is that important? |
79c6486
to
ed1659a
Compare
Force pushed to update spelling of "prioritises" in commit message, and updated
Yes it does.
Not sure. Struggling to think of a situation where equal precedence would be desirable/useful. Case A
Case B
Case C
In case A, precedence doesn't matter, any order of markers will identify the same root directory. The only situation where equal precedence would be useful is if you always wanted to identify |
ed1659a
to
cb3d3ca
Compare
if M.path.exists(p) then | ||
return path | ||
local match = M.search_ancestors(startpath, function(path) | ||
for _, p in ipairs(vim.fn.glob(M.path.join(M.path.escape_wildcards(path), pattern), true, true)) do |
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.
it's better use vim.fs module
thought after 0.10 we can use |
Did CI complain about that? 😆
We can save the Since we have carefully considered the implications and the behavior of this PR seems to match user intention, I think we should go ahead and try this. In a followup PR we should cleanup the existing configs since the |
nope. ci has been fixed on master. just need rebase :) |
Instead of traversing the filesystem upwards once and returning the first match of all the patterns, it traverses the filesystem upwards once for each pattern. This means that the order of the patterns provided matters, and the highest priority patterns should be put first. Also updated corresponding tests.
cb3d3ca
to
36e754a
Compare
36e754a
to
cc25ceb
Compare
lol no it was just bothering me 😝
Rebased master and CI is passing now. |
Because of the way
util.root_dir
is defined,.csproj
files are found before.sln
files and the incorrect root directory is set. This prevents go-to-definition between multiple projects in a single solution and causes a few other issues. See #2612 for a more in-depth explanation.This updates the default configuration to avoid this footgun.
EDIT:
The changes now cover the above issue, but does so in a more general way by updating the
util.root_pattern
function.closes #2612
related to razzmatazz/csharp-language-server#57