@@ -10,6 +10,7 @@ local uv = vim.uv or vim.loop
10
10
11
11
--- Fire an event
12
12
--- @param event string
13
+ --- @return nil
13
14
function M .fire (event )
14
15
vim .api .nvim_exec_autocmds (" User" , { pattern = " Persisted" .. event })
15
16
end
34
35
35
36
--- Automatically load the session for the current dir
36
37
--- @param opts ? { force ?: boolean }
38
+ --- @return nil
37
39
function M .autoload (opts )
38
40
opts = opts or {}
39
41
48
50
49
51
--- Load a session
50
52
--- @param opts ? { last ?: boolean , autoload ?: boolean , session ?: string }
53
+ --- @return nil
51
54
function M .load (opts )
52
55
opts = opts or {}
53
56
@@ -80,6 +83,7 @@ function M.load(opts)
80
83
end
81
84
82
85
--- Start a session
86
+ --- @return nil
83
87
function M .start ()
84
88
vim .api .nvim_create_autocmd (" VimLeavePre" , {
85
89
group = vim .api .nvim_create_augroup (" Persisted" , { clear = true }),
@@ -93,6 +97,7 @@ function M.start()
93
97
end
94
98
95
99
--- Stop a session
100
+ --- @return nil
96
101
function M .stop ()
97
102
vim .g .persisting = false
98
103
pcall (vim .api .nvim_del_augroup_by_name , " Persisted" )
101
106
102
107
--- Save the session
103
108
--- @param opts ? { force ?: boolean , session ?: string }
109
+ --- @return nil
104
110
function M .save (opts )
105
111
opts = opts or {}
106
112
@@ -115,11 +121,12 @@ function M.save(opts)
115
121
M .fire (" SavePost" )
116
122
end
117
123
118
- --- Delete the current session
119
- --- @param opts ? { session ?: string }
124
+ --- Delete a session
125
+ --- @param opts ? { path ?: string }
126
+ --- @return nil
120
127
function M .delete (opts )
121
128
opts = opts or {}
122
- local session = opts .session or M .current ()
129
+ local session = opts .path or M .current ()
123
130
124
131
if session and uv .fs_stat (session ) ~= 0 then
125
132
M .fire (" DeletePre" )
@@ -141,9 +148,9 @@ function M.branch()
141
148
end
142
149
143
150
--- Select a session to load
151
+ --- @return nil
144
152
function M .select ()
145
- --- @type { session : string , dir : string , branch ?: string } []
146
- local items = {}
153
+ local items = {} --- @type { session : string , dir : string , branch ?: string } []
147
154
local found = {} --- @type table<string , boolean>
148
155
for _ , session in ipairs (M .list ()) do
149
156
if uv .fs_stat (session ) then
@@ -160,7 +167,7 @@ function M.select()
160
167
end
161
168
end
162
169
vim .ui .select (items , {
163
- prompt = " Select a session: " ,
170
+ prompt = " Load a session: " ,
164
171
format_item = function (item )
165
172
local name = vim .fn .fnamemodify (item .dir , " :p:~" )
166
173
if item .branch then
@@ -170,13 +177,16 @@ function M.select()
170
177
end ,
171
178
}, function (item )
172
179
if item then
180
+ M .fire (" SelectPre" )
173
181
vim .fn .chdir (item .dir )
174
182
M .load ()
183
+ M .fire (" SelectPost" )
175
184
end
176
185
end )
177
186
end
178
187
179
188
--- Determines whether to load, start or stop a session
189
+ --- @return nil
180
190
function M .toggle ()
181
191
M .fire (" Toggle" )
182
192
if vim .g .persisting == nil then
219
229
220
230
--- Setup the plugin
221
231
--- @param opts ? table
232
+ --- @return nil
222
233
function M .setup (opts )
223
234
config .setup (opts )
224
235
0 commit comments