feat: skip/timeout preview if file cannot be easily previewed (#1231)

* For full configuration, see `:h telescope.defaults.preview`
* Unblocks previewer on binaries, too large files, and files that take too long to read
* Allows toggling treesitter highlighting for buffer_previewer
* Allows to globally opt out of previewer
This commit is contained in:
fdschmidt93
2021-09-16 23:01:40 +02:00
committed by GitHub
parent ac03f495c6
commit 7c5b846f6f
4 changed files with 253 additions and 11 deletions

View File

@@ -63,8 +63,18 @@ local function has_filetype(ft)
end
--- Attach default highlighter which will choose between regex and ts
utils.highlighter = function(bufnr, ft)
if not (utils.ts_highlighter(bufnr, ft)) then
utils.highlighter = function(bufnr, ft, opts)
opts = opts or {}
opts.preview = opts.preview or {}
opts.preview.treesitter = vim.F.if_nil(opts.preview.treesitter, true)
local ts_highlighting = opts.preview.treesitter == true
or type(opts.preview.treesitter) == "table" and vim.tbl_contains(opts.preview.treesitter, ft)
local ts_success
if ts_highlighting then
ts_success = utils.ts_highlighter(bufnr, ft)
end
if not (ts_highlighting or ts_success) then
utils.regex_highlighter(bufnr, ft)
end
end