fix(previewer): only run ftdetect for files (#2559)

This commit is contained in:
Simon Hauser
2023-06-09 18:51:17 +02:00
committed by GitHub
parent 8c998877f1
commit 69e8715786

View File

@@ -10,7 +10,7 @@ local utils = {}
local detect_from_shebang = function(p) local detect_from_shebang = function(p)
local s = p:readbyterange(0, 256) local s = p:readbyterange(0, 256)
if not s then if s then
local lines = vim.split(s, "\n") local lines = vim.split(s, "\n")
return vim.filetype.match { contents = lines } return vim.filetype.match { contents = lines }
end end
@@ -40,7 +40,7 @@ utils.filetype_detect = function(filepath)
end end
local p = Path:new(filepath) local p = Path:new(filepath)
if p and p:exists() then if p and p:is_file() then
match = detect_from_shebang(p) match = detect_from_shebang(p)
if match and match ~= "" then if match and match ~= "" then
return match return match