Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offset conversions at the end of the document #2203

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

pkukielka
Copy link
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
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
6 of 7 checks passed
@pkukielka pkukielka deleted the pkukielka/fix-edit-replace branch September 3, 2024 10:19
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.

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