stevearc / resession.nvim

A replacement for mksession with a better API
MIT License
175 stars 13 forks source link

bug: session auto reload snippet overwriting vi -t #54

Open rameshsanth opened 2 months ago

rameshsanth commented 2 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

0.9.6

Operating system/version

Redhat 8

Describe the bug

Technically this is not a bug. However it's an annoyance. I'm not sure how to fix this either. Wondering if anyone one else out there knows a better way to do this.

Below snippet provided as solution to auto restore session when no files are passed. Unfortunately, this overrides any commands provided when vi is invoked with options such as -t (tag search) or -c (commands).

The reason seems to be vim.fn.argc(-1) return 0 for these commands.

vim.api.nvim_create_autocmd("VimEnter", {
  callback = function()
    -- Only load the session if nvim was started with no args
    if vim.fn.argc(-1) == 0 then
      -- Save these to a different directory, so our manual sessions don't get polluted
      resession.load(vim.fn.getcwd(), { dir = "dirsession", silence_errors = true })
    end
  end,
  nested = true,
})
vim.api.nvim_create_autocmd("VimLeavePre", {
  callback = function()
    resession.save(vim.fn.getcwd(), { dir = "dirsession", notify = false })
  end,
})

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

Try running search for all files with stevearc and open in vim. vim -c "silent grep -- stevearc" -c "copen" if you have tags, vi -t <tag>

Expected Behavior

The files picked by grep or tag must be opened.

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/resession.nvim",
        config = function()
            require("resession").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
vim.api.nvim_create_autocmd("VimEnter", {
  callback = function()
    -- Only load the session if nvim was started with no args
    if vim.fn.argc(-1) == 0 then
      -- Save these to a different directory, so our manual sessions don't get polluted
      resession.load(vim.fn.getcwd(), { dir = "dirsession", silence_errors = true })
    end
  end,
  nested = true,
})
vim.api.nvim_create_autocmd("VimLeavePre", {
  callback = function()
    resession.save(vim.fn.getcwd(), { dir = "dirsession", notify = false })
  end,
})

Did you check the bug with a clean config?