axkirillov / hbac.nvim

Heuristic buffer auto-close
MIT License
197 stars 10 forks source link

Some light restructuring. #10

Closed axkirillov closed 1 year ago

axkirillov commented 1 year ago

Should not change anything functionally

al-ce commented 1 year ago

Hi! This restructuring makes sense and it cleans up a good amount of my build-as-I-go choices 😅

I'm having a few issues with a minimal config using lazy.nvim (and hoping I'm not about to embarrass myself with a lengthy misdiagnosis or that the issue is on my end).

EDIT: my lazy.nvim config

return {
  {
    enabled = true,
    "axkirillov/hbac.nvim",
    branch = "test",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons",
    },
    lazy = false,
    config = function()
      local hbac = require("hbac")
      hbac.setup({
        threshold = 4,
      })
    end,
  },
}

Buffers aren't autoclosing past the threshold, either with the default config or if I pass in explicit opts in my setup. Also, the :Hbac close_unpinned command and the corresponding Telescope action gives me these errors:

Command:

E5108: Error executing lua: ...l/share/nvim/lazy/hbac.nvim/lua/hbac/command/actions.lua:12: attempt to index upvalue 'config' (a nil value)
stack traceback:
    ...l/share/nvim/lazy/hbac.nvim/lua/hbac/command/actions.lua:12: in function 'close_unpinned'
    ...are/nvim/lazy/hbac.nvim/lua/hbac/command/subcommands.lua:8: in function 'close_unpinned'

Telescope action:

E5108: Error executing lua: ...l/share/nvim/lazy/hbac.nvim/lua/hbac/command/actions.lua:12: attempt to index upvalue 'config' (a nil value)
stack traceback:
    ...l/share/nvim/lazy/hbac.nvim/lua/hbac/command/actions.lua:12: in function 'action'
    ...im/lazy/hbac.nvim/lua/hbac/telescope/attach_mappings.lua:20: in function 'execute_telescope_action'
    ...im/lazy/hbac.nvim/lua/hbac/telescope/attach_mappings.lua:40: in function 'key_func'
    ...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:253: in function <...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:252>

Regarding the close_unpinned command/action, I think the problem originates with initializing command in init.lua (line 1) because:

My current workaround is to initialize the config variable in command/actions, utils, and autocommands to:

local config = require("hbac.config")

and make the relevant changes, e.g. changing config to config.values in autocommands.lua:32:

if num_buffers <= config.values.threshold then

Regarding the autoclose autocommand, in setup.lua, the assignment is currently:

local config = require("hbac.config")

But in the setup call we check for the autoclose value with:

if config.autoclose then
    autocommands.autoclose.setup()
end

As far as I can tell, the config module never gets autoclose inserted into the table it returns, so this condition is never true. I can fix this by changing it to:

if config.values.autoclose then
    autocommands.autoclose.setup()
end

Ok, hope I've understood the situation correctly and that these comments aren't misleading! How are things looking like on your end? Thanks for the restructuring

axkirillov commented 1 year ago

@al-ce sorry you had to go through my sloppy refactor 😅 I fixed the references to config module and now it should work as expected

al-ce commented 1 year ago

Looks good! Thanks for the example of a nice refactor, this will be a nice point of reference for me in future projects.