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

fix: open file results in one empty buffer #138

Merged
merged 2 commits into from
Jun 29, 2024

Conversation

rick-yao
Copy link
Contributor

I am using AstroNvim and encountered an issue that will result in one empty buffer.
background:
AstroNvim uses alpha.nvim as a greeting.
reproduce procedure:

  1. use astronvim
  2. add yazi.nvim with below config
---@type LazySpec
return {
  "mikavilpas/yazi.nvim",
  event = "VeryLazy",
  keys = {
    -- 👇 in this section, choose your own keymappings!
    {
      "<leader>-",
      function() require("yazi").yazi() end,
      desc = "Open the file manager",
    },
    {
      -- Open in the current working directory
      "<leader>+",
      function() require("yazi").yazi(nil, vim.fn.getcwd()) end,
      desc = "Open the file manager in nvim's working directory",
    },
  },
  ---@type YaziConfig
  opts = {
    -- open_for_directories = true,
    log_level = vim.log.levels.INFO,
  },
}
  1. open neovim , leader- to open yazi,select a file to open
  2. will look like below ,an Untitled buffer is created.
image

I added a temporary solution to fix it which is ugly because I did not find why this happened. If you'd like to help, I'd like to pr further.
My solution is to find the buffer with no actual path. If the path is empty , then delete the buffer.

minimum repro lua with astronvim nvim -u repro.lua to use

-- 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
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable",
    lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
  { "AstroNvim/AstroNvim", import = "astronvim.plugins" },
  {
    "mikavilpas/yazi.nvim",
    event = "VeryLazy",
    keys = {
      -- 👇 in this section, choose your own keymappings!
      {
        "<leader>-",
        function()
          require("yazi").yazi()
        end,
        desc = "Open the file manager",
      },
      {
        -- Open in the current working directory
        "<leader>+",
        function()
          require("yazi").yazi(nil, vim.fn.getcwd())
        end,
        desc = "Open the file manager in nvim's working directory",
      },
    },
    ---@type YaziConfig
    opts = {
      -- open_for_directories = true,
      log_level = vim.log.levels.INFO,
    },
  },

  -- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here (autocommands, vim.filetype, etc.)

@mikavilpas
Copy link
Owner

Thanks, I appreciate the effort you put in! I can reproduce the issue, and I'll try to find the root cause.

@mikavilpas mikavilpas merged commit 73a5f8f into mikavilpas:master Jun 29, 2024
13 checks passed
@mikavilpas
Copy link
Owner

Thanks again for pointing this out. I was able to fix it for my lazyvim setup as well as the astronvim repro setup you provided 👍🏻

@rick-yao
Copy link
Contributor Author

rick-yao commented Jul 1, 2024

Thanks so much for your quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants