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

Cursor position outside buffer error in pickers.lua #3163

Closed
jghauser opened this issue Jun 10, 2024 · 5 comments
Closed

Cursor position outside buffer error in pickers.lua #3163

jghauser opened this issue Jun 10, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jghauser
Copy link

jghauser commented Jun 10, 2024

Description

I'm the author of the plugin papis.nvim, which implements a Telescope picker. A user has opened a bug report and reported that they get an error when opening the picker. I've now realised that the only reason I wasn't getting the error was because I had sorting_strategy = "ascending" in my config. Once I changed that, I also started getting the error. It doesn't always happen when opening the picker -- sometimes I need to type some characters first. The error is:

Error executing vim.schedule lua callback: ...mPackages/start/telescope.nvim/lua/telescope/pickers.lua:1472: Cursor position outside buffer                                  
stack traceback:                                                                                                                                                             
        [C]: in function 'nvim_win_set_cursor'                                                                                                                               
        ...mPackages/start/telescope.nvim/lua/telescope/pickers.lua:1472: in function ''                                                                                     
        vim/_editor.lua: in function <vim/_editor.lua:0>

It seems to be triggered by a line that only executes when the sorting_strategy is descending:

if self.sorting_strategy == "descending" then
local visible_result_rows = vim.api.nvim_win_get_height(self.results_win)
vim.api.nvim_win_set_cursor(self.results_win, { self.max_results - visible_result_rows, 1 })
vim.api.nvim_win_set_cursor(self.results_win, { self.max_results, 1 })
else
vim.api.nvim_win_set_cursor(self.results_win, { 1, 0 })
end

The error seems related to (at least) the following other bug reports (though it's caused by a different line/file):

It's of course possible that something is wrong with how I implemented the picker, though I'm at a loss as to how I should further troubleshoot this. I would be very grateful for any pointers!

Neovim version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1693350652

Operating system and version

Nix unstable

Telescope version / branch / rev

35f94f0

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 ===== ~

Telescope Extension: `papis` ~
- No healthcheck provided

Steps to reproduce

I haven't been able to reliably reproduce the issue unfortunately. It requires installing my plugin, and (as far as I can tell) it only occurs when the picker is used to select from a sufficiently big number of entries (which in this case are bibliographic entries in a research library). In my library of about 1800 entries, the error happens very reliably.

My plugin provides a flake.nix with a devShell, where the command nvim-test launches a neovim instance with a minimal library (first clone the repo, then nix develop to enter the devShell). Unfortunately, that also doesn't cause the error as the test library is too small. I'm happy to provide access to my library for troubleshooting or to do whatever on my system to help find out what's going on.

Expected behavior

I would expect the picker to open without errors and for no errors to occur when typing to search among entries.

Actual behavior

The error mentioned in the description occurs.

Minimal config

I've tried to get the minimal config to work but ran into a bunch of problems. Nix seems to make installing the sqlite.lua dependency difficult with packer. The config that I use to test my plugin is in my flake.nix here and is quite minimal. I can try to get this to work in a VM if needed, but I thought I'd ask first -- maybe someone knows what's up with the info provided already.

@jghauser jghauser added the bug Something isn't working label Jun 10, 2024
@jamestrew
Copy link
Contributor

Hm..
I've not experienced this issue even with ~86k entries for find_files with sorting_strategy='descending' or any other pickers even with 1000+ entries.
But there's nothing obviously wrong with your picker either as far as I can tell.
Is the wrap_results option being used in your config?

I'm a little confused about that bit of code to begin with. What's with the double nvim_win_set_cursor call? Seems redundant to me.
Maybe @sultanahamer might have some insight?

@jghauser
Copy link
Author

Thanks a lot for taking a look!

I've not experienced this issue even with ~86k entries for find_files with sorting_strategy='descending' or any other pickers even with 1000+ entries.

It's possible, I suppose, that some particular entry causes the error and that large libraries simply increase the chances of having such an entry. I'll try 'bisecting' my library to see if I can find anything (might only get to it tomorrow, it's rather tedious).

Is the wrap_results option being used in your config?

No, neither my own config nor the test config in my devShell uses this option.

@sultanahamer
Copy link
Contributor

@jghauser stack trace is pointing to line

vim.api.nvim_win_set_cursor(self.results_win, { self.max_results, 1 })

if this has out of bounds issue then try some print statements to check what is the line count in the results buffer. 3rd line in below code should help you print it. Usually its always 250. Could you check if its the same in your case with and without the plugin? You can check the count by looking by running command :messages

      local visible_result_rows = vim.api.nvim_win_get_height(self.results_win)
      vim.api.nvim_win_set_cursor(self.results_win, { self.max_results - visible_result_rows, 1 })
      print(vim.api.nvim_buf_line_count(vim.api.nvim_win_get_buf(self.results_win)) .. "yolo line count")
      vim.api.nvim_win_set_cursor(self.results_win, { self.max_results, 1 })

@jghauser
Copy link
Author

jghauser commented Jun 14, 2024

Thanks for looking into this @sultanahamer! Whenever the error occurs, the line count is 249.

EDIT: And otherwise (without my plugin and when my plugin isn't causing any errors) it's 250.

EDIT2: I've finally gone through the trouble of trying to pin-point the entry that causes the problem and it really seems to be only 1 or 2 files that cause it. This leads me to think that the problem is with my plugin somewhere. I'll get back to you when I find out more! Thanks a lot for the help so far, it's been very useful! ❤️

@jghauser
Copy link
Author

Ok, I found the error. One of the strings contained a \n and I suspect this was also the cause behind my user's error. The mistake is therefore with my plugin not giving telescope proper lines rather than with telescope itself. I'm gonna close this bug report. Thanks again!

olidacombe pushed a commit to olidacombe/jirascope that referenced this issue Sep 23, 2024
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
Development

No branches or pull requests

3 participants