Skip to content

Conversation

@tris203
Copy link
Collaborator

@tris203 tris203 commented Nov 6, 2025

Ensure that the deletion preview's end_col does not exceed the length of the existing line, preventing potential errors when highlighting deletions in the buffer. This improves robustness when displaying deletion previews.

Fix #52
Fix #58

Ensure that the deletion preview's end_col does not exceed the length of the
existing line, preventing potential errors when highlighting deletions in the
buffer. This improves robustness when displaying deletion previews.
Ensure that edits and preview insertions beyond the buffer's end are
handled gracefully. Adjusts logic to walk to the last line if the edit
range exceeds buffer length, and fixes preview rendering for insertions
at the buffer's end.
@tris203 tris203 requested a review from Xuyuanp November 7, 2025 00:10
@tris203
Copy link
Collaborator Author

tris203 commented Nov 7, 2025

CC @AntoineGS

@tris203 tris203 requested a review from Copilot November 7, 2025 00:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds defensive boundary checks to prevent errors when dealing with buffer line ranges that exceed the actual buffer size, particularly in the NES (Next Edit Suggestion) UI functionality.

  • Adds handling for edge cases where edit ranges reference lines beyond the buffer's end
  • Fixes potential extmark errors when deletion ranges or insertion lines exceed buffer boundaries
  • Adds the strict = false parameter to extmark calls to allow more lenient positioning

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
lua/copilot-lsp/nes/ui.lua Adds boundary checks for line insertions and deletions, including handling when num_old_lines == 0, clamping deletion end columns to existing line length, and adjusting insertion line positions when at buffer end
lua/copilot-lsp/nes/init.lua Adds logic to handle cursor walking when the edit start line is beyond the buffer's end, redirecting to the last valid line instead

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add a new test to verify that suggestion previews are preserved even when
deletions occur before the response is displayed. Includes corresponding
screenshots for visual verification.
Update preview logic to correctly handle cases where insertion line is past
the buffer end. Adjust line calculation to avoid out-of-bounds errors and
ensure preview displays as expected. Add test case and screenshot for
insertion beyond buffer end.
Simplifies the "deletions before response" test in ui_preview by removing
redundant screenshot and state checks. Updates variable names for clarity
and applies text edits directly. Removes obsolete screenshot file.
Copy link
Contributor

@Xuyuanp Xuyuanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tris203 tris203 merged commit 884034b into main Nov 10, 2025
9 checks passed
@tris203 tris203 deleted the clamp branch November 10, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attempt to get length of a nil value Invalid "end_col": out of range

3 participants