-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fzf integration as an alternative to telescope - closes #701 #702
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local log = require("metals.log") | ||
local commands_table = require("metals.commands").commands_table | ||
|
||
local has_fzf, fzf = pcall(require, "fzf-lua") | ||
|
||
if not has_fzf then | ||
local msg = "fzf-lua must be installed to use this functionality (https://github.com/ibhagwan/fzf-lua)" | ||
log.error_and_show(msg) | ||
end | ||
|
||
local function run_entry(entry) | ||
local command = require("metals")[entry.id] | ||
local success, msg = pcall(command) | ||
if not success then | ||
vim.api.nvim_notify(msg, 2, {}) | ||
end | ||
end | ||
|
||
local function run_selected(label) | ||
for _, entry in ipairs(commands_table) do | ||
if entry.label == label then | ||
run_entry(entry) | ||
return | ||
end | ||
end | ||
end | ||
|
||
return function(opts) | ||
opts = opts or {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see one looking through the docs, but I wish there was a way to also include the description that would be shown but not considered when you search. Either way, maybe an improvement for later on if someone knows how to add that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only way I see is through a preview, as the fzf-lua menu entries are simple strings. |
||
opts.prompt = "Metals Commands> " | ||
opts.previewer = false | ||
opts.actions = { | ||
["default"] = function(sel) | ||
run_selected(sel[1]) | ||
end, | ||
} | ||
opts.winopts = { width = 40, height = 12, fullscreen = false } | ||
|
||
local labels = {} | ||
for _, entry in ipairs(commands_table) do | ||
table.insert(labels, entry.label) | ||
end | ||
|
||
return fzf.fzf_exec(labels, opts) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,4 +536,6 @@ M.commands = function() | |
end) | ||
end | ||
|
||
M.fzf_menu = require("fzf-lua._extensions.metals") | ||
|
||
return M |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I see what I wrote before you probably know since you touched this.