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 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) 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 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 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 ignored_dirs = nil, -- table of dirs that are ignored for auto-saving and auto-loading
telescope = { -- options for the telescope extension 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 reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted
}, },
} }
@ -36,77 +25,6 @@ M.options = {}
function M.setup(opts) function M.setup(opts)
M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {}) M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {})
vim.fn.mkdir(M.options.save_dir, "p") 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 end
return M return M

View File

@ -3,36 +3,36 @@
--https://github.com/EdenEast/nightfox.nvim/blob/main/lua/nightfox/lib/deprecation.lua --https://github.com/EdenEast/nightfox.nvim/blob/main/lua/nightfox/lib/deprecation.lua
--] --]
local M = { local M = {
_list = { { "[Persisted.nvim]\n", "Question" }, { "The following have been " }, { "deprecated:\n", "WarningMsg" } }, _list = { { "[Persisted.nvim]\n", "Question" }, { "The following have been " }, { "deprecated:\n", "WarningMsg" } },
_has_registered = false, _has_registered = false,
} }
function M.write(...) function M.write(...)
for _, e in ipairs({ ... }) do for _, e in ipairs({ ... }) do
table.insert(M._list, type(e) == "string" and { e } or e) table.insert(M._list, type(e) == "string" and { e } or e)
end end
M._list[#M._list][1] = M._list[#M._list][1] .. "\n" M._list[#M._list][1] = M._list[#M._list][1] .. "\n"
if not M._has_registered then if not M._has_registered then
vim.cmd([[ vim.cmd([[
augroup PersistedDeprecations augroup PersistedDeprecations
au! au!
autocmd VimEnter * ++once lua require("persisted.deprecate").flush() autocmd VimEnter * ++once lua require("persisted.deprecate").flush()
augroup END augroup END
]]) ]])
M._has_registered = true M._has_registered = true
end end
end end
function M.flush() function M.flush()
M.write( M.write(
"----------\n", "----------\n",
"See ", "See ",
{ "https://github.com/olimorris/persisted.nvim/issues/51", "Title" }, { "https://github.com/olimorris/persisted.nvim/issues/51", "Title" },
" for more information." " for more information."
) )
vim.api.nvim_echo(M._list, true, {}) vim.api.nvim_echo(M._list, true, {})
end end
return M return M

View File

@ -86,9 +86,7 @@ function M.load(opt)
if session then if session then
if vim.fn.filereadable(session) ~= 0 then if vim.fn.filereadable(session) ~= 0 then
vim.g.persisting_session = config.options.follow_cwd and nil or session 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.silent)
utils.load_session(session, config.options.before_source, config.options.after_source, config.options.silent)
--
elseif type(config.options.on_autoload_no_session) == "function" then elseif type(config.options.on_autoload_no_session) == "function" then
config.options.on_autoload_no_session() config.options.on_autoload_no_session()
end end
@ -131,37 +129,26 @@ end
function M.save(opt) function M.save(opt)
opt = opt or {} 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 if vim.g.persisting == false then
return return
end 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 if not config.options.autosave and not opt.override then
return return
end 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 if type(config.options.should_autosave) == "function" and not config.options.should_autosave() then
return return
end 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.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePre" })
vim.cmd("mks! " .. e(vim.g.persisting_session or get_current())) vim.cmd("mks! " .. e(vim.g.persisting_session or get_current()))
vim.g.persisting = true 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" }) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePost" })
end end

View File

@ -61,19 +61,9 @@ end
---Load the given session ---Load the given session
---@param session string ---@param session string
---@param before_callback function
---@param after_callback function
---@param silent boolean Load the session silently? ---@param silent boolean Load the session silently?
---@return nil|string ---@return nil|string
function M.load_session(session, before_callback, after_callback, silent) function M.load_session(session, 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
--
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPre", data = session }) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPre", data = session })
local ok, result = pcall(vim.cmd, (silent and "silent " or "") .. "source " .. e(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) return echoerr("Error loading the session! ", result)
end 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 }) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPost", data = session })
end end

View File

@ -18,14 +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()
-- TODO: clean up this function call after deprecation notice ends utils.load_session(session.file_path, config.silent)
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
--
)
end) end)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPost", data = session }) 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 function search_sessions(opts)
local config = require("persisted.config").options 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 pickers
.new(opts, { .new(opts, {
@ -21,7 +21,7 @@ local function search_sessions(opts)
local refresh_sessions = function() local refresh_sessions = function()
local picker = action_state.get_current_picker(prompt_bufnr) local picker = action_state.get_current_picker(prompt_bufnr)
picker:refresh(_finders.session_finder(require("persisted").list()), { 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 end