This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from mrjones2014/matjones/25-fzf-lua-support
Add support for fzf-lua
- Loading branch information
Showing
9 changed files
with
189 additions
and
67 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
Binary file not shown.
Binary file not shown.
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,72 @@ | ||
local M = {} | ||
|
||
local cached_results = {} | ||
|
||
local function handle_selected(selected) | ||
if not selected or #selected ~= 1 or not cached_results or #cached_results < 1 then | ||
return | ||
end | ||
|
||
local matching_items = vim.tbl_filter(function(item) | ||
return item.display == selected[1] | ||
end, cached_results) | ||
if not matching_items or #matching_items < 1 then | ||
return | ||
end | ||
local selected_item = matching_items[1] | ||
local libdash = require('libdash_nvim') | ||
if selected_item.is_fallback then | ||
libdash.open_search_engine(selected_item.value) | ||
else | ||
libdash.query(selected_item.query, '', true) | ||
libdash.open_item(selected_item.value) | ||
end | ||
end | ||
|
||
local default_opts = { | ||
exec_empty_query = true, | ||
bang = false, | ||
actions = { | ||
default = handle_selected, | ||
}, | ||
} | ||
|
||
M.dash = function(opts) | ||
local fzf_lua = require('fzf-lua') | ||
opts = fzf_lua.config.normalize_opts(opts, default_opts) | ||
if not opts then | ||
return | ||
end | ||
|
||
opts.query = opts.initial_text or '' | ||
opts.prompt = 'Dash> ' | ||
opts.fzf_opts = { | ||
['--header'] = vim.fn.shellescape(require('dash.providers').build_picker_title(opts.bang or false)), | ||
} | ||
|
||
-- This gets called whenever input is changed | ||
-- Also gets called first run if `opts.exec_empty_query == true` | ||
local current_file_type = vim.bo.filetype | ||
opts._reload_action = function(query) | ||
if not query or #query == 0 then | ||
return {} | ||
end | ||
|
||
cached_results = require('libdash_nvim').query(query, current_file_type, opts.bang or false) | ||
local items = {} | ||
for _, item in pairs(cached_results) do | ||
table.insert(items, item.display) | ||
end | ||
return items | ||
end | ||
|
||
-- This sets all the required fzf arguments for `change:reload` callbacks | ||
opts = fzf_lua.core.set_fzf_interactive_cb(opts) | ||
|
||
coroutine.wrap(function() | ||
local selected = fzf_lua.core.fzf_files(opts) | ||
fzf_lua.actions.act(opts.actions, selected, opts) | ||
end)() | ||
end | ||
|
||
return M |
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,26 @@ | ||
local M = {} | ||
|
||
function M.build_picker_title(bang) | ||
local config = require('libdash_nvim').config | ||
local filetype = vim.bo.filetype | ||
local file_type_keywords = config.file_type_keywords[filetype] | ||
if bang or not file_type_keywords then | ||
return 'Dash' | ||
end | ||
|
||
if file_type_keywords == true then | ||
return 'Dash - filtering by: ' .. filetype | ||
end | ||
|
||
if type(file_type_keywords) == 'string' then | ||
return 'Dash - filtering by: ' .. file_type_keywords | ||
end | ||
|
||
if type(file_type_keywords) == 'table' then | ||
return 'Dash - filtering by: ' .. (vim.inspect(file_type_keywords)):gsub('\n', '') | ||
end | ||
|
||
return 'Dash' | ||
end | ||
|
||
return M |
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
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