Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: <C-w> cause error in fuzzy search mode #97

Closed
Bekaboo opened this issue Sep 29, 2023 · 3 comments · Fixed by #98 or #79
Closed

[Bug]: <C-w> cause error in fuzzy search mode #97

Bekaboo opened this issue Sep 29, 2023 · 3 comments · Fixed by #98 or #79
Labels
bug Something isn't working

Comments

@Bekaboo
Copy link
Owner

Bekaboo commented Sep 29, 2023

Description

In fuzzy search mode, deleting texts before cursor using <C-w> or <C-u> etc. will make fzf_entry.pos to nil, triggering an error in

for _, pos_idx in ipairs(fzf_entry.pos) do

nvim version

v0.10.0-dev-1224+gdfa8b582a6

dropbar.nvim version

1a6c879

Operating system and version

Linux 6.1.54.15.realtime1-2-rt-lts

Minimal config

local tmp = vim.env.TMPDIR
  or vim.env.TEMPDIR
  or vim.env.TMP
  or vim.env.TEMP
  or '/tmp'
local data = tmp ..  '/' .. (vim.env.NVIM_APPNAME or 'nvim')
local packages_root = data .. '/site'
local cloned_root = packages_root .. '/pack/packages/start'
local cloned_path = cloned_root .. '/dropbar.nvim'
local url = 'https://github.com/Bekaboo/dropbar.nvim.git'

vim.fn.mkdir(cloned_root, 'p')
vim.opt.pp:prepend(packages_root)
vim.opt.rtp:prepend(packages_root)

if not vim.loop.fs_stat(cloned_path) then
  vim.fn.system({ 'git', 'clone', url, cloned_path })
end

cloned_path = cloned_root .. '/telescope-fzf-native'
url = 'https://github.com/nvim-telescope/telescope-fzf-native.nvim'

if not vim.loop.fs_stat(cloned_path) then
  vim.fn.system({ 'git', 'clone', url, cloned_path })
  vim.fn.system({ 'make', '-C', cloned_path })
end

require('dropbar').setup()

Steps to reproduce

  1. Save the configuration above as minimal.lua
  2. Make sure telescope-fzf-native is in &rtp
  3. nvim -u minimal.lua
  4. Open an arbitrary file
  5. Open dropbar menu
  6. Press i to enter fuzzy search mode
  7. Search for some pattern
  8. Press <C-w> to delete word before cursor
  9. See the error

Expected behavior

Should not error

Actual behavior

Error.

Additional information

simplescreenrecorder-2023-09-29_20.42.13.mp4
@Bekaboo Bekaboo added the bug Something isn't working label Sep 29, 2023
@Bekaboo
Copy link
Owner Author

Bekaboo commented Sep 29, 2023

@willothy I believe you can come up with a better fix to this bug than I can.

@willothy
Copy link
Collaborator

For sure, I'll look into this tomorrow.

@Bekaboo Bekaboo changed the title [Bug]: [Bug]: <C-w> cause error in fuzzy search mode Sep 29, 2023
willothy added a commit to willothy/dropbar.nvim that referenced this issue Sep 29, 2023
problem: since a large portion of `on_update` is inside of a `vim.schedule`
closure - if all input buffer text is removed quickly, fzf entries can have their `pos`
field removed before the `vim.schedule` callback executes, causing an error.
solution: add a check to ensure that `fzf_entry.pos` is not nil before iterating and
setting extmarks

fixes Bekaboo#97
@willothy
Copy link
Collaborator

willothy commented Sep 29, 2023

Nevermind, found it pretty quickly. Can you see if that works?

The issue is a race condition with the ordering of the first half of on_update and the vim.schedule block in the second half, because the possibility exists that on_update could be called again before the vim.schedule callback runs.

Bekaboo pushed a commit that referenced this issue Sep 29, 2023
problem: since a large portion of `on_update` is inside of a `vim.schedule`
closure - if all input buffer text is removed quickly, fzf entries can have their `pos`
field removed before the `vim.schedule` callback executes, causing an error.
solution: add a check to ensure that `fzf_entry.pos` is not nil before iterating and
setting extmarks

fixes #97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants