File tree Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ local provider = nil
8
8
local providers = {
9
9
fzf = " yacp.providers.fzf" ,
10
10
telescope = " yacp.providers.telescope" ,
11
+ native = " yacp.providers.native" ,
11
12
}
12
13
13
14
local function is_valid_provider (name )
@@ -28,16 +29,18 @@ M.setup = function(opts)
28
29
opts = opts or {}
29
30
30
31
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
34
36
notify .of_error (
35
37
" Invalid provider: "
36
38
.. opts .provider
37
- .. " . Must be one of: 'fzf', 'telescope'."
39
+ .. " . Must be one of: 'native', ' fzf', 'telescope'."
38
40
)
39
41
return
40
42
end
43
+
41
44
provider = opts .provider
42
45
43
46
if opts .palette ~= nil then
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments