Ok, found a few errors, but only one in your code. I have a workaround though for the bug in nvim-session-manager.
There's, at the very least, a bug in the code of neovim-session-manager which errors out even if you get the correct name while sidebar is open, before crashing. This may be an issue with sidebar though but session manager shouldn't crash neovim at all.
For your bug, in your binding, you should add one to the line number to get the correct index. So, local filename = filenames(line + 1)
will work. This isn't what caused your issue however
The second issue, is with you having the sidebar open. This, for some reason, crashes neovim for me. The following code closes the sidebar before running the command.
bindings = {
["l"] = function(line, col)
vim.cmd("SidebarNvinClose")
local filename = filenames[line + 1]
session_manager.load_session(filename, false)
end,
This, for me, works. I'll update later with my full code snippet along with how to output tables in lua.
Edit: Here's the code that worked for me, incase I missed something. You can use the dump function at the top to format the table into a string. Use print(dump(file))
to view it:
local function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
local sessionman = require'session_manager.utils'
local sessions = sessionman.get_sessions()
local dirs = {}
local filenames = {}
for _, file, _ in pairs(sessions) do
print(file.filename)
local directory = sessionman.shorten_path(file.dir)
table.insert(dirs, directory);
table.insert(filenames, file.filename);
end
local section = {
title = "Section Title",
icon = "->",
setup = function(ctx)
-- called only once and if the section is being used
end,
end,
draw = function(ctx)
return dirs;
end,
bindings = {
["l"] = function (line, col)
vim.cmd("SidebarNvimClose")
local filename = filenames[line + 1];
sessionman.load_session(filename, true);
end,
}
}
return {
"/sidebar-nvim/sidebar.nvim",
config = {
sections = {
section,
}
}
}