stevearc / dressing.nvim

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

Race with concurrent selections in telescope and builtin backends #139

Closed AlexJF closed 8 months ago

AlexJF commented 8 months ago

Describe the bug Some situations may lead to multiple selection prompts happening concurrently. For instance when using the vtsls LSP and opening a typescript project we get these 2 prompts at startup:

image

image

These show up as expected when using the nui backend but when using the default telescope backend, only one of them will show up. The LSP will continue showing as loading until it eventually times out on the selection.

When using the builtin backend, an error shows up "window was closed immediately" and the selection seems to get immediately cancelled. A single select UI still shows up but selecting it seems to not have any effect.

System information

return {
  "stevearc/dressing.nvim",
  -- dir = "~/Projects/dressing.nvim",
  enabled = true,
  opts = {
    select = {
      enabled = true,
      -- default telescope backend seems to not support "concurrent" selections
      backend = { "nui" },
      nui = {
        min_height = 0,
      },
    },
    input = {
      -- Allow escaping to normal mode inside inputs
      insert_only = false,
    },
  },
}

To Reproduce Steps to reproduce the behavior:

  1. We can easily reproduce this behaviour using the select test file in tests/manual/select.lua by adding a second run test call:
-- Run this test with :source %

local function run_test(backend)
  local config = require("dressing.config")
  local prev_backend = config.select.backend
  config.select.backend = backend
  vim.ui.select({ "first", "second", "third" }, {
    prompt = "Make selection: ",
    kind = "test",
  }, function(item, lnum)
    if item and lnum then
      vim.notify(string.format("selected '%s' (idx %d)", item, lnum), vim.log.levels.INFO)
    else
      vim.notify("Selection canceled", vim.log.levels.INFO)
    end
    config.select.backend = prev_backend
  end)
end

-- Replace this with the desired backend to test
run_test("telescope")
run_test("telescope")

Screenshots

dressing

This is the behaviour without dressing.nvim btw:

dressing2

stevearc commented 8 months ago

Fixed for all backends and for vim.ui.input as well