Skip to content

Commit d40473f

Browse files
author
don
committed
Refresh telescope picker after deleting a session file
1 parent 220ec71 commit d40473f

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

lua/seshi/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function M.defaults()
55
save_dir = vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/'),
66
autoload = true,
77
use_git_root = true,
8-
silent = false,
8+
silent = true,
99
telescope = {
1010
mappings = {
1111
delete_session = '<C-d>',

lua/telescope/_extensions/seshi.lua

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,53 @@ local action_state = require('telescope.actions.state')
77
local seshi = require('seshi')
88
local utils = require('seshi.utils')
99

10-
local function list_sessions()
11-
local sessions = {}
12-
local save_dir = seshi.options.save_dir
13-
local files = vim.fn.glob(save_dir .. '*', false, true)
10+
local function search_sessions(opts)
11+
opts = opts or {}
1412

15-
for _, file in ipairs(files) do
16-
local session_name = vim.fn.fnamemodify(file, ':t')
17-
local dir_path, branch = utils.split_session_filename(session_name)
18-
-- Decode the path and branch
19-
dir_path = utils.decode_path(dir_path)
20-
branch = branch and utils.decode_path(branch) or nil
13+
local function list_sessions()
14+
local sessions = {}
15+
local save_dir = seshi.options.save_dir
16+
local files = vim.fn.glob(save_dir .. '*', false, true)
2117

22-
table.insert(sessions, {
23-
name = session_name,
24-
file_path = file,
25-
dir_path = dir_path,
26-
branch = branch,
27-
})
28-
end
18+
for _, file in ipairs(files) do
19+
local session_name = vim.fn.fnamemodify(file, ':t')
20+
local dir_path, branch = utils.split_session_filename(session_name)
21+
-- Decode the path and branch
22+
dir_path = utils.decode_path(dir_path)
23+
branch = branch and utils.decode_path(branch) or nil
2924

30-
return sessions
31-
end
25+
table.insert(sessions, {
26+
name = session_name,
27+
file_path = file,
28+
dir_path = dir_path,
29+
branch = branch,
30+
})
31+
end
3232

33-
local function search_sessions(opts)
34-
opts = opts or {}
33+
return sessions
34+
end
35+
36+
local function make_finder()
37+
return finders.new_table({
38+
results = list_sessions(),
39+
entry_maker = function(entry)
40+
local display = entry.dir_path
41+
if entry.branch then
42+
display = display .. ' (' .. entry.branch .. ')'
43+
end
44+
return {
45+
value = entry,
46+
display = display,
47+
ordinal = entry.name,
48+
}
49+
end,
50+
})
51+
end
3552

3653
pickers
3754
.new(opts, {
3855
prompt_title = 'Sessions',
39-
finder = finders.new_table({
40-
results = list_sessions(),
41-
entry_maker = function(entry)
42-
local display = entry.dir_path
43-
if entry.branch then
44-
display = display .. ' (' .. entry.branch .. ')'
45-
end
46-
return {
47-
value = entry,
48-
display = display,
49-
ordinal = entry.name,
50-
}
51-
end,
52-
}),
56+
finder = make_finder(),
5357
sorter = conf.generic_sorter(opts),
5458
attach_mappings = function(prompt_bufnr, map)
5559
actions.select_default:replace(function()
@@ -63,6 +67,8 @@ local function search_sessions(opts)
6367
if selection then
6468
local file_path = selection.value.file_path
6569
seshi.delete_session(file_path)
70+
local current_picker = action_state.get_current_picker(prompt_bufnr)
71+
current_picker:refresh(make_finder(), { reset_prompt = false })
6672
end
6773
end)
6874
return true

0 commit comments

Comments
 (0)