Skip to content

Commit 180e99d

Browse files
committed
feat(session_picker): Fixes #68
1 parent 6625d18 commit 180e99d

File tree

5 files changed

+381
-52
lines changed

5 files changed

+381
-52
lines changed

lua/opencode/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ M.defaults = {
6969
accept_all = 'A',
7070
deny = 'd',
7171
},
72+
session_picker = {
73+
delete_session = { '<C-d>' },
74+
},
7275
},
7376
ui = {
7477
position = 'right',

lua/opencode/ui/file_picker.lua

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
local M = {}
2-
3-
local function get_best_picker()
4-
local config = require('opencode.config')
5-
6-
local preferred_picker = config.preferred_picker
7-
if preferred_picker and preferred_picker ~= '' then
8-
return preferred_picker
9-
end
10-
11-
if pcall(require, 'telescope') then
12-
return 'telescope'
13-
end
14-
if pcall(require, 'fzf-lua') then
15-
return 'fzf'
16-
end
17-
if pcall(require, 'mini.pick') then
18-
return 'mini.pick'
19-
end
20-
if pcall(require, 'snacks') then
21-
return 'snacks'
22-
end
23-
return nil
24-
end
2+
local picker = require('opencode.ui.picker')
253

264
local function format_file(path)
275
-- when path is something like: file.extension dir1/dir2 -> format to dir1/dir2/file.extension
@@ -146,9 +124,9 @@ local function snacks_picker_ui(callback, path)
146124
end
147125

148126
function M.pick(callback, path)
149-
local picker = get_best_picker()
127+
local picker_type = picker.get_best_picker()
150128

151-
if not picker then
129+
if not picker_type then
152130
return
153131
end
154132

@@ -158,13 +136,13 @@ function M.pick(callback, path)
158136
end
159137

160138
vim.schedule(function()
161-
if picker == 'telescope' then
139+
if picker_type == 'telescope' then
162140
telescope_ui(wrapped_callback, path)
163-
elseif picker == 'fzf' then
141+
elseif picker_type == 'fzf' then
164142
fzf_ui(wrapped_callback, path)
165-
elseif picker == 'mini.pick' then
143+
elseif picker_type == 'mini.pick' then
166144
mini_pick_ui(wrapped_callback, path)
167-
elseif picker == 'snacks' then
145+
elseif picker_type == 'snacks' then
168146
snacks_picker_ui(wrapped_callback, path)
169147
else
170148
callback(nil)

lua/opencode/ui/picker.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
local M = {}
2+
3+
function M.get_best_picker()
4+
local config = require('opencode.config')
5+
6+
local preferred_picker = config.preferred_picker
7+
if preferred_picker and preferred_picker ~= '' then
8+
return preferred_picker
9+
end
10+
11+
if pcall(require, 'telescope') then
12+
return 'telescope'
13+
end
14+
if pcall(require, 'fzf-lua') then
15+
return 'fzf'
16+
end
17+
if pcall(require, 'mini.pick') then
18+
return 'mini.pick'
19+
end
20+
if pcall(require, 'snacks') then
21+
return 'snacks'
22+
end
23+
return nil
24+
end
25+
26+
return M

0 commit comments

Comments
 (0)