options refactor, slightly better startup time
This commit is contained in:
parent
2ed1a56102
commit
ea38de4d7c
@ -18,317 +18,304 @@ if M._has_devicons and not M._devicons.has_loaded() then
|
||||
M._devicons.setup()
|
||||
end
|
||||
|
||||
M.win_height = 0.85
|
||||
M.win_width = 0.80
|
||||
M.win_row = 0.30
|
||||
M.win_col = 0.50
|
||||
M.win_border = true
|
||||
M.default_prompt = '> '
|
||||
M.fzf_bin = nil
|
||||
M.fzf_layout = 'reverse'
|
||||
M.preview_cmd = nil -- auto detect head|bat
|
||||
M.preview_border = 'border'
|
||||
M.preview_wrap = 'nowrap'
|
||||
M.preview_opts = 'nohidden'
|
||||
M.preview_vertical = 'down:45%'
|
||||
M.preview_horizontal = 'right:60%'
|
||||
M.preview_layout = 'flex'
|
||||
M.flip_columns = 120
|
||||
M.bat_theme = nil
|
||||
M.bat_opts = "--italic-text=always --style=numbers,changes --color always"
|
||||
|
||||
M.files = {
|
||||
prompt = '> ',
|
||||
cmd = nil, -- default: auto detect find|fd
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = true,
|
||||
git_diff_cmd = "git diff --name-status --relative HEAD",
|
||||
git_untracked_cmd = "git ls-files --exclude-standard --others",
|
||||
find_opts = "-type f -printf '%P\n'",
|
||||
fd_opts =
|
||||
[[--color never --type f --hidden --follow ]] ..
|
||||
[[--exclude .git --exclude node_modules --exclude '*.pyc']],
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
}
|
||||
}
|
||||
|
||||
M.grep = {
|
||||
prompt = 'Rg> ',
|
||||
input_prompt = 'Grep For> ',
|
||||
cmd = nil, -- default: auto detect rg|grep
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = true,
|
||||
git_diff_cmd = M.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.files.git_untracked_cmd,
|
||||
grep_opts = "--line-number --recursive --color=auto",
|
||||
rg_opts = "--column --line-number --no-heading --color=always --smart-case",
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
}
|
||||
}
|
||||
|
||||
M.oldfiles = {
|
||||
prompt = 'History> ',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
git_diff_cmd = M.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.files.git_untracked_cmd,
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
}
|
||||
}
|
||||
|
||||
M.quickfix = {
|
||||
prompt = 'Quickfix> ',
|
||||
separator = '▏',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
git_diff_cmd = M.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.files.git_untracked_cmd,
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
}
|
||||
}
|
||||
|
||||
M.loclist = {
|
||||
prompt = 'Locations> ',
|
||||
separator = '▏',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
git_diff_cmd = M.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.files.git_untracked_cmd,
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
}
|
||||
}
|
||||
|
||||
M.git = {
|
||||
prompt = 'GitFiles> ',
|
||||
cmd = "git ls-files --exclude-standard",
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = true,
|
||||
actions = M.files.actions,
|
||||
icons = {
|
||||
["M"] = { icon = "M", color = "yellow" },
|
||||
["D"] = { icon = "D", color = "red" },
|
||||
["A"] = { icon = "A", color = "green" },
|
||||
["?"] = { icon = "?", color = "magenta" },
|
||||
M.globals = {
|
||||
winopts = {
|
||||
win_height = 0.85,
|
||||
win_width = 0.80,
|
||||
win_row = 0.30,
|
||||
win_col = 0.50,
|
||||
win_border = true,
|
||||
window_on_create = function()
|
||||
-- Set popup background same as normal windows
|
||||
vim.cmd("set winhl=Normal:Normal")
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
M.buffers = {
|
||||
prompt = 'Buffers> ',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
sort_lastused = true,
|
||||
show_all_buffers = true,
|
||||
ignore_current_buffer = false,
|
||||
cwd_only = false,
|
||||
actions = {
|
||||
["default"] = actions.buf_edit,
|
||||
["ctrl-s"] = actions.buf_split,
|
||||
["ctrl-v"] = actions.buf_vsplit,
|
||||
["ctrl-t"] = actions.buf_tabedit,
|
||||
["ctrl-x"] = actions.buf_del,
|
||||
default_prompt = '> ',
|
||||
fzf_bin = nil,
|
||||
fzf_layout = 'reverse',
|
||||
fzf_binds = {
|
||||
-- <F2> toggle preview
|
||||
-- <F3> toggle preview text wrap
|
||||
-- <C-f>|<C-b> page down|up
|
||||
-- <C-d>|<C-u> half page down|up
|
||||
-- <S-d>|<S-u> preview page down|up
|
||||
-- <C-a> toggle select-all
|
||||
-- <C-u> clear query
|
||||
-- <C-q> send selected to quicfix
|
||||
-- <A-q> send all to quicfix
|
||||
'f2:toggle-preview',
|
||||
'f3:toggle-preview-wrap',
|
||||
'shift-down:preview-page-down',
|
||||
'shift-up:preview-page-up',
|
||||
'ctrl-d:half-page-down',
|
||||
'ctrl-u:half-page-up',
|
||||
'ctrl-f:page-down',
|
||||
'ctrl-b:page-up',
|
||||
'ctrl-a:toggle-all',
|
||||
'ctrl-l:clear-query',
|
||||
},
|
||||
preview_cmd = nil, -- auto detect head|bat
|
||||
preview_border = 'border',
|
||||
preview_wrap = 'nowrap',
|
||||
preview_opts = 'nohidden',
|
||||
preview_vertical = 'down:45%',
|
||||
preview_horizontal = 'right:60%',
|
||||
preview_layout = 'flex',
|
||||
flip_columns = 120,
|
||||
bat_theme = nil,
|
||||
bat_opts = "--italic-text=always --style=numbers,changes --color always",
|
||||
files = {
|
||||
prompt = '> ',
|
||||
cmd = nil, -- default: auto detect find|fd
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = true,
|
||||
git_diff_cmd = "git diff --name-status --relative HEAD",
|
||||
git_untracked_cmd = "git ls-files --exclude-standard --others",
|
||||
find_opts = "-type f -printf '%P\n'",
|
||||
fd_opts =
|
||||
[[--color never --type f --hidden --follow ]] ..
|
||||
[[--exclude .git --exclude node_modules --exclude '*.pyc']],
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
M.colorschemes = {
|
||||
prompt = 'Colorschemes> ',
|
||||
live_preview = true,
|
||||
-- Must construct our opts table in stages
|
||||
-- so we can reference 'M.globals.files'
|
||||
M.globals.git = {
|
||||
prompt = 'GitFiles> ',
|
||||
cmd = "git ls-files --exclude-standard",
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = true,
|
||||
actions = M.globals.files.actions,
|
||||
icons = {
|
||||
["M"] = { icon = "M", color = "yellow" },
|
||||
["D"] = { icon = "D", color = "red" },
|
||||
["A"] = { icon = "A", color = "green" },
|
||||
["?"] = { icon = "?", color = "magenta" },
|
||||
},
|
||||
}
|
||||
M.globals.grep = {
|
||||
prompt = 'Rg> ',
|
||||
input_prompt = 'Grep For> ',
|
||||
cmd = nil, -- default: auto detect rg|grep
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = true,
|
||||
git_diff_cmd = M.globals.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.globals.files.git_untracked_cmd,
|
||||
grep_opts = "--line-number --recursive --color=auto",
|
||||
rg_opts = "--column --line-number --no-heading --color=always --smart-case",
|
||||
actions = {
|
||||
["default"] = actions.colorscheme,
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
},
|
||||
winopts = {
|
||||
win_height = 0.55,
|
||||
win_width = 0.50,
|
||||
},
|
||||
}
|
||||
|
||||
M.helptags = {
|
||||
prompt = 'Help> ',
|
||||
actions = {
|
||||
["default"] = actions.help,
|
||||
["ctrl-s"] = actions.help,
|
||||
["ctrl-v"] = actions.help_vert,
|
||||
["ctrl-t"] = actions.help_tab,
|
||||
},
|
||||
}
|
||||
|
||||
M.manpages = {
|
||||
prompt = 'Man> ',
|
||||
cmd = "man -k .",
|
||||
actions = {
|
||||
["default"] = actions.man,
|
||||
["ctrl-s"] = actions.man,
|
||||
["ctrl-v"] = actions.man_vert,
|
||||
["ctrl-t"] = actions.man_tab,
|
||||
},
|
||||
}
|
||||
|
||||
M.lsp = {
|
||||
prompt = '> ',
|
||||
}
|
||||
M.globals.oldfiles = {
|
||||
prompt = 'History> ',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
lsp_icons = true,
|
||||
severity = "hint",
|
||||
actions = M.files.actions,
|
||||
icons = {
|
||||
["Error"] = { icon = "", color = "red" }, -- error
|
||||
["Warning"] = { icon = "", color = "yellow" }, -- warning
|
||||
["Information"] = { icon = "", color = "blue" }, -- info
|
||||
["Hint"] = { icon = "", color = "magenta" }, -- hint
|
||||
},
|
||||
}
|
||||
|
||||
M.builtin = {
|
||||
prompt = 'Builtin> ',
|
||||
winopts = {
|
||||
win_height = 0.65,
|
||||
win_width = 0.50,
|
||||
},
|
||||
git_diff_cmd = M.globals.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.globals.files.git_untracked_cmd,
|
||||
actions = {
|
||||
["default"] = actions.run_builtin,
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
},
|
||||
}
|
||||
M.globals.quickfix = {
|
||||
prompt = 'Quickfix> ',
|
||||
separator = '▏',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
git_diff_cmd = M.globals.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.globals.files.git_untracked_cmd,
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
},
|
||||
}
|
||||
M.globals.loclist = {
|
||||
prompt = 'Locations> ',
|
||||
separator = '▏',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
git_diff_cmd = M.globals.files.git_diff_cmd,
|
||||
git_untracked_cmd = M.globals.files.git_untracked_cmd,
|
||||
actions = {
|
||||
["default"] = actions.file_edit,
|
||||
["ctrl-s"] = actions.file_split,
|
||||
["ctrl-v"] = actions.file_vsplit,
|
||||
["ctrl-t"] = actions.file_tabedit,
|
||||
["ctrl-q"] = actions.file_sel_to_qf,
|
||||
},
|
||||
}
|
||||
M.globals.buffers = {
|
||||
prompt = 'Buffers> ',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
sort_lastused = true,
|
||||
show_all_buffers = true,
|
||||
ignore_current_buffer = false,
|
||||
cwd_only = false,
|
||||
actions = {
|
||||
["default"] = actions.buf_edit,
|
||||
["ctrl-s"] = actions.buf_split,
|
||||
["ctrl-v"] = actions.buf_vsplit,
|
||||
["ctrl-t"] = actions.buf_tabedit,
|
||||
["ctrl-x"] = actions.buf_del,
|
||||
},
|
||||
}
|
||||
M.globals.colorschemes = {
|
||||
prompt = 'Colorschemes> ',
|
||||
live_preview = true,
|
||||
actions = {
|
||||
["default"] = actions.colorscheme,
|
||||
},
|
||||
winopts = {
|
||||
win_height = 0.55,
|
||||
win_width = 0.50,
|
||||
},
|
||||
}
|
||||
M.globals.helptags = {
|
||||
prompt = 'Help> ',
|
||||
actions = {
|
||||
["default"] = actions.help,
|
||||
["ctrl-s"] = actions.help,
|
||||
["ctrl-v"] = actions.help_vert,
|
||||
["ctrl-t"] = actions.help_tab,
|
||||
},
|
||||
}
|
||||
M.globals.manpages = {
|
||||
prompt = 'Man> ',
|
||||
cmd = "man -k .",
|
||||
actions = {
|
||||
["default"] = actions.man,
|
||||
["ctrl-s"] = actions.man,
|
||||
["ctrl-v"] = actions.man_vert,
|
||||
["ctrl-t"] = actions.man_tab,
|
||||
},
|
||||
}
|
||||
M.globals.lsp = {
|
||||
prompt = '> ',
|
||||
file_icons = true and M._has_devicons,
|
||||
color_icons = true,
|
||||
git_icons = false,
|
||||
lsp_icons = true,
|
||||
severity = "hint",
|
||||
actions = M.globals.files.actions,
|
||||
icons = {
|
||||
["Error"] = { icon = "", color = "red" }, -- error
|
||||
["Warning"] = { icon = "", color = "yellow" }, -- warning
|
||||
["Information"] = { icon = "", color = "blue" }, -- info
|
||||
["Hint"] = { icon = "", color = "magenta" }, -- hint
|
||||
},
|
||||
}
|
||||
M.globals.builtin = {
|
||||
prompt = 'Builtin> ',
|
||||
winopts = {
|
||||
win_height = 0.65,
|
||||
win_width = 0.50,
|
||||
},
|
||||
actions = {
|
||||
["default"] = actions.run_builtin,
|
||||
},
|
||||
}
|
||||
M.globals.file_icon_colors = {
|
||||
["lua"] = "blue",
|
||||
["vim"] = "green",
|
||||
["sh"] = "cyan",
|
||||
["zsh"] = "cyan",
|
||||
["bash"] = "cyan",
|
||||
["py"] = "green",
|
||||
["md"] = "yellow",
|
||||
["c"] = "blue",
|
||||
["cpp"] = "blue",
|
||||
["h"] = "magenta",
|
||||
["hpp"] = "magenta",
|
||||
["js"] = "blue",
|
||||
["ts"] = "cyan",
|
||||
["tsx"] = "cyan",
|
||||
["css"] = "magenta",
|
||||
["yml"] = "yellow",
|
||||
["yaml"] = "yellow",
|
||||
["json"] = "yellow",
|
||||
["toml"] = "yellow",
|
||||
["conf"] = "yellow",
|
||||
["build"] = "red",
|
||||
["txt"] = "white",
|
||||
["gif"] = "green",
|
||||
["jpg"] = "green",
|
||||
["png"] = "green",
|
||||
["svg"] = "green",
|
||||
["sol"] = "red",
|
||||
["desktop"] = "magenta",
|
||||
}
|
||||
|
||||
-- <F2> toggle preview
|
||||
-- <F3> toggle preview text wrap
|
||||
-- <C-f>|<C-b> page down|up
|
||||
-- <C-d>|<C-u> half page down|up
|
||||
-- <S-d>|<S-u> preview page down|up
|
||||
-- <C-a> toggle select-all
|
||||
-- <C-u> clear query
|
||||
-- <C-q> send selected to quicfix
|
||||
-- <A-q> send all to quicfix
|
||||
M.fzf_binds = {
|
||||
'f2:toggle-preview',
|
||||
'f3:toggle-preview-wrap',
|
||||
'shift-down:preview-page-down',
|
||||
'shift-up:preview-page-up',
|
||||
'ctrl-d:half-page-down',
|
||||
'ctrl-u:half-page-up',
|
||||
'ctrl-f:page-down',
|
||||
'ctrl-b:page-up',
|
||||
'ctrl-a:toggle-all',
|
||||
'ctrl-l:clear-query',
|
||||
}
|
||||
|
||||
M.file_icon_colors = {
|
||||
["lua"] = "blue",
|
||||
["vim"] = "green",
|
||||
["sh"] = "cyan",
|
||||
["zsh"] = "cyan",
|
||||
["bash"] = "cyan",
|
||||
["py"] = "green",
|
||||
["md"] = "yellow",
|
||||
["c"] = "blue",
|
||||
["cpp"] = "blue",
|
||||
["h"] = "magenta",
|
||||
["hpp"] = "magenta",
|
||||
["js"] = "blue",
|
||||
["ts"] = "cyan",
|
||||
["tsx"] = "cyan",
|
||||
["css"] = "magenta",
|
||||
["yml"] = "yellow",
|
||||
["yaml"] = "yellow",
|
||||
["json"] = "yellow",
|
||||
["toml"] = "yellow",
|
||||
["conf"] = "yellow",
|
||||
["build"] = "red",
|
||||
["txt"] = "white",
|
||||
["gif"] = "green",
|
||||
["jpg"] = "green",
|
||||
["png"] = "green",
|
||||
["svg"] = "green",
|
||||
["sol"] = "red",
|
||||
["desktop"] = "magenta",
|
||||
}
|
||||
|
||||
|
||||
M.window_on_create = function()
|
||||
-- Set popup background same as normal windows
|
||||
vim.cmd("set winhl=Normal:Normal")
|
||||
end
|
||||
|
||||
M.winopts = function(opts)
|
||||
|
||||
opts = M.getopts(opts, M, {
|
||||
"win_height", "win_width",
|
||||
"win_row", "win_col", "win_border",
|
||||
"window_on_create",
|
||||
"winopts_raw",
|
||||
})
|
||||
if not opts then opts = {} end
|
||||
if not opts.winopts then opts.winopts = {} end
|
||||
opts.winopts = vim.tbl_deep_extend("keep", opts.winopts, M.globals.winopts)
|
||||
opts.winopts_raw = opts.winopts_raw or M.globals.winopts_raw
|
||||
|
||||
local raw = {}
|
||||
if opts.winopts_raw and type(opts.winopts_raw) == "function" then
|
||||
raw = opts.winopts_raw()
|
||||
end
|
||||
|
||||
local height = raw.height or math.floor(vim.o.lines * opts.win_height)
|
||||
local width = raw.width or math.floor(vim.o.columns * opts.win_width)
|
||||
local row = raw.row or math.floor((vim.o.lines - height) * opts.win_row)
|
||||
local col = raw.col or math.floor((vim.o.columns - width) * opts.win_col)
|
||||
local winopts = opts.winopts
|
||||
local height = raw.height or math.floor(vim.o.lines * winopts.win_height)
|
||||
local width = raw.width or math.floor(vim.o.columns * winopts.win_width)
|
||||
local row = raw.row or math.floor((vim.o.lines - height) * winopts.win_row)
|
||||
local col = raw.col or math.floor((vim.o.columns - width) * winopts.win_col)
|
||||
|
||||
return {
|
||||
-- style = 'minimal',
|
||||
height = height, width = width, row = row, col = col,
|
||||
border = raw.border or opts.win_border,
|
||||
window_on_create = raw.window_on_create or opts.window_on_create
|
||||
border = raw.border or winopts.win_border,
|
||||
window_on_create = raw.window_on_create or winopts.window_on_create
|
||||
}
|
||||
end
|
||||
|
||||
M.preview_window = function()
|
||||
local o = M.globals
|
||||
local preview_veritcal = string.format('%s:%s:%s:%s',
|
||||
M.preview_opts, M.preview_border, M.preview_wrap, M.preview_vertical)
|
||||
o.preview_opts, o.preview_border, o.preview_wrap, o.preview_vertical)
|
||||
local preview_horizontal = string.format('%s:%s:%s:%s',
|
||||
M.preview_opts, M.preview_border, M.preview_wrap, M.preview_horizontal)
|
||||
if M.preview_layout == "vertical" then
|
||||
o.preview_opts, o.preview_border, o.preview_wrap, o.preview_horizontal)
|
||||
if o.preview_layout == "vertical" then
|
||||
return preview_veritcal
|
||||
elseif M.preview_layout == "flex" then
|
||||
return utils._if(vim.o.columns>M.flip_columns, preview_horizontal, preview_veritcal)
|
||||
elseif o.preview_layout == "flex" then
|
||||
return utils._if(vim.o.columns>o.flip_columns, preview_horizontal, preview_veritcal)
|
||||
else
|
||||
return preview_horizontal
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- called to merge caller opts and default config
|
||||
-- before calling a provider method
|
||||
function M.getopts(opts, cfg, keys)
|
||||
function M.normalize_opts(opts, defaults)
|
||||
if not opts then opts = {} end
|
||||
if keys then
|
||||
for _, k in ipairs(keys) do
|
||||
if opts[k] == nil then opts[k] = cfg[k] end
|
||||
end
|
||||
opts = vim.tbl_deep_extend("keep", opts, defaults)
|
||||
if defaults.winopts then
|
||||
if not opts.winopts then opts.winopts = {} end
|
||||
opts.winopts = vim.tbl_deep_extend("keep", opts.winopts, defaults.winopts)
|
||||
end
|
||||
return opts
|
||||
end
|
||||
|
@ -16,12 +16,12 @@ M.get_devicon = function(file, ext)
|
||||
return icon
|
||||
end
|
||||
|
||||
M.preview_cmd = function(opts, cfg)
|
||||
M.preview_cmd = function(opts)
|
||||
opts = opts or {}
|
||||
opts.filespec = opts.filespec or '{}'
|
||||
opts.preview_cmd = opts.preview_cmd or cfg.preview_cmd
|
||||
opts.preview_cmd = opts.preview_cmd or config.globals.preview_cmd
|
||||
opts.preview_args = opts.preview_args or ''
|
||||
opts.bat_opts = opts.bat_opts or cfg.bat_opts
|
||||
opts.bat_opts = opts.bat_opts or config.globals.bat_opts
|
||||
local preview = nil
|
||||
if not opts.cwd then opts.cwd = ''
|
||||
elseif #opts.cwd > 0 then
|
||||
@ -44,23 +44,22 @@ M.preview_cmd = function(opts, cfg)
|
||||
end
|
||||
|
||||
M.build_fzf_cli = function(opts)
|
||||
local cfg = require'fzf-lua.config'
|
||||
opts.prompt = opts.prompt or cfg.default_prompt
|
||||
opts.prompt = opts.prompt or config.globals.default_prompt
|
||||
opts.preview_offset = opts.preview_offset or ''
|
||||
opts.fzf_bin = opts.fzf_bin or cfg.fzf_bin
|
||||
opts.fzf_bin = opts.fzf_bin or config.globals.fzf_bin
|
||||
local cli = string.format(
|
||||
[[ %s --layout=%s --bind=%s --prompt=%s]] ..
|
||||
[[ --preview-window='%s%s' --preview=%s]] ..
|
||||
[[ --height=100%% --ansi]] ..
|
||||
[[ %s %s %s %s]],
|
||||
opts.fzf_args or cfg.fzf_args or '',
|
||||
opts.fzf_layout or cfg.fzf_layout,
|
||||
opts.fzf_args or config.globals.fzf_args or '',
|
||||
opts.fzf_layout or config.globals.fzf_layout,
|
||||
utils._if(opts.fzf_binds, opts.fzf_binds,
|
||||
vim.fn.shellescape(table.concat(cfg.fzf_binds, ','))),
|
||||
vim.fn.shellescape(table.concat(config.globals.fzf_binds, ','))),
|
||||
vim.fn.shellescape(opts.prompt),
|
||||
utils._if(opts.preview_window, opts.preview_window, cfg.preview_window()),
|
||||
utils._if(opts.preview_window, opts.preview_window, config.preview_window()),
|
||||
utils._if(#opts.preview_offset>0, ":"..opts.preview_offset, ''),
|
||||
utils._if(opts.preview, opts.preview, M.preview_cmd(opts, cfg)),
|
||||
utils._if(opts.preview, opts.preview, M.preview_cmd(opts)),
|
||||
-- HACK: support skim (rust version of fzf)
|
||||
utils._if(opts.fzf_bin and opts.fzf_bin:find('sk')~=nil, "--inline-info", "--info=inline"),
|
||||
utils._if(actions.expect(opts.actions), actions.expect(opts.actions), ''),
|
||||
@ -73,7 +72,7 @@ end
|
||||
|
||||
local get_diff_files = function()
|
||||
local diff_files = {}
|
||||
local status = vim.fn.systemlist(config.files.git_diff_cmd)
|
||||
local status = vim.fn.systemlist(config.globals.files.git_diff_cmd)
|
||||
if not utils.shell_error() then
|
||||
for i = 1, #status do
|
||||
local split = vim.split(status[i], " ")
|
||||
@ -86,7 +85,7 @@ end
|
||||
|
||||
local get_untracked_files = function()
|
||||
local untracked_files = {}
|
||||
local status = vim.fn.systemlist(config.files.git_untracked_cmd)
|
||||
local status = vim.fn.systemlist(config.globals.files.git_untracked_cmd)
|
||||
if vim.v.shell_error == 0 then
|
||||
for i = 1, #status do
|
||||
untracked_files[status[i]] = "?"
|
||||
@ -128,7 +127,7 @@ M.make_entry_file = function(opts, x)
|
||||
local ext = path.extension(x)
|
||||
icon = M.get_devicon(x, ext)
|
||||
if opts.color_icons then
|
||||
icon = utils.ansi_codes[config.file_icon_colors[ext] or "dark_grey"](icon)
|
||||
icon = utils.ansi_codes[config.globals.file_icon_colors[ext] or "dark_grey"](icon)
|
||||
end
|
||||
prefix = prefix .. icon
|
||||
end
|
||||
@ -136,10 +135,10 @@ M.make_entry_file = function(opts, x)
|
||||
local filepath = x:match("^[^:]+")
|
||||
local indicator = get_git_indicator(filepath, opts.diff_files, opts.untracked_files)
|
||||
icon = indicator
|
||||
if config.git.icons[indicator] then
|
||||
icon = config.git.icons[indicator].icon
|
||||
if config.globals.git.icons[indicator] then
|
||||
icon = config.globals.git.icons[indicator].icon
|
||||
if opts.color_icons then
|
||||
icon = utils.ansi_codes[config.git.icons[indicator].color or "dark_grey"](icon)
|
||||
icon = utils.ansi_codes[config.globals.git.icons[indicator].color or "dark_grey"](icon)
|
||||
end
|
||||
end
|
||||
prefix = prefix .. utils._if(#prefix>0, utils.nbsp, '') .. icon
|
||||
@ -179,7 +178,7 @@ M.fzf_files = function(opts)
|
||||
|
||||
local selected = fzf.fzf(opts.fzf_fn,
|
||||
M.build_fzf_cli(opts),
|
||||
config.winopts(opts.winopts))
|
||||
config.winopts(opts))
|
||||
|
||||
if opts.post_select_cb then
|
||||
opts.post_select_cb()
|
||||
|
@ -3,198 +3,36 @@ if not pcall(require, "fzf") then
|
||||
end
|
||||
|
||||
local fzf = require "fzf"
|
||||
local utils = require "fzf-lua.utils"
|
||||
local config = require "fzf-lua.config"
|
||||
|
||||
local M = {}
|
||||
|
||||
local getopt = function(opts, key, expected_type, default)
|
||||
if opts and opts[key] ~= nil then
|
||||
if expected_type == "any" or type(opts[key]) == expected_type then
|
||||
return opts[key]
|
||||
else
|
||||
utils.info(
|
||||
string.format("Expected '%s' for config option '%s', got '%s'",
|
||||
expected_type, key, type(opts[key]))
|
||||
)
|
||||
end
|
||||
elseif default ~= nil then
|
||||
return default
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local setopt = function(cfg, opts, key, type)
|
||||
cfg[tostring(key)] = getopt(opts, key, type, cfg[tostring(key)])
|
||||
end
|
||||
|
||||
local setopts = function(cfg, opts, tbl)
|
||||
for k, v in pairs(tbl) do
|
||||
setopt(cfg, opts, k, v)
|
||||
end
|
||||
end
|
||||
|
||||
local setopt_tbl = function(cfg, opts, key)
|
||||
if opts and opts[key] then
|
||||
for k, v in pairs(opts[key]) do
|
||||
if not cfg[key] then cfg[key] = {} end
|
||||
cfg[key][k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
setopts(config, opts, {
|
||||
win_height = "number",
|
||||
win_width = "number",
|
||||
win_row = "number",
|
||||
win_col = "number",
|
||||
win_border = "any", -- boolean|table (borderchars)
|
||||
winopts_raw = "function",
|
||||
default_prompt = "string",
|
||||
fzf_bin = "string",
|
||||
fzf_args = "string",
|
||||
fzf_layout = "string",
|
||||
fzf_binds = "table",
|
||||
preview_cmd = "string",
|
||||
preview_border = "string",
|
||||
preview_wrap = "string",
|
||||
preview_opts = "string",
|
||||
preview_vertical = "string",
|
||||
preview_horizontal = "string",
|
||||
preview_layout = "string",
|
||||
flip_columns = "number",
|
||||
window_on_create = "function",
|
||||
bat_theme = "string",
|
||||
bat_opts = "string",
|
||||
})
|
||||
setopts(config.files, opts.files, {
|
||||
prompt = "string",
|
||||
cmd = "string",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
fd_opts = "string",
|
||||
find_opts = "string",
|
||||
git_diff_cmd = "string",
|
||||
git_untracked_cmd = "string",
|
||||
})
|
||||
setopts(config.grep, opts.grep, {
|
||||
prompt = "string",
|
||||
input_prompt = "string",
|
||||
cmd = "string",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
rg_opts = "string",
|
||||
grep_opts = "string",
|
||||
git_diff_cmd = "string",
|
||||
git_untracked_cmd = "string",
|
||||
})
|
||||
setopts(config.oldfiles, opts.oldfiles, {
|
||||
prompt = "string",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
git_diff_cmd = "string",
|
||||
git_untracked_cmd = "string",
|
||||
cwd_only = "boolean",
|
||||
include_current_session = "boolean",
|
||||
})
|
||||
setopts(config.quickfix, opts.quickfix, {
|
||||
prompt = "string",
|
||||
cwd = "string",
|
||||
separator = "string",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
git_diff_cmd = "string",
|
||||
git_untracked_cmd = "string",
|
||||
})
|
||||
setopts(config.loclist, opts.loclist, {
|
||||
prompt = "string",
|
||||
cwd = "string",
|
||||
separator = "string",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
git_diff_cmd = "string",
|
||||
git_untracked_cmd = "string",
|
||||
})
|
||||
setopts(config.lsp, opts.lsp, {
|
||||
prompt = "string",
|
||||
cwd = "string",
|
||||
severity = "string",
|
||||
severity_exact = "string",
|
||||
severity_bound = "string",
|
||||
lsp_icons = "boolean",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
git_diff_cmd = "string",
|
||||
git_untracked_cmd = "string",
|
||||
})
|
||||
setopts(config.git, opts.git, {
|
||||
prompt = "string",
|
||||
cmd = "string",
|
||||
git_icons = "boolean",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
})
|
||||
setopts(config.buffers, opts.buffers, {
|
||||
prompt = "string",
|
||||
git_prompt = "string",
|
||||
file_icons = "boolean",
|
||||
color_icons = "boolean",
|
||||
sort_lastused = "boolean",
|
||||
show_all_buffers = "boolean",
|
||||
ignore_current_buffer = "boolean",
|
||||
cwd_only = "boolean",
|
||||
})
|
||||
setopts(config.colorschemes, opts.colorschemes, {
|
||||
prompt = "string",
|
||||
live_preview = "boolean",
|
||||
post_reset_cb = "function",
|
||||
})
|
||||
setopts(config.manpages, opts.manpages, {
|
||||
prompt = "string",
|
||||
cmd = "string",
|
||||
})
|
||||
setopts(config.helptags, opts.helptags, {
|
||||
prompt = "string",
|
||||
})
|
||||
setopts(config.builtin, opts.builtin, {
|
||||
prompt = "string",
|
||||
})
|
||||
-- table overrides without losing defaults
|
||||
for _, k in ipairs({
|
||||
"git", "files", "oldfiles", "buffers",
|
||||
"grep", "quickfix", "loclist", "lsp",
|
||||
"colorschemes", "helptags", "manpages",
|
||||
"builtin",
|
||||
}) do
|
||||
setopt_tbl(config[k], opts[k], "actions")
|
||||
setopt_tbl(config[k], opts[k], "winopts")
|
||||
local globals = vim.tbl_deep_extend("keep", opts, config.globals)
|
||||
-- backward compatibility before winopts was it's own struct
|
||||
for k, _ in pairs(globals.winopts) do
|
||||
if opts[k] ~= nil then globals.winopts[k] = opts[k] end
|
||||
end
|
||||
setopt_tbl(config.git, opts.git, "icons")
|
||||
setopt_tbl(config.lsp, opts.lsp, "icons")
|
||||
setopt_tbl(config, opts, "file_icon_colors")
|
||||
-- override the bat preview theme if set by caller
|
||||
if config.bat_theme and #config.bat_theme > 0 then
|
||||
vim.env.BAT_THEME = config.bat_theme
|
||||
if globals.bat_theme and #globals.bat_theme > 0 then
|
||||
vim.env.BAT_THEME = globals.bat_theme
|
||||
end
|
||||
-- reset default window opts if set by user
|
||||
fzf.default_window_options = config.winopts()
|
||||
-- set the fzf binary if set by the user
|
||||
if config.fzf_bin then
|
||||
if globals.fzf_bin ~= nil then
|
||||
if fzf.default_options ~= nil and
|
||||
vim.fn.executable(config.fzf_bin) == 1 then
|
||||
fzf.default_options.fzf_binary = config.fzf_bin
|
||||
vim.fn.executable(globals.fzf_bin) == 1 then
|
||||
fzf.default_options.fzf_binary = globals.fzf_bin
|
||||
else
|
||||
config.fzf_bin = nil
|
||||
globals.fzf_bin = nil
|
||||
end
|
||||
end
|
||||
-- reset our globals based on user opts
|
||||
-- this doesn't happen automatically
|
||||
config.globals = globals
|
||||
globals = nil
|
||||
-- _G.dump(config.globals)
|
||||
end
|
||||
|
||||
-- we usually send winopts with every fzf.fzf call
|
||||
|
@ -22,12 +22,7 @@ end
|
||||
|
||||
M.buffers = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.buffers, {
|
||||
"prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "sort_lastused",
|
||||
"show_all_buffers", "ignore_current_buffer",
|
||||
"cwd_only",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.buffers)
|
||||
|
||||
local act = action(function (items, fzf_lines, _)
|
||||
-- only preview first item
|
||||
@ -113,7 +108,7 @@ M.buffers = function(opts)
|
||||
local extension = path.extension(buf.info.name)
|
||||
buficon = core.get_devicon(buf.info.name, extension)
|
||||
if opts.color_icons then
|
||||
buficon = utils.ansi_codes[config.file_icon_colors[extension] or "dark_grey"](buficon) .. " "
|
||||
buficon = utils.ansi_codes[config.globals.file_icon_colors[extension] or "dark_grey"](buficon) .. " "
|
||||
end
|
||||
end
|
||||
local item_str = string.format("%s%s %s %s%s",
|
||||
|
@ -21,9 +21,7 @@ local M = {}
|
||||
|
||||
M.colorschemes = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.colorschemes, {
|
||||
"prompt", "actions", "winopts", "live_preview", "post_reset_cb",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.colorschemes)
|
||||
|
||||
coroutine.wrap(function ()
|
||||
local prev_act = action(function (args)
|
||||
@ -45,7 +43,7 @@ M.colorschemes = function(opts)
|
||||
|
||||
local selected = fzf.fzf(colors,
|
||||
core.build_fzf_cli(opts),
|
||||
config.winopts(opts.winopts))
|
||||
config.winopts(opts))
|
||||
|
||||
-- reset color scheme if live_preview is enabled
|
||||
-- and nothing or non-default action was selected
|
||||
|
@ -32,12 +32,9 @@ local get_files_cmd = function(opts)
|
||||
end
|
||||
|
||||
M.files = function(opts)
|
||||
opts = config.getopts(opts, config.files, {
|
||||
"cmd", "prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "git_icons",
|
||||
"fd_opts", "find_opts",
|
||||
})
|
||||
|
||||
opts = config.normalize_opts(opts, config.globals.files)
|
||||
-- _G.dump(opts)
|
||||
|
||||
local command = get_files_cmd(opts)
|
||||
|
||||
@ -55,10 +52,7 @@ M.git_files = function(opts)
|
||||
utils.info(unpack(output))
|
||||
return
|
||||
end
|
||||
opts = config.getopts(opts, config.git, {
|
||||
"cmd", "prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "git_icons",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.git)
|
||||
-- opts.cmd sets this to "git ls-files"
|
||||
return M.files(opts)
|
||||
end
|
||||
|
@ -40,15 +40,10 @@ end
|
||||
|
||||
M.grep = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.grep, {
|
||||
"cmd", "prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "git_icons",
|
||||
"search", "input_prompt",
|
||||
"rg_opts", "grep_opts",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.grep)
|
||||
|
||||
if opts.continue_last_search or opts.repeat_last_search then
|
||||
opts.search = config.grep.last_search
|
||||
opts.search = config._grep_last_search
|
||||
end
|
||||
|
||||
-- if user did not provide a search term
|
||||
@ -64,7 +59,7 @@ M.grep = function(opts)
|
||||
|
||||
-- save the search query so the use can
|
||||
-- call the same search again
|
||||
config.grep.last_search = opts.search
|
||||
config._grep_last_search = opts.search
|
||||
|
||||
local command = get_grep_cmd(opts, opts.search)
|
||||
|
||||
@ -124,25 +119,20 @@ end
|
||||
|
||||
M.live_grep = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.grep, {
|
||||
"cmd", "prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "git_icons",
|
||||
"search", "input_prompt",
|
||||
"rg_opts", "grep_opts",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.grep)
|
||||
|
||||
if opts.continue_last_search or opts.repeat_last_search then
|
||||
opts.search = config.grep.last_search
|
||||
opts.search = config._grep_last_search
|
||||
end
|
||||
|
||||
if opts.search and #opts.search>0 then
|
||||
-- save the search query so the use can
|
||||
-- call the same search again
|
||||
config.grep.last_search = opts.search
|
||||
config._grep_last_search = opts.search
|
||||
end
|
||||
|
||||
-- HACK: support skim (rust version of fzf)
|
||||
opts.fzf_bin = opts.fzf_bin or config.fzf_bin
|
||||
opts.fzf_bin = opts.fzf_bin or config.globals.fzf_bin
|
||||
if opts.fzf_bin and opts.fzf_bin:find('sk')~=nil then
|
||||
return M.live_grep_sk(opts)
|
||||
end
|
||||
@ -204,7 +194,7 @@ end
|
||||
|
||||
M.grep_curbuf = function(opts)
|
||||
if not opts then opts = {} end
|
||||
opts.rg_opts = config.grep.rg_opts .. " --with-filename"
|
||||
opts.rg_opts = config.globals.grep.rg_opts .. " --with-filename"
|
||||
opts.filename = vim.api.nvim_buf_get_name(0)
|
||||
if #opts.filename > 0 then
|
||||
opts.filename = path.relative(opts.filename, vim.loop.cwd())
|
||||
|
@ -14,8 +14,8 @@ local M = {}
|
||||
|
||||
local fzf_function = function (cb)
|
||||
local opts = {}
|
||||
opts.lang = config.helptags.lang or vim.o.helplang
|
||||
opts.fallback = utils._if(config.helptags.fallback ~= nil, config.helptags.fallback, true)
|
||||
opts.lang = config.globals.helptags.lang or vim.o.helplang
|
||||
opts.fallback = utils._if(config.globals.helptags.fallback ~= nil, config.globals.helptags.fallback, true)
|
||||
|
||||
local langs = vim.split(opts.lang, ',', true)
|
||||
if opts.fallback and not vim.tbl_contains(langs, 'en') then
|
||||
@ -97,9 +97,7 @@ end
|
||||
|
||||
M.helptags = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.helptags, {
|
||||
"prompt", "actions", "winopts",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.helptags)
|
||||
|
||||
coroutine.wrap(function ()
|
||||
|
||||
@ -111,7 +109,7 @@ M.helptags = function(opts)
|
||||
|
||||
local selected = fzf.fzf(fzf_function,
|
||||
core.build_fzf_cli(opts),
|
||||
config.winopts(opts.winopts))
|
||||
config.winopts(opts))
|
||||
|
||||
if not selected then return end
|
||||
|
||||
|
@ -185,12 +185,7 @@ local set_fzf_files_args = function(opts)
|
||||
end
|
||||
|
||||
local normalize_lsp_opts = function(opts, cfg)
|
||||
opts = config.getopts(opts, cfg, {
|
||||
"cwd", "actions", "winopts",
|
||||
"file_icons", "color_icons",
|
||||
"git_icons", "lsp_icons", "severity",
|
||||
"severity_exact", "severity_bound",
|
||||
})
|
||||
opts = config.normalize_opts(opts, cfg)
|
||||
|
||||
if not opts.cwd then opts.cwd = vim.loop.cwd() end
|
||||
if not opts.prompt then
|
||||
@ -208,7 +203,7 @@ local normalize_lsp_opts = function(opts, cfg)
|
||||
end
|
||||
|
||||
local function fzf_lsp_locations(opts)
|
||||
opts = normalize_lsp_opts(opts, config.lsp)
|
||||
opts = normalize_lsp_opts(opts, config.globals.lsp)
|
||||
opts = set_fzf_files_args(opts)
|
||||
opts = set_lsp_fzf_fn(opts)
|
||||
return core.fzf_files(opts)
|
||||
@ -244,7 +239,7 @@ M.document_symbols = function(opts)
|
||||
end
|
||||
|
||||
M.workspace_symbols = function(opts)
|
||||
opts = normalize_lsp_opts(opts, config.lsp)
|
||||
opts = normalize_lsp_opts(opts, config.globals.lsp)
|
||||
opts.lsp_params = {query = ''}
|
||||
opts = set_fzf_files_args(opts)
|
||||
opts = set_lsp_fzf_fn(opts)
|
||||
@ -252,7 +247,7 @@ M.workspace_symbols = function(opts)
|
||||
end
|
||||
|
||||
M.code_actions = function(opts)
|
||||
opts = normalize_lsp_opts(opts, config.lsp)
|
||||
opts = normalize_lsp_opts(opts, config.globals.lsp)
|
||||
opts.lsp_params = vim.lsp.util.make_range_params()
|
||||
opts.lsp_params.context = {
|
||||
diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
|
||||
@ -285,7 +280,7 @@ M.code_actions = function(opts)
|
||||
|
||||
local selected = fzf.fzf(opts.fzf_fn,
|
||||
core.build_fzf_cli(opts),
|
||||
config.winopts(opts.winopts))
|
||||
config.winopts(opts))
|
||||
|
||||
if opts.post_select_cb then
|
||||
opts.post_select_cb()
|
||||
@ -323,7 +318,7 @@ local filter_diag_severity = function(opts, severity)
|
||||
end
|
||||
|
||||
M.diagnostics = function(opts)
|
||||
opts = normalize_lsp_opts(opts, config.lsp)
|
||||
opts = normalize_lsp_opts(opts, config.globals.lsp)
|
||||
|
||||
local lsp_clients = vim.lsp.buf_get_clients(0)
|
||||
if #lsp_clients == 0 then
|
||||
@ -331,11 +326,12 @@ M.diagnostics = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
opts.winid = vim.api.nvim_get_current_win()
|
||||
local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity
|
||||
local current_buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
-- save this so handler can get the lsp icon
|
||||
opts.cfg = config.lsp
|
||||
opts.cfg = config.globals.lsp
|
||||
|
||||
-- hint = 4
|
||||
-- information = 3
|
||||
@ -386,9 +382,21 @@ M.diagnostics = function(opts)
|
||||
|
||||
local buffer_diags = opts.diag_all and vim.lsp.diagnostic.get_all() or
|
||||
{[current_buf] = vim.lsp.diagnostic.get(current_buf, opts.client_id)}
|
||||
if #buffer_diags == 0 then
|
||||
local has_diags = false
|
||||
for _, diags in pairs(buffer_diags) do
|
||||
if #diags > 0 then has_diags = true end
|
||||
end
|
||||
if not has_diags then
|
||||
utils.info(string.format('No %s found', string.lower(opts.lsp_handler.label)))
|
||||
utils.send_ctrl_c()
|
||||
local winid = vim.api.nvim_get_current_win()
|
||||
if opts.winid ~= winid then
|
||||
-- TODO: why does it go into insert mode after
|
||||
-- 'nvim_win_close()?
|
||||
-- vim.api.nvim_win_close(0, {force=true})
|
||||
-- utils.feed_key("<C-c>")
|
||||
-- utils.feed_key("<Esc>")
|
||||
utils.send_ctrl_c()
|
||||
end
|
||||
end
|
||||
for bufnr, diags in pairs(buffer_diags) do
|
||||
for _, diag in ipairs(diags) do
|
||||
|
@ -19,9 +19,7 @@ end
|
||||
|
||||
M.manpages = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.manpages, {
|
||||
"prompt", "actions", "winopts", "cmd",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.manpages)
|
||||
|
||||
coroutine.wrap(function ()
|
||||
|
||||
@ -40,7 +38,7 @@ M.manpages = function(opts)
|
||||
|
||||
local selected = fzf.fzf(fzf_fn,
|
||||
core.build_fzf_cli(opts),
|
||||
config.winopts(opts.winopts))
|
||||
config.winopts(opts))
|
||||
|
||||
if not selected then return end
|
||||
|
||||
|
@ -12,9 +12,7 @@ local M = {}
|
||||
|
||||
M.metatable = function(opts)
|
||||
|
||||
opts = config.getopts(opts, config.builtin, {
|
||||
"prompt", "winopts", "actions",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.builtin)
|
||||
|
||||
if not opts.metatable then opts.metatable = getmetatable('').__index end
|
||||
|
||||
@ -41,7 +39,7 @@ M.metatable = function(opts)
|
||||
|
||||
local selected = fzf.fzf(methods,
|
||||
core.build_fzf_cli(opts),
|
||||
config.winopts(opts.winopts))
|
||||
config.winopts(opts))
|
||||
|
||||
if not selected then return end
|
||||
|
||||
|
@ -12,11 +12,7 @@ local config = require "fzf-lua.config"
|
||||
local M = {}
|
||||
|
||||
M.oldfiles = function(opts)
|
||||
opts = config.getopts(opts, config.oldfiles, {
|
||||
"prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "git_icons",
|
||||
"include_current_session", "cwd_only",
|
||||
})
|
||||
opts = config.normalize_opts(opts, config.globals.oldfiles)
|
||||
|
||||
local current_buffer = vim.api.nvim_get_current_buf()
|
||||
local current_file = vim.api.nvim_buf_get_name(current_buffer)
|
||||
|
@ -18,11 +18,7 @@ local quickfix_run = function(opts, cfg, locations)
|
||||
table.insert(results, core.make_entry_lcol(opts, entry))
|
||||
end
|
||||
|
||||
opts = config.getopts(opts, cfg, {
|
||||
"cwd", "prompt", "actions", "winopts",
|
||||
"file_icons", "color_icons", "git_icons",
|
||||
"separator"
|
||||
})
|
||||
opts = config.normalize_opts(opts, cfg)
|
||||
|
||||
if not opts.cwd then opts.cwd = vim.loop.cwd() end
|
||||
|
||||
@ -73,7 +69,7 @@ M.quickfix = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
return quickfix_run(opts, config.quickfix, locations)
|
||||
return quickfix_run(opts, config.globals.quickfix, locations)
|
||||
end
|
||||
|
||||
M.loclist = function(opts)
|
||||
@ -88,7 +84,7 @@ M.loclist = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
return quickfix_run(opts, config.loclist, locations)
|
||||
return quickfix_run(opts, config.globals.loclist, locations)
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -76,7 +76,7 @@ end
|
||||
M.read_file_async = function(filepath, callback)
|
||||
vim.loop.fs_open(filepath, "r", 438, function(err_open, fd)
|
||||
if err_open then
|
||||
print("We tried to open this file but couldn't. We failed with following error message: " .. err_open)
|
||||
M.warn("We tried to open this file but couldn't. We failed with following error message: " .. err_open)
|
||||
return
|
||||
end
|
||||
vim.loop.fs_fstat(fd, function(err_fstat, stat)
|
||||
@ -193,6 +193,11 @@ function M.send_ctrl_c()
|
||||
vim.api.nvim_replace_termcodes("<C-c>", true, false, true), 'n', true)
|
||||
end
|
||||
|
||||
function M.feed_key(key)
|
||||
vim.api.nvim_feedkeys(
|
||||
vim.api.nvim_replace_termcodes(key, true, false, true), 'n', true)
|
||||
end
|
||||
|
||||
function M.delayed_cb(cb)
|
||||
-- HACK: slight delay to prevent missing results
|
||||
-- otherwise the input stream closes too fast
|
||||
|
Loading…
Reference in New Issue
Block a user