Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass target_tabpage to ext.on_save #41

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ To create an extension, create a file in your runtimepath at `lua/resession/exte
local M = {}

---Get the saved data for this extension
---@param opts resession.Extension.OnSaveOpts Information about the session being saved
---@return any
M.on_save = function()
M.on_save = function(opts)
return {}
end

Expand Down
4 changes: 3 additions & 1 deletion lua/resession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ local function save(name, opts, target_tabpage)
for ext_name, ext_config in pairs(config.extensions) do
local ext = util.get_extension(ext_name)
if ext and ext.on_save and (ext_config.enable_in_tab or not target_tabpage) then
local ok, ext_data = pcall(ext.on_save)
local ok, ext_data = pcall(ext.on_save, {
tabpage = target_tabpage,
})
if ok then
data[ext_name] = ext_data
else
Expand Down
5 changes: 4 additions & 1 deletion lua/resession/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
---@field silence_errors? boolean Don't error when trying to load a missing session
---@field dir? string Name of directory to load from (overrides config.dir)

---@class (exact) resession.Extension.OnSaveOpts
---@field tabpage integer? The tabpage being saved, if in a tab-scoped session

---@class (exact) resession.Extension
---@field on_save? fun():any
---@field on_save? fun(opts: resession.Extension.OnSaveOpts):any
---@field on_pre_load? fun(data: any)
---@field on_post_load? fun(data: any)
---@field config? fun(options: table)
Expand Down