fix(previewer): improve binary mime type check (#3083)
* fix(previewer): improve binary mime type check Problem: mime type for a ts/js file can either return `text/plain` or `application/javascript` based on the contents of the file. Previously, this meant `application/javascript` would be considered "possibly binary". This, in conjunction with how `vim.filetype.match` does not give a result for a filename that ends in `.ts`, would lead to a typescript file taking the path of `check_mime_type` and eventually `mime_hook`. Solution: Include `application/javascript` as a non-binary file type during mime type check. * [docgen] Update doc/telescope.txt skip-checks: true --------- Co-authored-by: Github Actions <actions@github>
This commit is contained in:
@@ -222,4 +222,21 @@ utils.set_preview_message = function(bufnr, winid, message, fillchar)
|
||||
end
|
||||
end
|
||||
|
||||
--- Check if mime type is binary.
|
||||
--- NOT an exhaustive check, may get false negatives. Ideally should check
|
||||
--- filetype with `vim.filetype.match` or `filetype_detect` first for filetype
|
||||
--- info.
|
||||
---@param mime_type string
|
||||
---@return boolean
|
||||
utils.binary_mime_type = function(mime_type)
|
||||
local type_, subtype = unpack(vim.split(mime_type, "/"))
|
||||
if vim.tbl_contains({ "text", "inode" }, type_) then
|
||||
return false
|
||||
end
|
||||
if vim.tbl_contains({ "json", "javascript" }, subtype) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return utils
|
||||
|
||||
Reference in New Issue
Block a user