gennaro-tedesco / nvim-possession

📌 the no-nonsense session manager
MIT License
215 stars 7 forks source link

autoload doesn't work #38

Closed slekup closed 4 months ago

slekup commented 5 months ago

I am able to the other features list list(), but I'm not exactly sure how to get autoload to work. I have it set to true and am executing nvim from the current directory as the project I created the in.

Any suggestions on why autoload isn't working?

Plugin config:

  {
    "gennaro-tedesco/nvim-possession",
    dependencies = {
      "ibhagwan/fzf-lua",
    },
    config = true,
    opts = {
      autoload = true,
      autoswitch = {
        enable = true,
      },
      fzf_winopts = {
        width = 0.75,
      },
    },
    keys = function()
      local possession = require("nvim-possession")
      return {
        {
          "<leader>ql",
          function()
            possession.list()
          end,
          desc = "List Sessions",
          mode = "n",
        },
        {
          "<leader>qn",
          function()
            possession.new()
          end,
          desc = "New Session",
          mode = "n",
        },
        {
          "<leader>qu",
          function()
            possession.update()
          end,
          desc = "Update Session",
          mode = "n",
        },
        {
          "<leader>qd",
          function()
            possession.delete()
          end,
          desc = "Delete Session",
          mode = "n",
        },
      }
    end,
  },
gennaro-tedesco commented 5 months ago

Good evening!

Could you specify what it means that autoload isn't working? The autoload function checks whether a session whose directory path corresponds to the cwd exists in the vim session file: if so, it executes it.

Could you please verify:

Under these conditions is the autoload mechanism still not working?

slekup commented 5 months ago

I might not fully understand what you're asking for, but I'll try my best.

This is what I presume to be the session file: ~/.local/share/nvim/sessions/dotfiles

let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
  let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
  set shortmess=aoOA
else
  set shortmess=aoO
endif
badd +97 ~/dotfiles/setup.sh
argglobal
%argdel
edit ~/dotfiles/setup.sh
let s:save_splitbelow = &splitbelow
let s:save_splitright = &splitright
set splitbelow splitright
let &splitbelow = s:save_splitbelow
let &splitright = s:save_splitright
wincmd t
let s:save_winminheight = &winminheight
let s:save_winminwidth = &winminwidth
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
argglobal
balt ~/dotfiles/.config/nvim/lua/config/autocmds.lua
let s:l = 97 - ((27 * winheight(0) + 28) / 56)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 97
normal! 0
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
  silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let &winminheight = s:save_winminheight
let &winminwidth = s:save_winminwidth
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
  exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
set hlsearch
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :

When I open the terminal in nvim and type pwd, it does return the absolute path for ~/dotfiles.

The cwd in the sessions list seems to show where the session files are, I'm not sure if that's the issue or if it's intended? swappy-20240331-102508

gennaro-tedesco commented 5 months ago

Whenever you save a session from a certain directory, the corresponding session file must present the entry

...
cd ~/<dir_name>
...

which seems to be absent in yours: please check if you have specific configurations for vim sessions (for instance, not to save session path when saving). See :h sessionoptions, if I am not mistaken you have to set the value curdir.

Once such entry is present in the session file, and once you open neovim from within that directory, the plugin will automatically load the session.

slekup commented 4 months ago

I did see that in the README, but I wasn't sure how to do that with LazyVim. However, it seems to work with:

vim.cmd("set ssop+=curdir")

in options.lua and setting lazy = false for possession.

So, now the plugin seems to work, except I get a large error saying "failed to run config for nvim-possession".

Error:

Failed to run `config` for nvim-possession

.../nvim/lazy/nvim-possession/lua/nvim-possession/utils.lua:62: /home/slekup/dotfiles/.config/nvim/init.lua../home/slekup/.local/share/nvim/sessions/blue[19]..BufReadPost Autocommands for "*": Vim(append):Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: /home/slekup/dotfiles/.config/nvim/init.lua../home/slekup/.local/share/nvim/sessions/blue[19]..BufReadPost Autocommands for "*"..FileType Autocommands for "*": Vim(append):Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:151: Invalid 'group': 'syntaxset'
stack traceback:
    [C]: in function 'nvim_exec_autocmds'
    /usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:151: in function 'destroy'
    /usr/share/nvim/runtime/lua/vim/treesitter.lua:471: in function 'stop'
    ...m/lazy/nvim-treesitter/lua/nvim-treesitter/highlight.lua:28: in function 'detach'
    ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:522: in function 'detach_module'
    ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:531: in function 'reattach_module'
    ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>
    [C]: in function 'nvim_cmd'
    /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
    [C]: in function 'nvim_buf_call'
    /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
    ...
    [C]: in function 'xpcall'
    .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:381: in function 'config'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:348: in function '_load'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:191: in function 'load'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:123: in function 'startup'
    ...lekup/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:112: in function 'setup'
    /home/slekup/.config/nvim/lua/config/lazy.lua:14: in main chunk
    [C]: in function 'require'
    /home/slekup/dotfiles/.config/nvim/init.lua:2: in main chunk
stack traceback:
    [C]: in function 'nvim_cmd'
    /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
    [C]: in function 'nvim_buf_call'
    /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
    [C]: in function 'source'
    .../nvim/lazy/nvim-possession/lua/nvim-possession/utils.lua:62: in function 'autoload'
    ...e/nvim/lazy/nvim-possession/lua/nvim-possession/init.lua:148: in function 'setup'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:373: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:371>
    [C]: in function 'xpcall'
    .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:381: in function 'config'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:348: in function '_load'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:191: in function 'load'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:123: in function 'startup'
    ...lekup/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:112: in function 'setup'
    /home/slekup/.config/nvim/lua/config/lazy.lua:14: in main chunk
    [C]: in function 'require'
    /home/slekup/dotfiles/.config/nvim/init.lua:2: in main chunk
