stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.69k stars 32 forks source link

vim.ui.select telescope: complete hang on focus loss #165

Closed emmanueltouzery closed 1 week ago

emmanueltouzery commented 2 weeks ago

Describe the bug when using vim.ui.select with the telescope backend, if you focus out of the telescope window (switch to any another window), telescope will close. However at that point the dressing vim.ui.select implementation is completely hung and no vim.ui.select will open again until neovim is restarted.

System information

    require('dressing').setup({
      input = {
        -- ESC won't close the modal, ability to use vim keys
        insert_only = false,
        get_config = function(opts)
          if opts.kind == 'center_win' then
            return {
              relative = 'editor',
            }
          end
        end
      },
      select = {
        get_config = function(opts)
          -- https://github.com/stevearc/dressing.nvim/issues/22#issuecomment-1067211863
          -- for codeaction, we want null-ls to be last
          -- https://github.com/jose-elias-alvarez/null-ls.nvim/issues/630
          -- for eslint, it's offering me options like "disable eslint rule" which
          -- are almost never what I want, and they appear before the more useful options
          -- from the LSP
          if opts.kind == 'codeaction' then
            return {
              telescope = {
                -- sorter = require'telescope.sorters'.Sorter:new {
                --   scoring_function = function(_, _, line)
                --     local order = tonumber(string.match(line, "^[%d]+"))
                --     if string.find(line, escape_pattern('null-ls')) then
                --       return order+100
                --     else
                --       return order
                --     end
                --   end,
                -- },
                cache_picker = false,
                -- copied from the telescope dropdown theme
                sorting_strategy = "ascending",
                layout_strategy = "center",
                layout_config = {
                  preview_cutoff = 1, -- Preview should always show (unless previewer = false)
                  width = 80,
                  height = 15,
                },
                borderchars = {
                  prompt = { "─", "│", " ", "│", "╭", "╮", "│", "│" },
                  results = { "─", "│", "─", "│", "├", "┤", "╯", "╰" },
                  preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
                },
              }
            }
          end
        end,
      },
    })

To Reproduce Steps to reproduce the behavior:

  1. :lua vim.ui.select({"a", "b"}, {prompt="pick one"}, function(choice) print(choice) end)
  2. escape if you're in insert mode
  3. :1 wincmd w to switch to another window, or any other way to switch to another window than the telescope window. When switching, telescope (dressing) closes
  4. try again => :lua vim.ui.select({"a", "b"}, {prompt="pick one"}, function(choice) print(choice) end)

From now on, vim.ui.select won't open again.

Additional context I'm pretty certain that the issue is that callback(nil, nil) should be called when telescope is closed, but telescope does not tell us when it gets closed due to focus loss (as opposed for instance of the user explicitly closing telescope). I tried to find a way to get notified somehow when telescope gets closed in such situations, but couldn't do it.

emmanueltouzery commented 1 week ago

Hmm I realised this is a duplicate of #150