nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.43k stars 824 forks source link

Telescope takes ages to close #3159

Open Mango0x45 opened 3 months ago

Mango0x45 commented 3 months ago

Description

I am using telescope, and have <Esc> mapped to close telescope when I’m in insert mode. This works… but for whatever reason this has a very noticable delay (1 full second) in a very specific directory of mine which contains… a few 100 lines of C code.

I have tested and confirmed that this has nothing to do with LSP or TreeSitter (I tried with :LspStop and :TSBufDisable <options>). I also checked my mappings with :map <Esc> and confirmed that I only have a single mapping, but that mapping is in normal mode (I am in insert mode), and even without it the delay persists.

I am at a total loss as to how to further debug this.

Neovim version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1716656478

Operating system and version

Arch Linux

Telescope version / branch / rev

commit 3a743491e5c6be0ed0aa8c31c6905df8f66179ba

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 14.1.0
- OK fd: found fd 10.1.0

===== Installed extensions ===== ~

Steps to reproduce

local telescope = require 'telescope'
local actions = require 'telescope.actions'

telescope.setup {
    defaults = {
        mappings = {
            i = {
                ['<Esc>'] = {
                    actions.close,
                    type = 'action',
                    opts = { nowait = true, silent = true },
                },
            },
        },
    },
}

Then I just do :Telescope find_files (or really any picker), and hit <Esc>.

Expected behavior

The picker to close instantly.

Actual behavior

The picker takes over a second.

Minimal config

(The issue also persists when using simply this 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',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
    },
    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({
    defaults = {
      mappings = {
        i = {
          ['<Esc>'] = {
            require('telescope.actions').close,
            type = 'action',
            opts = { nowait = true, silent = true },
          },
        },
      },
    },
  })
  require('telescope').load_extension('fzf')
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()]]
jamestrew commented 3 months ago

This only happens in one specific directory?

I'm not able to reproduce this and I'm not sure what could even be causing it especially without being able to reproduce it.

Mango0x45 commented 3 months ago

This only happens in one specific directory?

I'm not able to reproduce this and I'm not sure what could even be causing it especially without being able to reproduce it.

Yes, but I also only started using telescope today. I can try to copy my files to a different directory and see if the issue still persists in the copy.
If it does, I can upload a tarball of the directory to see if others can reproduce the issue

dizzib commented 5 days ago

I wonder if it’s because Telescope creates a <esc><esc> mapping:

Screenshot 2024-09-11 at 10 53 03

So pressing <esc> waits timeoutlen ms before closing?

Strangely, I must first enter insert mode before invoking Telescope to see this <esc><esc>. If I open nvim then Telescope without first going into insert mode, there is no <esc><esc>.

This workaround seems to work:

vim.api.nvim_create_autocmd(‘BufEnter’, {
  pattern = ‘*’,
  callback = function()
    vim.schedule(function()  — without this, filetype is empty
      if vim.api.nvim_buf_get_option(0, ‘filetype’) == ‘TelescopePrompt’ then
        vim.keymap.set(‘I’, ‘<esc><esc>’, ‘’) — avoid E31 error
        vim.keymap.del(‘I’, ‘<esc><esc>’)
      end
    end)
  end,
})