-
Notifications
You must be signed in to change notification settings - Fork 19
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 #112 from Bleksak/main
Add fzf-lua as a picker
- Loading branch information
Showing
23 changed files
with
637 additions
and
106 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
File renamed without changes.
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,83 @@ | ||
local M = {} | ||
|
||
function M.gen_from_artisan(commands) | ||
local string_names = vim | ||
.iter(commands) | ||
:map(function(command) | ||
return command.name | ||
end) | ||
:totable() | ||
|
||
local command_hash = {} | ||
for _, command in ipairs(commands) do | ||
command_hash[command.name] = command | ||
end | ||
|
||
return string_names, command_hash | ||
end | ||
|
||
function M.gen_from_commands(commands) | ||
local string_names = vim | ||
.iter(commands) | ||
:map(function(command) | ||
return command.display | ||
end) | ||
:totable() | ||
|
||
local command_hash = {} | ||
for _, command in ipairs(commands) do | ||
command_hash[command.display] = command | ||
end | ||
|
||
return string_names, command_hash | ||
end | ||
|
||
function M.gen_from_history(history) | ||
local string_names = vim | ||
.iter(history) | ||
:map(function(command) | ||
return command.name | ||
end) | ||
:totable() | ||
|
||
local history_hash = {} | ||
for _, command in ipairs(history) do | ||
history_hash[command.name] = command | ||
end | ||
|
||
return string_names, history_hash | ||
end | ||
|
||
function M.gen_from_related(relations) | ||
local string_names = vim | ||
.iter(relations) | ||
:map(function(relation) | ||
return relation.class .. " " .. relation.type .. " " .. relation.extra_information | ||
end) | ||
:totable() | ||
|
||
local relation_hash = {} | ||
for _, relation in ipairs(relations) do | ||
relation_hash[relation.class .. " " .. relation.type .. " " .. relation.extra_information] = relation | ||
end | ||
|
||
return string_names, relation_hash | ||
end | ||
|
||
function M.gen_from_routes(routes) | ||
local string_names = vim | ||
.iter(routes) | ||
:map(function(route) | ||
return route.uri .. " " .. (route.name or "") | ||
end) | ||
:totable() | ||
|
||
local route_hash = {} | ||
for _, route in ipairs(routes) do | ||
route_hash[route.uri .. " " .. (route.name or "")] = route | ||
end | ||
|
||
return string_names, route_hash | ||
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,44 @@ | ||
local format_entry = require("laravel.pickers.fzf_lua.format_entry").gen_from_artisan | ||
local actions = require("laravel.pickers.common.actions") | ||
local fzf_exec = require("fzf-lua").fzf_exec | ||
local CommandPreviewer = require("laravel.pickers.fzf_lua.previewer").CommandPreviewer | ||
|
||
---@class LaravelFzfLuaArtisanPicker | ||
---@field commands_repository CommandsRepository | ||
local ui_artisan_picker = {} | ||
|
||
function ui_artisan_picker:new(cache_commands_repository) | ||
local instance = { | ||
commands_repository = cache_commands_repository, | ||
} | ||
setmetatable(instance, self) | ||
self.__index = self | ||
|
||
return instance | ||
end | ||
|
||
function ui_artisan_picker:run(opts) | ||
opts = opts or {} | ||
|
||
return self.commands_repository:all():thenCall(function(commands) | ||
local command_names, command_table = format_entry(commands) | ||
|
||
fzf_exec(command_names, { | ||
actions = { | ||
["default"] = function(selected) | ||
local command = command_table[selected[1]] | ||
actions.run(command) | ||
end, | ||
}, | ||
prompt = "Artisan > ", | ||
previewer = CommandPreviewer(command_table), | ||
fzf_opts = { | ||
["--preview-window"] = "nohidden,70%", | ||
}, | ||
}) | ||
end, function(error) | ||
vim.api.nvim_err_writeln(error) | ||
end) | ||
end | ||
|
||
return ui_artisan_picker |
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,61 @@ | ||
local format_entry = require("laravel.pickers.fzf_lua.format_entry").gen_from_commands | ||
local fzf_exec = require("fzf-lua").fzf_exec | ||
|
||
local commands_picker = {} | ||
|
||
function commands_picker:new(runner, options) | ||
local instance = { | ||
runner = runner, | ||
options = options, | ||
} | ||
setmetatable(instance, self) | ||
self.__index = self | ||
|
||
return instance | ||
end | ||
|
||
function commands_picker:run(opts) | ||
opts = opts or {} | ||
|
||
local commands = {} | ||
|
||
for command_name, group_commands in pairs(self.options:get().user_commands) do | ||
for name, details in pairs(group_commands) do | ||
table.insert(commands, { | ||
executable = command_name, | ||
name = name, | ||
display = string.format("[%s] %s", command_name, name), | ||
cmd = details.cmd, | ||
desc = details.desc, | ||
opts = details.opts or {}, | ||
}) | ||
end | ||
end | ||
|
||
if vim.tbl_isempty(commands) then | ||
vim.notify("No user command defined in the config", vim.log.levels.WARN, {}) | ||
return | ||
end | ||
|
||
local command_names, command_table = format_entry(commands) | ||
|
||
fzf_exec(command_names, { | ||
actions = { | ||
["default"] = function(selected) | ||
local command = command_table[selected[1]] | ||
self.runner:run(command.executable, command.cmd, command.opts) | ||
end, | ||
}, | ||
prompt = "User Commands > ", | ||
fzf_opts = { | ||
["--preview-window"] = "nohidden,70%", | ||
["--preview"] = function(selected) | ||
local command = command_table[selected[1]] | ||
|
||
return command.desc | ||
end | ||
}, | ||
}) | ||
end | ||
|
||
return commands_picker |
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,33 @@ | ||
local fzf_exec = require("fzf-lua").fzf_exec | ||
local format_entry = require("laravel.pickers.fzf_lua.format_entry").gen_from_history | ||
local app = require("laravel").app | ||
|
||
local history_picker = {} | ||
|
||
function history_picker:new(history) | ||
local instance = { | ||
history_provider = history, | ||
} | ||
setmetatable(instance, self) | ||
self.__index = self | ||
return instance | ||
end | ||
|
||
function history_picker:run(opts) | ||
opts = opts or {} | ||
|
||
local history = self.history_provider:get() | ||
local history_names, history_table = format_entry(history) | ||
|
||
fzf_exec(history_names, { | ||
actions = { | ||
["default"] = function(selected) | ||
local command = history_table[selected[1]] | ||
app("runner"):run(command.name, command.args, command.opts) | ||
end, | ||
}, | ||
prompt = "History > ", | ||
}) | ||
end | ||
|
||
return history_picker |
Oops, something went wrong.