Skip to content

Commit 698c6aa

Browse files
committed
feat: add ability for finders to provide an options transformer
So that specific finders can override options dynamically/temporarily. For example, the finders in this commit have been updated to always show dotfiles, because that is the logical behavior for items that are not on the filesystem (leading dots only have that special meaning in the filesystem). Example: try searching for `netrwbook` (to find `.netrwbook`) in `:CommandTHelp` before and after this commit.
1 parent 2fcd91a commit 698c6aa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lua/wincent/commandt/init.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ local options_spec = {
4444
},
4545
optional = true,
4646
},
47+
options = {
48+
kind = 'function',
49+
optional = true,
50+
},
4751
command = {
4852
kind = {
4953
one_of = {
@@ -222,6 +226,15 @@ local options_spec = {
222226
end,
223227
}
224228

229+
-- Function that returns a copy of `options` with
230+
-- `always_show_dot_files = true` and `never_show_dot_files = false`.
231+
local force_dot_files = function(options)
232+
return merge(options, {
233+
always_show_dot_files = true,
234+
never_show_dot_files = false,
235+
})
236+
end
237+
225238
local default_options = {
226239
always_show_dot_files = false,
227240
finders = {
@@ -243,6 +256,7 @@ local default_options = {
243256
end
244257
return paths
245258
end,
259+
options = force_dot_files,
246260
},
247261
find = {
248262
command = function(directory, options)
@@ -347,6 +361,7 @@ local default_options = {
347361
-- context, see: https://github.com/autozimu/LanguageClient-neovim/pull/731
348362
vim.cmd('try | ' .. command .. ' ' .. item .. ' | catch /E434/ | endtry')
349363
end,
364+
options = force_dot_files,
350365
},
351366
line = {
352367
candidates = function()
@@ -366,6 +381,7 @@ local default_options = {
366381
local index = tonumber(item:sub(suffix))
367382
vim.api.nvim_win_set_cursor(0, { index, 0 })
368383
end,
384+
options = force_dot_files,
369385
},
370386
rg = {
371387
command = function(directory, options)
@@ -560,6 +576,12 @@ commandt.finder = function(name, directory)
560576
if config == nil then
561577
error('commandt.finder(): no finder registered with name ' .. tostring(name))
562578
end
579+
if config.options then
580+
-- Optionally transform options.
581+
local sanitized_options, errors = sanitize_options(config.options(options))
582+
report_errors(errors, 'commandt.finder()')
583+
options = sanitized_options
584+
end
563585
if directory ~= nil then
564586
directory = vim.trim(directory)
565587
end

0 commit comments

Comments
 (0)