added builtin previewer options for syntax bytes/lines limits

main
bhagwan 3 years ago
parent e6c4f31c06
commit 757d6392f0

@ -257,6 +257,8 @@ require'fzf-lua'.setup {
scrollchar = '█', -- scrollbar character
wrap = false, -- wrap lines?
syntax = true, -- preview syntax highlight?
syntax_limit_l = 0, -- syntax limit (lines), 0=nolimit
syntax_limit_b = 1024*1024, -- syntax limit (bytes), 0=nolimit
expand = false, -- preview max size?
hl_cursor = 'Cursor', -- cursor highlight
hl_cursorline = 'CursorLine', -- cursor line highlight

@ -109,6 +109,8 @@ M.globals = {
wrap = false,
syntax = true,
syntax_delay = 0,
syntax_limit_l = 0,
syntax_limit_b = 1024*1024,
expand = false,
hidden = false,
hl_cursor = 'Cursor',

@ -57,6 +57,8 @@ function Previewer:new(o, opts, fzf_win)
self.hidden = o.hidden
self.syntax = o.syntax
self.syntax_delay = o.syntax_delay
self.syntax_limit_b = o.syntax_limit_b
self.syntax_limit_l = o.syntax_limit_l
self.hl_cursor = o.hl_cursor
self.hl_cursorline = o.hl_cursorline
self.hl_range = o.hl_range
@ -174,12 +176,29 @@ function Previewer:do_syntax(entry)
local preview_winid = self.win.preview_winid
if self.preview_bufloaded and vim.bo[bufnr].filetype == '' then
if fn.bufwinid(bufnr) == preview_winid then
-- do not enable for lage files, treesitter still has perf issues:
-- do not enable for large files, treesitter still has perf issues:
-- https://github.com/nvim-treesitter/nvim-treesitter/issues/556
-- https://github.com/nvim-treesitter/nvim-treesitter/issues/898
local lcount = api.nvim_buf_line_count(bufnr)
local bytes = api.nvim_buf_get_offset(bufnr, lcount)
if bytes / lcount < 1000 then
local syntax_limit_reached = 0
if self.syntax_limit_l > 0 and lcount > self.syntax_limit_l then
syntax_limit_reached = 1
end
if self.syntax_limit_b > 0 and bytes > self.syntax_limit_b then
syntax_limit_reached = 2
end
if syntax_limit_reached > 0 then
utils.info(string.format(
"syntax disabled for '%s' (%s), consider increasing '%s(%d)'", entry.path,
utils._if(syntax_limit_reached==1,
("%d lines"):format(lcount),
("%db"):format(bytes)),
utils._if(syntax_limit_reached==1, 'syntax_limit_l', 'syntax_limit_b'),
utils._if(syntax_limit_reached==1, self.syntax_limit_l, self.syntax_limit_b)
))
end
if syntax_limit_reached == 0 then
-- nvim_buf_call is less side-effects than changing window
-- make sure that buffer in preview window must not in normal window
-- greedy match anything after last dot

Loading…
Cancel
Save