Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Fix offset conversions at the end of the document#2203

Merged
pkukielka merged 1 commit intomainfrom
pkukielka/fix-edit-replace
Sep 3, 2024
Merged

Fix offset conversions at the end of the document#2203
pkukielka merged 1 commit intomainfrom
pkukielka/fix-edit-replace

Conversation

@pkukielka
Copy link
Copy Markdown
Contributor

Fixes #2196

Changes

Conversion of the end of range to offset was buggy.
VSC sometimes sends -1 as line index. If the start or end position of the range is outside the document, the corresponding offset should be set to 0 or the document's text length, respectively.
But in case of the end range we were setting it to 0.

To avoid that mistake:

  • I changed Position::toOffset method name to Position::toOffsetOrZero to be very explicit of what it does. It should not be used for ranges, but sometimes we only have a single position (like for a text insert).
  • I added Range::toOffsetRange which returns pair of offsets, correcting them appropriately depending if position is a start or end

Test plan

  1. Login to Cody with Free/Pro user
  2. Create new empty python file called quicksort.py, make sure it's empty
  3. Ask Cody to "create a quicksort function"
  4. Click on Apply, make sure code is added to source code file
  5. Click on Reject

Edit should be properly rejected and file should be empty again.

Copy link
Copy Markdown
Contributor

@mkondratek mkondratek left a comment

Choose a reason for hiding this comment

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

lgtm

@pkukielka pkukielka merged commit fde7f3c into main Sep 3, 2024
@pkukielka pkukielka deleted the pkukielka/fix-edit-replace branch September 3, 2024 10:19
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.

JetBrains: Clicking on reject doesn't remove code from source code file

2 participants