Skip to content

fix(file-nesting): ensure deterministic rule application #1602

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

Merged
merged 9 commits into from
Feb 12, 2025

Conversation

saifulapm
Copy link
Contributor

When multiple file nesting rules were configured, rules were being applied inconsistently. For example, sometimes when both package.json and vite.config.* rules existed, only one set of rules would be applied while the other would be ignored intermittently.

Example configuration that was working inconsistently:

{
  nesting_rules = require('neotree-file-nesting-config').nesting_rules,
}

The fix modifies the nesting logic to:

  • Collect all matching rules before applying any nesting
  • Use file IDs to prevent duplicate nesting
  • Track nested status properly
  • Apply rules in a deterministic order

This ensures that all configured nesting rules are applied consistently regardless of their order or complexity.

Fixes #1494

…rules (nvim-neo-tree#1494)

When multiple file nesting rules were configured, rules were being applied
inconsistently. For example, sometimes when both `package.json` and
`vite.config.*` rules existed, only one set of rules would be applied
while the other would be ignored intermittently.

Example configuration that was working inconsistently:
```lua
{
  ['vite.config.*'] = {
    files = { '%.babelrc*', 'babel%.config%.*', 'postcss%.config%.*',
              'tailwind%.config%.*', '%.env%.*', 'tsconfig%.*' },
    pattern = 'vite%.config%.(.*)$'
  },
  ['package.json'] = {
    files = { '%.browserslist*', 'bower%.json', 'package-lock%.json',
              'yarn%.lock', '%.eslint*', '%.prettier*' },
    pattern = 'package%.json$'
  }
}
```

The fix modifies the nesting logic to:
- Collect all matching rules before applying any nesting
- Use file IDs to prevent duplicate nesting
- Track nested status properly
- Apply rules in a deterministic order

This ensures that all configured nesting rules are applied consistently
regardless of their order or complexity.

Fixes nvim-neo-tree#1494
@cseickel
Copy link
Contributor

It sounds like a good solution, but I'm afraid I don't have the time to properly evaluate it. See #1606.

@pynappo
Copy link
Collaborator

pynappo commented Jan 20, 2025

Made the rule application actually deterministic. Rules now have an optional priority field that works similarly to lazy.nvim's and defaults to 100, where higher priority rules are applied first. if priorities are equal, rules are applied in order of the keys (that is, alphabetically ascending order).

lmk if you could try it out and make sure it works and i'll merge.

@pynappo pynappo changed the title fix(file-nesting): ensure consistent application of multiple nesting fix(file-nesting): ensure deterministic rule application Feb 12, 2025
@pynappo pynappo merged commit e96fd85 into nvim-neo-tree:main Feb 12, 2025
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.

BUG: File Nesting sometimes not working.
3 participants