olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: attempt to index a nil value while calling Telescope persisted

DeadlySquad13 opened this issue · comments

Thanks for the plugin! Unfotunately, I have some problems with it.
When I call Telescope persisted I get the error message:

Error executing Lua callback: .../pack/packer/start/persisted.nvim/lua/persisted/init.lua:199: attempt to index a nil value
stack traceback:
        .../pack/packer/start/persisted.nvim/lua/persisted/init.lua:199: in function 'list'
        ...t/persisted.nvim/lua/telescope/_extensions/persisted.lua:15: in function <...t/persisted.nvim/lua/telescope/_extensions/persisted.lua:9>
        ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
        ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
        ...te/pack/packer/start/telescope.nvim/plugin/telescope.lua:109: in function <...te/pack/packer/start/telescope.nvim/plugin/telescope.lua:108>

I expected to get Telescope window with sessions instead.

My Configuration

Persisted related part of packer config:

    -- * Session management.
    use({
      'olimorris/persisted.nvim',
      --module = "persisted", -- For lazy loading
      config = [[ require('config.persisted') ]],
    });

Persisted config:

local prequire = require('utils').prequire;

local persisted_status_is_ok, persisted = prequire("persisted");
if not persisted_status_is_ok then 
  return;
end

--local ENV = require('global');

persisted.setup({
  -- Unfortunately, SessionLoadLast doesn't work with save_dir even though it's
  --   newer.
  --save_dir = ENV.NVIM_DATA .. '/sessions/', -- directory where session files are saved
  --dir = ENV.NVIM_DATA .. '/sessions/', -- directory where session files are saved
  save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"),
  --dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"),
  --command = 'VimLeavePre', -- the autocommand for which the session is saved
  --use_git_branch = true, -- create session files based on the branch of the git enabled repository
  --autosave = true, -- automatically save session files when exiting Neovim
  --autoload = false, -- automatically load the session for the cwd on Neovim startup
  --allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
  --ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading
  --before_save = function() end, -- function to run before the session is saved to disk
  --after_save = function() end, -- function to run after the session is saved to disk
  --telescope = { -- options for the telescope extension
    --before_source = function(session) end, -- function to run before the session is sourced via telescope
    --after_source = function(session) end, -- function to run after the session is sourced via telescope
  --},
});

-- To load the telescope extension.
local telescope_status_is_ok, telescope = prequire("telescope");
if not telescope_status_is_ok then
  return;
end

telescope.load_extension("persisted");

prequire is like pcall but with nvim.notify for errors, nothing fancy.

My small investigation

Tried to call lua require('persisted').list() directly to understand if the problem on Telescope or this plugin's side and got this error:

E5108: Error executing lua .../pack/packer/start/persisted.nvim/lua/persisted/init.lua:199: attempt to index a nil value
stack traceback:
        .../pack/packer/start/persisted.nvim/lua/persisted/init.lua:199: in function 'list'
        [string ":lua"]:1: in main chunk

Unfortunately, I couldn't make any progress by

  • changing any options,
  • rerunning PackerSync & PackerCompile

That's why I'm posting this issue here. Hope you will help me solve it!

commented

Just pushed a potential fix. Could you let me know if that works?

Just pushed a potential fix. Could you let me know if that works?

Hello! Thanks for the attention to my issue, It's now working fine!
I have only problem with dir and save_dir options with Telescope persisted specifically, I decided to post it in another issue as thought it would be more appropriate: #13 (comment)
Mentioning it here just in case.

commented

From #13

However, it seems like Telescope persisted still takes only dir into consideration as it loads only sessions saved while dir option is set.

Steps to reproduce:

  1. Remove dir option,
  2. set save_dir instead,
  3. restart nvim to apply settings,
  4. spam some files and save session,
  5. restart vim
  6. open Telescope persisted and your newly created session won't be displayed.
commented

@DeadlySquad13 I'm reluctant to fix this given we state in the config that users should use the save_dir config option. I allowed for dir as I changed the API and didn't want users config to break. But I don't want to add functionality to anticipate users switching between the old and new API.

@DeadlySquad13 I'm reluctant to fix this given we state in the config that users should use the save_dir config option. I allowed for dir as I changed the API and didn't want users config to break. But I don't want to add functionality to anticipate users switching between the old and new API.

I understand your decision. Unfortunately, the problem is that Telescope persisted in my case works only with dir but not with save_dir. I added step "remove dir option" only to make sure that only save_dir is used, I wasn't insisting that users should jump from old to new api and back.

commented

@DeadlySquad13 - Have you pulled the latest version of the plugin?

There is nowhere in the code which references soley the dir option. For example, here, we attempt to use the dir option and if it's not present we use the save_dir one (which is technically always present as it's in the default config).

My only thought is that perhaps the session isn't saved at all. once you've carried out your "steps to reproduce", above. The Telescope extension relies on the plugin to do all of the heavy lifting like list sessions, source them etc.