From 89c67676a8fae529497a725e54677e9257ec16d5 Mon Sep 17 00:00:00 2001 From: KevinSilvester <56918431+KevinSilvester@users.noreply.github.com> Date: Sun, 14 May 2023 21:04:34 +0100 Subject: [PATCH] fix(preview): update mime-type check for json files (#2221) (#2480) --- lua/telescope/previewers/buffer_previewer.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua index 22fc040..8a077f5 100644 --- a/lua/telescope/previewers/buffer_previewer.lua +++ b/lua/telescope/previewers/buffer_previewer.lua @@ -192,8 +192,8 @@ previewers.file_maker = function(filepath, bufnr, opts) if opts.preview.check_mime_type == true and has_file and opts.ft == "" then -- avoid SIGABRT in buffer previewer happening with utils.get_os_command_output local output = capture(string.format([[file --mime-type -b "%s"]], filepath)) - local mime_type = vim.split(output, "/")[1] - if mime_type ~= "text" and mime_type ~= "inode" then + local mime_type = vim.split(output, "/") + if mime_type[1] ~= "text" and mime_type[1] ~= "inode" and mime_type[2] ~= "json" then if type(opts.preview.mime_hook) == "function" then vim.schedule_wrap(opts.preview.mime_hook)(filepath, bufnr, opts) else @@ -206,6 +206,9 @@ previewers.file_maker = function(filepath, bufnr, opts) end return end + if mime_type[2] == "json" then + opts.ft = "json" + end end if opts.preview.filesize_limit then