telescope.nvim
telescope.nvim copied to clipboard
Telescope live_grep freezes nvim sometimes
Description
In one specific work project, I sometimes get neovim frozen by using Telescope live_grep (with ripgrep)
At that point neovim does not respond to any input. I can kill it with killall nvim
. After that, following error is visible in the terminal:
Error executing vim.schedule lua callback: ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:14: The coroutine failed with this message: ...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:1279: attempt to index a nil value
Based on testing with minimal configs, I can only get this to happen with treesitter also installed.
Also, I can only get this to happen with one specific code base I'm developing. I'll try debugging this more. Any hints on what to look for would be useful.
Telescope version is latest master 782d802d44077e07f80189560f91c86370f11e39
Neovim version
NVIM v0.6.0-dev+509-g09e96fe60 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3
Operating system and version
Ubuntu 20.04
checkhealth telescope
telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
- OK: plenary installed.
- OK: nvim-treesitter installed.
## Checking external dependencies
- OK: rg: found ripgrep 12.1.1
- OK: fd: found fd 7.4.0
## ===== Installed extensions =====
Steps to reproduce
- open a text file (should not be relevant, but this seem to require some obscure things before happening)
- :Telescope live_grep
- start searching
Expected behavior
Neovim does not stop responding to input
Actual behavior
Neovim stops responding to input (freezes)
Minimal config
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
require('packer').startup {
{
'wbthomason/packer.nvim',
{
'nvim-telescope/telescope.nvim',
requires = {
'nvim-lua/plenary.nvim',
},
},
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
'nvim-treesitter/nvim-treesitter',
},
config = {
package_root = package_root,
compile_path = install_path .. '/plugin/packer_compiled.lua',
display = { non_interactive = true },
},
}
end
_G.load_config = function()
require('telescope').setup()
-- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
require'nvim-treesitter.configs'.setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
highlight = {
enable = true
},
incremental_selection = {
enable = false
},
indent = {
enable = false,
}
}
end
if vim.fn.isdirectory(install_path) == 0 then
print("Installing Telescope and dependencies.")
vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
Added debug printing to pickers.lua
function Picker:_get_prompt()
local prompt = vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)
if prompt == nil or prompt[1] == nil then
print('i broke: ' .. vim.inspect(prompt) .. ' ; ' .. vim.inspect(#self))
return 'foo'
else
return prompt[1]:sub(#self.prompt_prefix + 1)
end
end
Still results in nvim freesing. After killing, following is seen
i broke: {} ; 0
That "fixed" the nil reference and the other error output, but nvim stopped working anyway. Not sure what to think about this.
I can't reproduce anymore. Might be that my code project's file tree has changed, or updated neovim, or stars aligned differently. I'll close.
I'm struggling with this in reops with large files. It actually happens regularly in the neovim/neovim repo.
NVIM v0.6.0-dev+525-ge921e98ce
macOS Monterey 12.0.1
I've customized the vimgrep_arguments to the following:
local vimgrep_arguments = {
"rg",
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
"--smart-case",
"--hidden",
}
Ok so I wasn't the only one... I quess it makes sense to reopen this then, so it doesn't get lost. Sorry in advance, if this isn't appropriate.
This happened to me quite frequently in a repo with a few hundred thousand files and large files.
I've switched to fzf because it never freezes my whole editor.
@chase for the time being for that large of a scale fzf probably is the better tool. telescope and fzf are perfectly fine to co-exist, after all :)
telescope in the longer term will likely incorporate rust (https://github.com/nvim-telescope/telescope-rs.nvim) in its core to better accommodate such use cases in the long future.
This happens to me on NVIM v0.6.0-dev+582-g87a053f12
I don't know if its of any help but I disabled treesitter and the problem persists.
Well this have started happening to me again.
@fdschmidt93 I don't believe this is a matter of one tool being better. For me at least, the problem is not some slowness, but the fact that nvim hard freezes and never recovers. Only way out is to kill nvim. I don't understand if this is a bug in neovim itself or in telescope but for me it only seems to happend with telescope, usually with live_grep (or only with live_grep, not 100% sure).
I think it happens less often when I have telescope-fzf-native.nvim installed, so it might be speed related (but it definitely does not fully prevent the issue).
Quick update: For me it was a couple of things in my config that where causing the sluggishness. One was this plugin https://github.com/norcalli/nvim-colorizer.lua. Activating it only for specific files did the trick.
The other one its Treesitter highlighting. If I disable it, big searches work well. Before I didn't think it was TS because of the Colorizer plugin making live_grep
equally slow.
Can I disable Treesitter highlight on Telescope? Maybe there is a better alternative ( I seen file preview hooks but I did not try anything yet )
I'm experiencing the same issue and if I completely disable TS then my greps and file searches are fast again. I'm curious if @marcelarie's option of disabling TS for Telescope is an option.
I'm experiencing the same issue and if I completely disable TS then my greps and file searches are fast again. I'm curious if @marcelarie's option of disabling TS for Telescope is an option.
@jc00ke for me it was only the highlighting that was making Telescope slow.
Maybe you want to disable just that while keeping other TS functionalities. You can do it like this on the TS config:
treesitter.setup({
highlight = {
enable = true,
disable = { "perl", "javascript" },
-- ...
},
}
For me the best option will be to disable TS highlight just on Telescope.
@marcelarie much better approach, thank you!
See also :h telescope.defaults.preview
. Also has some options to opt-out of treesitter etc.
thanks @fdschmidt93 !! just what I needed:
telescope.setup({
defaults = {
preview = {
treesitter = false,
},
},
})
The minified js
files are the ones that make Telescope freeze so maybe I can find a better solution than just disable Treesitter. The hooks seem the way to go.
I just created a pull request (https://github.com/nvim-telescope/telescope.nvim/pull/1612) with a change on the telescope.defaults.preview
config that maybe can be useful for cases like this.
live_grep doesn't work with fzf syntax even with the nvim-telescope/telescope-fzf-native.nvim plugin
however, find_files works with the fzf syntax. Not sure why.
For me it was a couple of things in my config that where causing the sluggishness. One was this plugin https://github.com/norcalli/nvim-colorizer.lua. Activating it only for specific files did the trick.
The colorizer plugin really was the malefactor in my case as well. Had those freezes on a decent machine when the projects got a bit bigger - also with preview disabled.
For me it was a couple of things in my config that where causing the sluggishness. One was this plugin https://github.com/norcalli/nvim-colorizer.lua. Activating it only for specific files did the trick.
The colorizer plugin really was the malefactor in my case as well. Had those freezes on a decent machine when the projects got a bit bigger - also with preview disabled.
I have the same issue for a while, disable https://github.com/norcalli/nvim-colorizer.lua works. Does anyone have an alternative colorizer plugin recommend?
@mactanxin you can use colorizer. Just don't enable it for every ft. E.g., config that makes no performance problems:
local ok, colorizer = pcall(require, "colorizer")
if not ok then return end
-- https://github.com/lilydjwg/colorizer
colorizer.setup(
{ "css", "javascript", "lua", "vim", "toml", "svelte", "typescript" },
{
RGB = true, -- #RGB hex codes
RRGGBB = true, -- #RRGGBB hex codes
names = false, -- "Name" codes like Blue oe blue
RRGGBBAA = true, -- #RRGGBBAA hex codes
rgb_fn = true, -- CSS rgb() and rgba() functions
hsl_fn = true, -- CSS hsl() and hsla() functions
css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn
-- Available modes: foreground, background, virtualtext
mode = "background", -- Set the display mode.)
}
)
@tobealive I tried add { "css", "javascript", "lua", "vim", "toml", "svelte", "typescript" },
line into my config file, won't freeze immediately, if I type a little faster or maybe after 5, 6 characters, will freeze again
As this is an additional, separate table from the rest of the setup values(which is rather unusual) , the first trivial thing I would ask is if you are sure that you pasted it correctly.
Next thing you could try is further excluding filtetypes. Or try creating an autocmd that's disabling colorizer when entering live grep.
@tobealive Ok cool. I replaced the entire colorizer config, it works :) a million thanks 🚀🚀🚀
This happens to me on a large project. It happens consistently when I search for a class name that doesn't exist like ActsAsSomething
Actually it exactly freezes on ActsA
every time. I suspected it must be related to something that live_grep can't find but I'm not sure.
Or it could be related to the capital letters. Again not sure about the cause but the behavior is consistent.
This happens to me on a large project. It happens consistently when I search for a class name that doesn't exist like
ActsAsSomething
Actually it exactly freezes on
ActsA
every time. I suspected it must be related to something that live_grep can't find but I'm not sure.Or it could be related to the capital letters. Again not sure about the cause but the behavior is consistent.
Have you been able to identify if it's an issue with the previewer (see comments about for disabling tree-sitter for the previewer, seemed to help some) or colorizer (again see comments above).
colorizer it is. Removed colorizer for now. Telescope works fine with treesitter enabled.
I think this issue is good to close now. Seems like it's come down to:
- disabling colorizer for telescope
- disabling treesitter for telescope previews (nightly telescope has a
highlight_limit
file size limit under preview options with a default of 1MB) - telescope can't compete with fzf on larger projects depending on hardware (known issue / trade off of telescope vs fzf)