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: splitting window: oil split could not find parent window #155

Closed
3 tasks done
FrostyNick opened this issue Aug 16, 2023 · 6 comments
Closed
3 tasks done

bug: splitting window: oil split could not find parent window #155

FrostyNick opened this issue Aug 16, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@FrostyNick
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)

0.9.0 Release

Operating system/version

Ubuntu 20.04

Describe the bug

image

Steps To Reproduce

  1. nvim -u repro.lua
  2. ZZ to close Lazy.
  3. :Ex
  4. <C-w>v
  5. Warning text below: "Oil split could not find parent window. Please try to replicate whatever you just did and report a bug on github"

Expected Behavior

Oil split finds parent window.

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.
@FrostyNick FrostyNick added the bug Something isn't working label Aug 16, 2023
stevearc added a commit that referenced this issue Aug 20, 2023
If you use oil and you want to still use netrw, set
`default_file_explorer = false`.

It is nonsensical to both use netrw _and_ have oil hijack directory
buffers (which was the case for the default config). It also causes
undefined behavior and bugs. When `default_file_explorer = true` (the
default) oil will now disable netrw for you.
@stevearc
Copy link
Owner

This is due to bad interactions with oil and netrw when oil is trying to take over directory buffers but netrw is doing the same. The correct thing to do here is to set

require("oil").setup({
  default_file_explorer = false
})

Because I've seen these errors before, I've changed the behavior so that when default_file_explorer = true (the default), oil will disable netrw. This means that you now must set default_file_explorer = false if you want to continue using netrw.

@Hippo0o
Copy link

Hippo0o commented Aug 26, 2023

if netrw is disabled scp:// ftp:// sftp:// stops working. Is it really the best choice to straight up disable it?

@stevearc
Copy link
Owner

Fundamentally, if you want oil to work when you do nvim ., you have to disable netrw. netrw does a lot, but is not very configurable so there's no way to turn off the directory hijacking without disabling the whole plugin. If you still want to use netrw, I'm not stopping you. Just set default_file_explorer = false and you're good.

@Hippo0o
Copy link

Hippo0o commented Aug 28, 2023

I'm pretty sure hijacking worked fine without disabling netrw before and nvim-tree does so aswell but i don't know every edge case.
I will just set default_file_explorer to true after setup then.

@kevinm6
Copy link

kevinm6 commented Feb 25, 2024

@stevearc sorry to bother here, but I think that’s better than open a new issue.

I got the same warning today, after opening a file via
nvim scp://user@server//private/etc/hosts that was correctly loaded by Oil, the warning appears after I’ve tried to enter a command like diffsplit /private/etc/hosts.

I have netrw completely disabled and this is my compacted oil config

"stevearc/oil.nvim",
keys = {}
cmd = "Oil",
opts = function(_, o)
  o.columns = default_coloumns(true)
  o.keymaps = {},
  o.use_default_keymaps = false
  o.silence_scp_warning = true -- disable scp warn to use oil-ssh since I'm using a remap
   o.view_options = {}
   o.float = {}
   o.progress = {}
 
   -- This are defaults for now, no need to override
   -- adapters = {
   --   ["oil://"] = "file",
   --   ["oil-ssh://"] = "ssh",
   -- },
   -- When opening the parent of a file, substitute these url schemes
 
   -- HACK:
   -- https://github.com/stevearc/oil.nvim/blob/931453fc09085c09537295c991c66637869e97e1/lua/oil/config.lua#L102~110
   -- Using this to remap url-scheme from args with oil-ssh schemes
   o.adapter_aliases = {
     ["ssh://"] = "oil-ssh://",
     ["scp://"] = "oil-ssh://",
     ["sftp://"] = "oil-ssh://",
   }
end,
init = function(p)
  if vim.fn.argc() == 1 then
    local argv = tostring(vim.fn.argv(0))
    local stat = vim.loop.fs_stat(argv)

    local remote_dir_args = vim.startswith(argv, "ssh") or
      vim.startswith(argv, "sftp") or
      vim.startswith(argv, "scp")

      if stat and stat.type == "directory" or remote_dir_args then
        require("lazy").load { plugins = { p.name } }
      end
   end
   if not require("lazy.core.config").plugins[p.name]._.loaded then
     vim.api.nvim_create_autocmd("BufNew", {
       callback = function()
         if vim.fn.isdirectory(vim.fn.expand("<afile>")) == 1 then
           require("lazy").load { plugins = { "oil.nvim" } }
           -- Once oil is loaded, we can delete this autocmd
           return true
        end
      end,
    })
  end
end

@HarshK200
Copy link

HarshK200 commented Sep 9, 2024

@kevinm6 Did you find a fix for it?
@stevearc please look into this if possible
i got the same issue today as well
image
The wierd thing is that this warning disappears every now and then

// the config
return {
	"stevearc/oil.nvim",
	---@module 'oil'
	---@type oil.SetupOpts
	opts = {},
	-- Optional dependencies
	dependencies = { { "echasnovski/mini.icons", opts = {} } },
	-- dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if prefer nvim-web-devicons
	config = function()
		require("oil").setup({
            -- just shows all the hidden files
			view_options = {
				show_hidden = true,
			},
            default_file_explorer = true
		})
		vim.keymap.set("n", "<C-n>", "<CMD>Oil<CR>", { desc = "Open parent directory" })
	end,
}

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

5 participants