-
-
Notifications
You must be signed in to change notification settings - Fork 856
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
Faster preview #623
Comments
We have considered all the above and we found a pretty good solution, (in my opinion, but i also designed them sooooooo 🤣 ) already. So we decided to make I wanted to make an extension that lets you not have to override the function but i never found the interest in doing that. So here are some snippets: Disable highlighting for certain files: local previewers = require('telescope.previewers')
local _bad = { '.*%.csv', '.*%.lua' } -- Put all filetypes that slow you down in this array
local bad_files = function(filepath)
for _, v in ipairs(_bad) do
if filepath:match(v) then
return false
end
end
return true
end
local new_maker = function(filepath, bufnr, opts)
opts = opts or {}
if opts.use_ft_detect == nil then opts.use_ft_detect = true end
opts.use_ft_detect = opts.use_ft_detect == false and false or bad_files(filepath)
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
require('telescope').setup {
defaults = {
buffer_previewer_maker = new_maker,
}
} Ignore files bigger than a threshold. Make sure you are on current master, i pushed a fix to make this work: local previewers = require('telescope.previewers')
local new_maker = function(filepath, bufnr, opts)
opts = opts or {}
filepath = vim.fn.expand(filepath)
vim.loop.fs_stat(filepath, function(_, stat)
if not stat then return end
if stat.size > 100000 then
return
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)
end
require('telescope').setup {
defaults = {
buffer_previewer_maker = new_maker,
}
} |
I had a file with that's basically one big line, that made Telescope freeze too, it's quite a small file, so Id have to write a custom previewer function for that too? |
This may be understood already, since the issue is still open, but I think some better default handling of this would be great. I was going to switch back to clap before I found this workaround, would be nicer IMO if there was some sensible default, like timeout after 200ms or something. |
In case others find this useful: local previewers = require('telescope.previewers')
local previewers_utils = require('telescope.previewers.utils')
local max_size = 100000
local truncate_large_files = function(filepath, bufnr, opts)
opts = opts or {}
filepath = vim.fn.expand(filepath)
vim.loop.fs_stat(filepath, function(_, stat)
if not stat then return end
if stat.size > max_size then
local cmd = {"head", "-c", max_size, filepath}
previewers_utils.job_maker(cmd, bufnr, opts)
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)
end |
I've added this to mentored projects. I'm really happy to guide a PR here. It's a bit of a question also, as to what Telescope can do here since it basically boils down to an upstream problem vim.treesitter should hopefully eventually handle. fzf-lua tackles this problem by switching to bat if the number of lines exceeds a threshold, which would be straightforward to implement I suppose though it's of course a hack. Further, this hack is pretty much the same solution as posted here. |
Another option could be to add a timeout to rendering previewers somehow. This would be a nice option because it doesn't have to be specific to what's causing this issue here. EDIT: Mfw I should have re-read the thread 🤦 |
Yeah, I haven't fully thought the timeout idea through; even if treesitter was fast there's enough issues where sluggishness probably would persist. But yeah, probably even more challenging ;) |
I've written up a quite naive PR. If anyone here can confirm that this works for you just as well, that would be great. Then I'd bring this in better shape. Thanks in advance. |
Ok, the PR is in pretty good shape. Happy to get comments from anyone who's subscribed here. Any changes to the PR are hopefully primarily of cosmetic nature. |
I hope this is now sufficiently addressed with #1231. Please see We also enable hooks for varying scenarios such that you can quite easily provide functions that display what you'd like to see in case default previewer is not possible, for instance with some of the functions as laid out here. Please comment if you feel we should provide default hooks, then I'd maybe look into it (but really hope somebody steps up, it's not that hard :). We can then reopen this or make a new issue or something. Other than that, I'll close this for the time being. |
Here's how I'm truncating the files in the preview if they're over the file size limit: telescope.setup {
defaults = {
preview = {
filesize_hook = function(filepath, bufnr, opts)
local max_bytes = 10000
local cmd = {"head", "-c", max_bytes, filepath}
require('telescope.previewers.utils').job_maker(cmd, bufnr, opts)
end
}
}
} Much neater :D (Although I discovered #1252 😭) |
Moreoever, telescope.nvim/lua/telescope/previewers/buffer_previewer.lua Lines 187 to 194 in 2d92125
(I don't see that in the documentation.) |
I don't know why, but for large minified (javascript/typescript) files, if I do specifically a telescope.setup {
defaults = {
preview = {
filesize_limit = 0.9999,
timeout = 250,
},
},
} |
@kkoomen how large are these files? |
@jamestrew 2MB |
@kkoomen The previewer timeout mechanism can definitely be improved... |
@jamestrew https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.asm.js here is a 1.1MB js file.
Oh right, totally forgot about that. I'll have a look at this as well. |
@jamestrew When I disable all my plugins except for telescope, I still get the same problem that it yet again fixed with 0.9999 as a value. |
Ah. I assume you're on 0.1.x branch or one of the tags. |
i am gonna stop this conversation on this almost 3 year old issue now! If you @kkoomen need help, found a bug with a feature, please open a new issue, fill out the issue form and then we will look into this. not here on an old issue! It is not helpful and its hard to debug stuff without much information |
Telescope freezes when attempting to preview large files. For instance, previewing a 100000 line CSV file causes a 10 second long freeze.
Possible solutions, in order of easiest to most difficult to implement (I presume):
cat file.csv | head -c 1000000 | head -n 1000 > file.csv.preview
so that a preview does not need to be generated for too much data. Here,file.csv.preview
is a smaller file (<1MB and <1000 lines) that can read by telescope.The text was updated successfully, but these errors were encountered: