Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

fix(inlay_hints): disable strict_indexing for nvim_buf_get_lines #353

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arindas
Copy link

@arindas arindas commented Mar 17, 2023

The last parameter of vim.api.nvim_buf_get_lines() is a boolean called strict_indexing. It causes the following behaviour:

  • When strict_indexing is true out of bounds indices cause an error
  • When strict_indexing is false out of bounds indices are clamped to the nearest valid index.

So we set strict_indexing to false.

Now nvim_buf_get_lines() returns an array, which might be empty. So attempting to access the first element (our line) could evaluate to nil.

So we use "" as the fallback line string value.

Fixes #349

@pgherveou
Copy link

Thanks for this, it fixed the same issue I had 👍

@PSeitz
Copy link

PSeitz commented Apr 17, 2023

Can confirm, this fixes the issue

@tbodt
Copy link

tbodt commented May 16, 2023

@simrat39

MunifTanjim pushed a commit to MunifTanjim/rust-tools.nvim that referenced this pull request May 20, 2023
@MunifTanjim
Copy link

@arindas
Copy link
Author

arindas commented May 20, 2023

I wasn't aware of the strict indexing feature. Thank you. Is there anything actionable from my end?

@MunifTanjim
Copy link

You can update this PR with the suggestion. But until @simrat39 gets back, nobody can merge this.

In the meantime, if you want to use rust-tools.nvim with a few fixes from various PRs, you can use my patched branch: https://github.com/MunifTanjim/rust-tools.nvim/commits/patched

The last parameter of vim.api.nvim_buf_get_lines() is a boolean called
"strict_indexing". It causes the following behaviour:
- When strict_indexing is "true" out of bounds indices cause an error
- When strict_indexing is "false" out of bounds indices are clamped to
the nearest valid index.

Now nvim_buf_get_lines() returns an array, which might be empty. So
attempting to access the first element (our line) could evaluate to nil.

So we use "" as the fallback line string value.
@arindas arindas changed the title fix(inlay_hints): safely call nvim_buf_get_lines with pcall fix(inlay_hints): disable strict_indexing for nvim_buf_get_lines May 20, 2023
@ryo33
Copy link

ryo33 commented Jun 8, 2023

I also start forking at https://github.com/ryo33/rust-tools.nvim-nightly-. But I don't recommend this to most people because I don't mind my fork being broken by eagerly merging many pull-requests without my own review or compatibility check.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Inlay hints: Index out of bounds error
6 participants