telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

Telescope live_grep freezes nvim sometimes

Open juho-p opened this issue 3 years ago • 23 comments

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

  1. open a text file (should not be relevant, but this seem to require some obscure things before happening)
  2. :Telescope live_grep
  3. 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()]]

juho-p avatar Oct 25 '21 15:10 juho-p

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.

juho-p avatar Oct 25 '21 16:10 juho-p

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.

juho-p avatar Oct 29 '21 14:10 juho-p

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",
}

williamboman avatar Nov 02 '21 13:11 williamboman

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.

juho-p avatar Nov 02 '21 15:11 juho-p

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 avatar Nov 08 '21 01:11 chase

@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.

fdschmidt93 avatar Nov 08 '21 08:11 fdschmidt93

This happens to me on NVIM v0.6.0-dev+582-g87a053f12

marcelarie avatar Nov 17 '21 12:11 marcelarie

I don't know if its of any help but I disabled treesitter and the problem persists.

marcelarie avatar Nov 23 '21 10:11 marcelarie

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).

juho-p avatar Nov 24 '21 15:11 juho-p

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 )

marcelarie avatar Dec 14 '21 09:12 marcelarie

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 avatar Dec 16 '21 00:12 jc00ke

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 avatar Dec 16 '21 07:12 marcelarie

@marcelarie much better approach, thank you!

jc00ke avatar Dec 16 '21 19:12 jc00ke

See also :h telescope.defaults.preview. Also has some options to opt-out of treesitter etc.

fdschmidt93 avatar Dec 16 '21 20:12 fdschmidt93

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.

marcelarie avatar Dec 17 '21 10:12 marcelarie

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.

marcelarie avatar Dec 19 '21 13:12 marcelarie

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.

ssh352 avatar Jun 25 '22 08:06 ssh352

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.

ttytm avatar Jul 02 '22 02:07 ttytm

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 avatar Aug 08 '22 06:08 mactanxin

@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.)
	}
)

ttytm avatar Aug 08 '22 11:08 ttytm

@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

mactanxin avatar Aug 15 '22 02:08 mactanxin

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.

ttytm avatar Aug 16 '22 04:08 ttytm

@tobealive Ok cool. I replaced the entire colorizer config, it works :) a million thanks 🚀🚀🚀

mactanxin avatar Aug 16 '22 09:08 mactanxin

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.

sathishmanohar avatar Oct 10 '23 20:10 sathishmanohar

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).

jamestrew avatar Oct 10 '23 22:10 jamestrew

colorizer it is. Removed colorizer for now. Telescope works fine with treesitter enabled.

sathishmanohar avatar Oct 12 '23 20:10 sathishmanohar

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)

jamestrew avatar Oct 14 '23 21:10 jamestrew