error-lens.nvim icon indicating copy to clipboard operation
error-lens.nvim copied to clipboard

Fix: Prevent out-of-range line error in set_highlight function

Open WebDeveloperBen opened this issue 1 year ago • 1 comments

Pull Request Body

This pull request adds a safeguard to the set_highlight function in error-lens.nvim to prevent errors when attempting to highlight diagnostics that reference lines outside the valid range of the buffer.

Problem

Previously, error-lens.nvim could encounter an error (Invalid 'line': out of range) when calling nvim_buf_set_extmark or nvim_buf_add_highlight if a diagnostic line number was out of range. This would disrupt the highlighting and could lead to plugin errors, especially when diagnostics are provided asynchronously or if a buffer is changed dynamically.

Solution

This fix adds a check to ensure diagnostic.lnum is within the buffer’s line count before attempting to highlight it. Specifically:

The function now verifies that diagnostic.lnum is between 0 and the total number of lines in the buffer. If diagnostic.lnum is out of range, the function skips highlighting for that diagnostic, thus preventing the error.

WebDeveloperBen avatar Nov 13 '24 03:11 WebDeveloperBen

Hey @WebDeveloperBen appreciate your commit! Thanks for fixing that.

I've seen you changed the indentation in the file, this should be consistent throughout the project. Would it be possible for you to change that so its consistent?

chikko80 avatar Dec 20 '24 10:12 chikko80