stevearc / oil.nvim

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

bug: `win_options` gets applied for the first opened buffer/window #398

Closed NStefan002 closed 2 months ago

NStefan002 commented 5 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Ubuntu 22.04.4 LTS

Describe the bug

When starting the new neovim instance with nvim <dir_name> and instantly using something like <C-o>, <C-i> or harpoon jump the first opened buffer has no signcolumn nor number or relativenumber (basically win_options get applied to the first buffer/window opened after Oil loads).

https://github.com/stevearc/oil.nvim/assets/100767853/b825d6ab-cb3f-4a6c-9cfb-11d207a8c193

In the video, you can see that I press <C-o> right as the Oil is loading.

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. nvim -u repro.lua dir/
  2. instantly press <C-o> (if the jumplist is empty just open up a file and press G, that should create one entry in the jumplist and then redo steps 1 and 2)

Expected Behavior

Buffer/window opened using the mentioned methods should have statuscolumn, number, and relativenumber (if they're set in the neovim config directory, of course).

Directory structure

dir/1.lua

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 = {
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
                win_options = {
                    number = false,
                    relativenumber = false,
                    signcolumn = "yes",
                },
            })
        end,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.opt.signcolumn = "yes"
vim.opt.number = true
vim.opt.relativenumber = true

Did you check the bug with a clean config?

csponge commented 2 months ago

Are you still having this problem? I tried recreating the issue, but I couldn't get it to fail on nvim 0.10.1 and oil 2.12.0.

I wouldn't mind helping out if you are still experiencing this issue.

NStefan002 commented 2 months ago

@csponge I can still reproduce this problem with oil 2.12.0 on both neovim stable and nightly.

csponge commented 2 months ago

@NStefan002, okay. I'll keep playing around with it. I'll let you know if I find anything.

csponge commented 2 months ago

@NStefan002, I think I might have found a fix. It seems that the initialize function in lua/oil/view.lua was getting called after loading the file in the jumplist. It was calling set_win_options without any checks on the filetype. I added a check for filetype before setting win_options.

Since I made that change, I haven't seen the issue. However, I only got it to fail around 1-2 times out of 10 before the fix. I'm probably not timing the keystrokes correctly. With that said, would you be willing to test my fork out before I make a pull request?

You can find it here:

https://github.com/csponge/oil.nvim/tree/bug/win_options-applied-to-first-buffer

Let me know if that resolves your issue.

NStefan002 commented 2 months ago

@csponge I think you fixed it! I can't reproduce the problematic behavior anymore (note that I could reproduce it about 80-90 percent of the time). Good work, thank you!