Skip to content

Commit

Permalink
feat: pass target_tabpage to ext.on_save (#41)
Browse files Browse the repository at this point in the history
Allows extensions to determine if the session being saved is tab-scoped, and if so
what the current tabpage is.
  • Loading branch information
willothy authored Oct 8, 2023
1 parent c6a508e commit 6ce009e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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

0 comments on commit 6ce009e

Please sign in to comment.