diff options
| author | fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> | 2021-09-16 23:01:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-16 23:01:40 +0200 |
| commit | 7c5b846f6f8caa8acf4b63dc4c33a801e2ea78a0 (patch) | |
| tree | 128ca47803814e4ba35c629ac0e194325dbfc830 /lua/telescope/previewers/utils.lua | |
| parent | ac03f495c6ec1f832488556969f72677b69ef33d (diff) | |
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
Diffstat (limited to 'lua/telescope/previewers/utils.lua')
| -rw-r--r-- | lua/telescope/previewers/utils.lua | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index 54435fd..abb44e3 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -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 |
