-
-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] typescript
(ts
) files are not previewed with custom mime_hook for images
#3068
Comments
Are you sure it's the image preview code that's affecting ts file previews? I'm also not able to reproduce this. I can get a ts file to show its preview. img-preview.mp4This was done using this minimal config. Granted I switched out min.lualocal root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
{
"nvim-telescope/telescope.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
},
config = function()
require("telescope").setup({
defaults = {
preview = {
mime_hook = function(filepath, bufnr, opts)
local get_ext = function(filepath)
local split_path = vim.split(filepath:lower(), ".", { plain = true })
return split_path[#split_path]
end
local is_image = function(filepath)
local image_extensions = { "png", "jpg" } -- Supported image formats
return vim.tbl_contains(image_extensions, get_ext(filepath))
end
if is_image(filepath) then
local term = vim.api.nvim_open_term(bufnr, {})
local function send_output(a, data, c)
for _, d in ipairs(data) do
vim.api.nvim_chan_send(term, d .. "\r\n")
end
end
vim.fn.jobstart({
"catimg",
-- "chafa,"
filepath, -- Terminal image viewer command
}, { on_stdout = send_output, stdout_buffered = true, pty = true })
else
require("telescope.previewers.utils").set_preview_message(
bufnr,
opts.winid,
"Binary cannot be previewed (" .. get_ext(filepath) .. ")"
)
end
end,
},
},
})
end,
},
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
}) I'd like you to try this minimal config. |
Hi @jamestrew, I cannot try it right now, as i am answering from my phone, but I will try asap.
Removing the mimehook makes the ts files preview return, also if you notice on the screenshot that I provided the extension is present on the |
That's strange. Seems to me like a couple of things have to go very wrong for this to be the case..
telescope.nvim/lua/telescope/previewers/buffer_previewer.lua Lines 171 to 175 in 35f94f0
I'd ask you to try the |
Running against the same file that is on the screenshot: $ file --mime-type -b en.ts
application/javascript Doing the same against a tsx file returns the same result, weird: $ file --mime-type -b index.tsx
application/javascript |
Interesting... never really questioned how We can fix this though. |
If we can give the linked PR a try, that would be helpful. |
Just tried it and its working now: Thanks for that, cant wait for it to merge 😄, just to confirm, without #3083 it does not work still: |
Description
Setting up the mimehook to the example shown in Configuration-Recipes#use-terminal-image-viewer-to-preview-images makes
ts
files not being renderedNeovim version
Operating system and version
NixOs unstable
Telescope version / branch / rev
1-unstable-2024-04-21
checkhealth telescope
Steps to reproduce
Telescope find_files hidden=True
Expected behavior
No response
Actual behavior
Minimal config
Edit: Format
The text was updated successfully, but these errors were encountered: