fix: properly start a session from Telescope (#134)

Properly starts sessions loaded from another directory using Telescope.
Crucially, this version compares the working directory of the session, not
the working directory at the time of the session load, to the lists
of allowed and ignored directories.

Co-authored-by: Oli <olimorris@users.noreply.github.com>
main
Jurek Olden 2024-06-04 00:29:47 +10:00 committed by GitHub
parent 2b4f192aca
commit e50e0b65b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View File

@ -203,14 +203,23 @@ end
function M.load(opt, dir) function M.load(opt, dir)
opt = opt or {} opt = opt or {}
dir = dir or session_dir() dir = dir or session_dir()
local branch = get_branchname()
local session = opt.session or (opt.last and get_last() or get_current(dir)) local branch
local session
local session_exists = vim.fn.filereadable(session) ~= 0 if opt.session then
session = opt.session
local session_data = utils.make_session_data(session)
branch = session_data and session_data.branch or ""
if not branch then
vim.notify(string.format("[Persisted.nvim]: Invalid session file %s", session), vim.log.levels.WARN)
end
else
branch = get_branchname()
session = opt.last and get_last() or get_current(dir)
end
if session then if session then
if session_exists then if vim.fn.filereadable(session) ~= 0 then
vim.g.persisting_session = not config.options.follow_cwd and session or nil vim.g.persisting_session = not config.options.follow_cwd and session or nil
utils.load_session(session, config.options.silent) utils.load_session(session, config.options.silent)
elseif type(config.options.on_autoload_no_session) == "function" then elseif type(config.options.on_autoload_no_session) == "function" then
@ -218,6 +227,7 @@ function M.load(opt, dir)
end end
end end
dir = session_dir()
if config.options.autosave and (allow_dir(dir) and not ignore_dir(dir)) and not ignore_branch(branch) then if config.options.autosave and (allow_dir(dir) and not ignore_dir(dir)) and not ignore_branch(branch) then
M.start() M.start()
end end

View File

@ -1,7 +1,7 @@
local actions_state = require("telescope.actions.state") local actions_state = require("telescope.actions.state")
local transform_mod = require("telescope.actions.mt").transform_mod local transform_mod = require("telescope.actions.mt").transform_mod
local utils = require("persisted.utils") local persisted = require("persisted")
local M = {} local M = {}
---Get the selected session from Telescope ---Get the selected session from Telescope
@ -18,7 +18,7 @@ M.load_session = function(session, config)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPre", data = session }) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPre", data = session })
vim.schedule(function() vim.schedule(function()
utils.load_session(session.file_path, config.silent) persisted.load({ session = session.file_path })
end) end)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPost", data = session }) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPost", data = session })