stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
4.12k stars 121 forks source link

bug: all directory sizes show 4.1k #486

Open ndfsa opened 2 months ago

ndfsa commented 2 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

v0.11.0-dev-771+g67d6b6f27

Operating system/version

Arch Linux

Describe the bug

When using the size column, it shows "4.1k" for all directories regardless of their contents.

Screenshot from 2024-09-20 01-08-53 Screenshot from 2024-09-20 01-08-57 Screenshot from 2024-09-20 01-09-05

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. enable the size column
  2. open directory with subdirectories inside

Expected Behavior

Although it is technically correct, 4096 being the size of the inode, I think it would be better to just hide the size if it does not represent the actual size of the contents.

Directory structure

test/ test/directory1/test.txt test/directory2/

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "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",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({

      columns = { "size", "icon" },
            })
        end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

ndfsa commented 2 months ago

The following change to the files adapter would hide the size if the entry type is a directory.

--- a/lua/oil/adapters/files.lua
+++ b/lua/oil/adapters/files.lua
@@ -65,7 +65,7 @@ file_columns.size = {
   render = function(entry, conf)
     local meta = entry[FIELD_META]
     local stat = meta.stat
-    if not stat then
+    if not stat or stat.type == "directory" then
       return columns.EMPTY
     end
     if stat.size >= 1e9 then

Screenshot from 2024-09-20 01-14-50

Note that this only works for this adapter, as I have not yet used the others.

I can make a PR with the change