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: Error when opening a new tab if Oil is currently open #40

Closed
3 tasks done
RoryNesbitt opened this issue Jan 18, 2023 · 5 comments
Closed
3 tasks done

bug: Error when opening a new tab if Oil is currently open #40

RoryNesbitt opened this issue Jan 18, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@RoryNesbitt
Copy link

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

NVIM v0.8.2

Operating system/version

Endeavour OS

Describe the bug

If you're currently looking at an Oil buffer and you use the command tabedit or tabnew it pops up with an error Oil split could not find parent window. Please try to replicate whatever you just did and report a bug on github

So I'm doing that. Other than this displaying everything seems to work as expected

Steps To Reproduce

nvim .
:tabnew

Expected Behavior

Oil to not needlessly worry
Everything is fine, stress is bad for a young plugin, you're doing great <3

Directory structure

No response

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({
              -- add any needed settings here
            })
        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?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@RoryNesbitt RoryNesbitt added the bug Something isn't working label Jan 18, 2023
@stevearc
Copy link
Owner

Thanks for the report, and the kind words! This actually was causing a bug, just subtly. It was interfering with resetting the window options after leaving an oil buffer after you :tabnew. Should be fixed now!

@RoryNesbitt
Copy link
Author

RoryNesbitt commented Jan 19, 2023

This now gives a more classic error when the new buffer AND the current buffer is the pwd.

nvim .
:tabnew .
Error executing vim.schedule lua callback: /home/rory/.local/share/nvim/lazy/oil.nvim/l
ua/oil/util.lua:130: Invalid buffer id: 5
stack traceback:
        [C]: in function '__index'
        /home/rory/.local/share/nvim/lazy/oil.nvim/lua/oil/util.lua:130: in function </
home/rory/.local/share/nvim/lazy/oil.nvim/lua/oil/util.lua:121>

Also interesting notes:

  • While this error is on screen I see netrw behind it, when I hit enter to close it I get oil and it appears to work great.
  • This does not happen if you open a different directory e.g. :tabnew lua
  • if you open a directory in the current oil, then you tabnew the same one you just opened you get no error but you get netrw not oil. e.g. cd .config/nvim; nvim . select lua and enter :tabnew lua

@stevearc
Copy link
Owner

Ah, it's more race conditions. There's more edge cases around the netrw conflicts than I thought :/

The first part of this is fixed. Still working on that last one.

@stevearc
Copy link
Owner

Well I've wrestled with it for a while now, but I've hit a case that I can't figure out how to handle gracefully. It's triggered by nvim lua then :e lua. The issue is that we try to rename the buffer to the oil:// format, but that buffer already exists. We then fall back to creating a new buffer and replacing the existing one, but somehow in the meantime netrw manages to delete the old buffer and replace it with a new one, so our replace operation fails. I've tried finding a way to stop netrw (not possible; all the variables that affect the control flow are script-local), changing the timing of the replace operation (doesn't help), and detecting the new buffer creation (strangely, I seem to not get any autocmds for the new buffer. No BufNew, BufAdd, BufEnter, nothing. Even with nested = true). I'm documenting this in case I try to pick this back up again some time down the road, but I'm giving up for now. I think that I'm okay with saying that if you don't disable netrw, you may sometimes see netrw. As a compromise, I've added a notification that tells the user how to disable netrw.

@RoryNesbitt
Copy link
Author

Yeah that sounds like a fair solution. In practice now I see netrw for just a split second once per session, and the cursor position changes in the new tab. Both things being pretty non-issues considering how rare this actually comes up in real use

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

No branches or pull requests

2 participants