refactor: remove deprecations

main
olimorris 2023-03-09 09:41:22 +00:00
parent 3dcad75325
commit 0a6be5db0e
6 changed files with 25 additions and 143 deletions

View File

@ -8,13 +8,6 @@ local defaults = {
autosave = true, -- automatically save session files when exiting Neovim
should_autosave = nil, -- function to determine if a session should be autosaved (resolve to a boolean)
-- TODO: Remove callbacks after deprecation notice ends
before_save = nil, -- function to run before the session is saved to disk
after_save = nil, -- function to run after the session is saved to disk
before_source = nil, -- function to run before the session is sourced
after_source = nil, -- function to run after the session is sourced
--
autoload = false, -- automatically load the session for the cwd on Neovim startup
on_autoload_no_session = nil, -- function to run when `autoload = true` but there is no session to load
@ -23,10 +16,6 @@ local defaults = {
ignored_dirs = nil, -- table of dirs that are ignored for auto-saving and auto-loading
telescope = { -- options for the telescope extension
-- TODO: Remove callbacks after deprecation notice ends
before_source = nil, -- function to run before the session is sourced via telescope
after_source = nil, -- function to run after the session is sourced via telescope
--
reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted
},
}
@ -36,77 +25,6 @@ M.options = {}
function M.setup(opts)
M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {})
vim.fn.mkdir(M.options.save_dir, "p")
if opts then
if opts.before_source then
require("persisted.deprecate").write(
"----------\n",
"The use of the ",
{ "before_source", "ErrorMsg" },
" callback.\nPlease replace with the ",
{ "PersistedLoadPre", "WarningMsg" },
{ " user event. This will be removed from the plugin on " },
{ "2023-03-05", "WarningMsg" }
)
end
if opts.after_source then
require("persisted.deprecate").write(
"----------\n",
"The use of the ",
{ "after_source", "ErrorMsg" },
" callback.\nPlease replace with the ",
{ "PersistedLoadPost", "WarningMsg" },
{ " user event. This will be removed from the plugin on " },
{ "2023-03-05", "WarningMsg" }
)
end
if opts.before_save then
require("persisted.deprecate").write(
"----------\n",
"The use of the ",
{ "before_save", "ErrorMsg" },
" callback.\nPlease replace with the ",
{ "PersistedSavePre", "WarningMsg" },
{ " user event. This will be removed from the plugin on " },
{ "2023-03-05", "WarningMsg" }
)
end
if opts.after_save then
require("persisted.deprecate").write(
"----------\n",
"The use of the ",
{ "after_save", "ErrorMsg" },
" callback.\nPlease replace with the ",
{ "PersistedSavePost", "WarningMsg" },
{ " user event. This will be removed from the plugin on " },
{ "2023-03-05", "WarningMsg" }
)
end
-- Telescope
if opts.telescope and opts.telescope.before_source then
require("persisted.deprecate").write(
"----------\n",
"The use of the ",
{ "telescope.before_source", "ErrorMsg" },
" callback.\nPlease replace with the ",
{ "PersistedTelescopeLoadPre", "WarningMsg" },
{ " user event. This will be removed from the plugin on " },
{ "2023-03-05", "WarningMsg" }
)
end
if opts.telescope and opts.telescope.after_source then
require("persisted.deprecate").write(
"----------\n",
"The use of the ",
{ "telescope.after_source", "ErrorMsg" },
" callback.\nPlease replace with the ",
{ "PersistedTelescopeLoadPost", "WarningMsg" },
{ " user event. This will be removed from the plugin on " },
{ "2023-03-05", "WarningMsg" }
)
end
end
end
return M

View File

@ -86,9 +86,7 @@ function M.load(opt)
if session then
if vim.fn.filereadable(session) ~= 0 then
vim.g.persisting_session = config.options.follow_cwd and nil or session
-- TODO: Alter this function call after deprecation notice ends
utils.load_session(session, config.options.before_source, config.options.after_source, config.options.silent)
--
utils.load_session(session, config.options.silent)
elseif type(config.options.on_autoload_no_session) == "function" then
config.options.on_autoload_no_session()
end
@ -131,37 +129,26 @@ end
function M.save(opt)
opt = opt or {}
-- If the user has stopped the session, then do not save
-- Do not save the session if the user has manually stopped it
if vim.g.persisting == false then
return
end
-- Autosave config option takes priority unless it's overriden
-- Do not save the session if autosave is turned off...unless it's overriden
if not config.options.autosave and not opt.override then
return
end
-- Do not save the session if the callback returns false
if type(config.options.should_autosave) == "function" and not config.options.should_autosave() then
return
end
--TODO: Remove this after deprecation notice period ends
if type(config.options.before_save) == "function" then
config.options.before_save()
end
--
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePre" })
vim.cmd("mks! " .. e(vim.g.persisting_session or get_current()))
vim.g.persisting = true
--TODO: Remove this after deprecation notice period ends
if type(config.options.after_save) == "function" then
config.options.after_save()
end
--
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePost" })
end

View File

@ -61,19 +61,9 @@ end
---Load the given session
---@param session string
---@param before_callback function
---@param after_callback function
---@param silent boolean Load the session silently?
---@return nil|string
function M.load_session(session, before_callback, after_callback, silent)
-- TODO: Clean up this function call after deprecation notice ends
--TODO: Remove this after deprecation notice period ends
if type(before_callback) == "function" then
before_callback()
end
--
function M.load_session(session, silent)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPre", data = session })
local ok, result = pcall(vim.cmd, (silent and "silent " or "") .. "source " .. e(session))
@ -81,12 +71,6 @@ function M.load_session(session, before_callback, after_callback, silent)
return echoerr("Error loading the session! ", result)
end
--TODO: Remove this after deprecation notice period ends
if type(after_callback) == "function" then
after_callback()
end
--
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPost", data = session })
end

View File

@ -18,14 +18,7 @@ M.load_session = function(session, config)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPre", data = session })
vim.schedule(function()
-- TODO: clean up this function call after deprecation notice ends
utils.load_session(
session.file_path,
config.telescope.before_source and config.telescope.before_source(session) or _,
config.telescope.after_source and config.telescope.after_source(session) or _,
config.silent
--
)
utils.load_session(session.file_path, config.silent)
end)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPost", data = session })

View File

@ -10,7 +10,7 @@ local telescope_opts = {}
local function search_sessions(opts)
local config = require("persisted.config").options
opts = vim.tbl_extend('force', telescope_opts, opts or {})
opts = vim.tbl_extend("force", telescope_opts, opts or {})
pickers
.new(opts, {
@ -21,7 +21,7 @@ local function search_sessions(opts)
local refresh_sessions = function()
local picker = action_state.get_current_picker(prompt_bufnr)
picker:refresh(_finders.session_finder(require("persisted").list()), {
reset_prompt = config.telescope.reset_prompt_after_deletion
reset_prompt = config.telescope.reset_prompt_after_deletion,
})
end