stack traceback:
    [C]: in function 'nvim_buf_call'
    /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
    [C]: in function 'source'
    .../nvim/lazy/nvim-possession/lua/nvim-possession/utils.lua:62: in function 'autoload'
    ...e/nvim/lazy/nvim-possession/lua/nvim-possession/init.lua:148: in function 'setup'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:373: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:371>
    [C]: in function 'xpcall'
    .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:381: in function 'config'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:348: in function '_load'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:191: in function 'load'
    ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:123: in function 'startup'
    ...lekup/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:112: in function 'setup'
    /home/slekup/.config/nvim/lua/config/lazy.lua:14: in main chunk
    [C]: in function 'require'
    /home/slekup/dotfiles/.config/nvim/init.lua:2: in main chunk

# stacktrace:
  - ~/.config/nvim/lua/config/lazy.lua:14
  - ~/dotfiles/.config/nvim/init.lua:2

Possession config:

  {
    "gennaro-tedesco/nvim-possession",
    lazy = false,
    dependencies = {
      { "ibhagwan/fzf-lua" },
    },
    config = true,
    opts = {
      autoload = true,
      autoswitch = {
        enable = true,
      },
      fzf_winopts = {
        width = 0.75,
      },
    },
    keys = function()
      local possession = require("nvim-possession")
      return {
        {
          "<leader>ql",
          function()
            possession.list()
          end,
          desc = "List Sessions",
          mode = "n",
        },
        {
          "<leader>qn",
          function()
            possession.new()
          end,
          desc = "New Session",
          mode = "n",
        },
        {
          "<leader>qu",
          function()
            possession.update()
          end,
          desc = "Update Session",
          mode = "n",
        },
        {
          "<leader>qd",
          function()
            possession.delete()
          end,
          desc = "Delete Session",
          mode = "n",
        },
      }
    end,
  },

Treesitter config:

  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    event = "BufReadPost",
    opts = function(_, opts)
      if type(opts.ensure_installed) == "table" then
        vim.list_extend(opts.ensure_installed, {
          -- Languages
          "markdown",
          "markdown_inline",
        })
      end
    end,
    config = require("nvim-treesitter.configs").setup({
      ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown" },
      sync_install = false,
      auto_install = true,
      ignore_install = {},
      highlight = {
        enable = true,
        use_languagetree = true,
      },
      modules = {},
    }),
  },
gennaro-tedesco commented 4 months ago

The error seems to be unrelated to nvim-possession: the line it is pointing to is essentially loading a vim session, when doing so some other (treesitter) errors occur.

  1. Have you updated Treesitter and all its parsers to the latest versions?
  2. Could you try with a minimally reproducible configuration? I do not know how LazyVim interfaces with treesitter, so there may be configurations in there that need to be updated/set properly.

Here on the wiki you can find a minimally reproducible mini.lua to try and reproduce.

slekup commented 4 months ago

It happens when I use the "extra" plugins that LazyVim provides that include the treesitter plugin, such as the rust one, but when adding treesitter manually, no error shows.

(I had to replace the relative path with an absolute path on the first line and remove the extra / added for the three references to root.)

Repro:

local root = vim.fn.fnamemodify("/home/slekup/.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "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

vim.g.mapleader = " "
require("lazy").setup({
    root = root .. "plugins",
    spec = {
        { "lazyvim/lazyvim", import = "lazyvim.plugins" },
        { import = "lazyvim.plugins.extras.ui.alpha" },
        { import = "lazyvim.plugins.extras.lang.rust" },
        { import = "plugins" },
        {
            { "craftzdog/solarized-osaka.nvim" },
            -- {
            --  "nvim-treesitter/nvim-treesitter",
            --  opts = function(_, opts)
            --      opts.ensure_installed = opts.ensure_installed or {}
            --      vim.list_extend(opts.ensure_installed, { "ron", "rust", "toml" })
            --  end,
            -- },
            {
                "gennaro-tedesco/nvim-possession",
                lazy = false,
                dependencies = {
                    "ibhagwan/fzf-lua",
                },
                config = true,
                opts = {
                    autoload = true,
                },
                init = function()
                    local possession = require("nvim-possession")
                    vim.keymap.set("n", "<leader>ml", function()
                        possession.list()
                    end)
                    vim.keymap.set("n", "<leader>mn", function()
                        possession.new()
                    end)
                    vim.keymap.set("n", "<leader>mu", function()
                        possession.update()
                    end)
                    vim.keymap.set("n", "<leader>md", function()
                        possession.delete()
                    end)
                end,
            },
        },
    },
    defaults = {
        lazy = false,
        version = false,
    },
    checker = { enabled = true }, -- automatically check for plugin updates
    performance = {
        rtp = {
            disabled_plugins = {
                "gzip",
                "tarplugin",
                "tohtml",
                "tutor",
                "zipplugin",
            },
        },
    },
})

vim.opt.termguicolors = true
vim.cmd([[colorscheme solarized-osaka]])
slekup commented 4 months ago

I don't know why, but after some trial and error, I realized the problem only occurred when the rustaceanvim plugin (one of the plugins included in lazyvim.plugins.extras.lang.rust) was being imported. I fixed the issue by making it a dependency of treesitter.

Thanks for the help!