rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

fix(inlay_hints): disable strict_indexing for nvim_buf_get_lines

Open arindas opened this issue 2 years ago • 7 comments

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

arindas avatar Mar 17 '23 08:03 arindas

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

pgherveou avatar Mar 30 '23 09:03 pgherveou

Can confirm, this fixes the issue

PSeitz avatar Apr 17 '23 08:04 PSeitz

@simrat39

tbodt avatar May 16 '23 18:05 tbodt

I've pulled this in https://github.com/MunifTanjim/rust-tools.nvim/tree/patched

MunifTanjim avatar May 20 '23 07:05 MunifTanjim

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

arindas avatar May 20 '23 07:05 arindas

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

MunifTanjim avatar May 20 '23 07:05 MunifTanjim

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.

ryo33 avatar Jun 08 '23 04:06 ryo33