-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add native provider and default to it
- Loading branch information
Showing
2 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local M = {} | ||
|
||
local notify = require "yacp.notify" | ||
local exec = require "yacp.exec" | ||
local palette = require "yacp.palette" | ||
|
||
local function make_select_entries(p) | ||
local entries = {} | ||
for _, entry in ipairs(p) do | ||
table.insert(entries, entry.name) | ||
end | ||
return entries | ||
end | ||
|
||
local function find_command(p, name) | ||
for _, entry in ipairs(p) do | ||
if entry.name == name then | ||
return entry.cmd | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
function M.yacp(opts) | ||
local p = palette.list() | ||
if vim.tbl_isempty(palette) then | ||
notify.of_error "Empty command palette" | ||
return | ||
end | ||
local entries = make_select_entries(p) | ||
|
||
local defaults = { | ||
prompt = "", | ||
} | ||
|
||
opts = vim.tbl_deep_extend("keep", opts or {}, defaults) | ||
|
||
vim.ui.select(entries, opts, function(choice) | ||
local cmd = find_command(p, choice) | ||
if cmd ~= nil then | ||
exec.exec(cmd) | ||
end | ||
end) | ||
end | ||
|
||
return M |