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

BUG: File Nesting sometimes not working. #1494

Closed
3 tasks done
saifulapm opened this issue Jun 9, 2024 · 3 comments · May be fixed by #1602
Closed
3 tasks done

BUG: File Nesting sometimes not working. #1494

saifulapm opened this issue Jun 9, 2024 · 3 comments · May be fixed by #1602
Labels
bug Something isn't working

Comments

@saifulapm
Copy link

saifulapm commented Jun 9, 2024

Did you check docs and existing issues?

  • I have read all the docs.
  • I have searched the existing issues.
  • I have searched the existing discussions.

Neovim Version (nvim -v)

v0.10.0

Operating System / Version

macOS Sonoma 14.5 arm64

Describe the Bug

Hi, When I added large nesting rules tables, then sometimes nesting rules works and sometimes not. I understand that it's happening because of large table. Not sure it's possible to fix...

You can check video: In LazyVim folder, I have rules for readmes. sometime readmes nested sometime not.

Screen.Recording.2024-06-09.at.7.30.26.PM.mov

Here is those rules:

  ['README.*'] = {
    files = { 'AUTHORS', 'BACKERS*', 'CHANGELOG*', 'CITATION*', 'CODE_OF_CONDUCT*', 'CODEOWNERS', 'CONTRIBUTING*', 'CONTRIBUTORS', 'COPYING*', 'CREDITS', 'GOVERNANCE%.MD', 'HISTORY%.MD', 'LICENSE*', 'MAINTAINERS', 'RELEASE_NOTES*', 'SECURITY%.MD', 'SPONSORS*', 'README-*' },
    ignore_case = true,
    pattern = 'README%.(.*)$'
  },

If I just added this rule no any other rule, then it works every time. So this issue happening because large table.

Thanks

Screenshots, Traceback

No response

Steps to Reproduce

  1. Install nesting rules
-- init.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
{
    "nvim-neo-tree/neo-tree.nvim",
    branch = "v3.x",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
      "MunifTanjim/nui.nvim",
      "saifulapm/neotree-file-nesting-config",
    },
    keys = {
      {
        "<C-n>",
        function()
          require("neo-tree.command").execute({ toggle = true })
        end,
        desc = "Explorer NeoTree",
      },
    },
    config = function(_, opts)
      opts.nesting_rules = require('neotree-file-nesting-config').nesting_rules
      require('neo-tree').setup(opts)
    end,
}
})
  1. git clone https://github.com/lazyVim/LazyVim/ and open in neovim. Sometime readmes nested sometimes not,

Thanks

Expected Behavior

It should be nested every time. In the video, you can see what's happening.

Your Configuration

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}

local neotree_config = {
  "nvim-neo-tree/neo-tree.nvim",
  dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim", "saifulapm/neotree-file-nesting-config" },
  cmd = { "Neotree" },
  keys = {
    { "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
  },
  opts = {
    -- Your config here
    -- ...
  },
  config = function(_, opts)
    opts.nesting_rules = require('neotree-file-nesting-config').nesting_rules
    require('neo-tree').setup(opts)
  end,
}

table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@saifulapm saifulapm added the bug Something isn't working label Jun 9, 2024
@Ajaymamtora
Copy link

I have this issue as well, did you find a fix?

@saifulapm
Copy link
Author

I have this issue as well, did you find a fix?

No.

saifulapm added a commit to saifulapm/neo-tree.nvim that referenced this issue Nov 16, 2024
…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
@saifulapm
Copy link
Author

I have this issue as well, did you find a fix?

This PR #1602 will solve that issue..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants