Skip to content

Commit 48a2073

Browse files
committed
Add native provider and default to it
1 parent c37af2e commit 48a2073

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

lua/yacp/init.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local provider = nil
88
local providers = {
99
fzf = "yacp.providers.fzf",
1010
telescope = "yacp.providers.telescope",
11+
native = "yacp.providers.native",
1112
}
1213

1314
local function is_valid_provider(name)
@@ -28,16 +29,18 @@ M.setup = function(opts)
2829
opts = opts or {}
2930

3031
if opts.provider == nil then
31-
notify.of_error "Missing provider setting"
32-
return
33-
elseif not is_valid_provider(opts.provider) then
32+
opts.provider = "native"
33+
end
34+
35+
if not is_valid_provider(opts.provider) then
3436
notify.of_error(
3537
"Invalid provider: "
3638
.. opts.provider
37-
.. ". Must be one of: 'fzf', 'telescope'."
39+
.. ". Must be one of: 'native', 'fzf', 'telescope'."
3840
)
3941
return
4042
end
43+
4144
provider = opts.provider
4245

4346
if opts.palette ~= nil then

lua/yacp/providers/native.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
local M = {}
2+
3+
local notify = require "yacp.notify"
4+
local exec = require "yacp.exec"
5+
local palette = require "yacp.palette"
6+
7+
local function make_select_entries(p)
8+
local entries = {}
9+
for _, entry in ipairs(p) do
10+
table.insert(entries, entry.name)
11+
end
12+
return entries
13+
end
14+
15+
local function find_command(p, name)
16+
for _, entry in ipairs(p) do
17+
if entry.name == name then
18+
return entry.cmd
19+
end
20+
end
21+
return nil
22+
end
23+
24+
function M.yacp(opts)
25+
local p = palette.list()
26+
if vim.tbl_isempty(palette) then
27+
notify.of_error "Empty command palette"
28+
return
29+
end
30+
local entries = make_select_entries(p)
31+
32+
local defaults = {
33+
prompt = "",
34+
}
35+
36+
opts = vim.tbl_deep_extend("keep", opts or {}, defaults)
37+
38+
vim.ui.select(entries, opts, function(choice)
39+
local cmd = find_command(p, choice)
40+
if cmd ~= nil then
41+
exec.exec(cmd)
42+
end
43+
end)
44+
end
45+
46+
return M

0 commit comments

Comments
 (0)