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

feat(auto-edits): fix the suffix duplication on inline accept #6583

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

hitesh-1997
Copy link
Contributor

@hitesh-1997 hitesh-1997 commented Jan 9, 2025

Context

For the auto-edits feature, the suffix is duplicated on every inline suffix. This is a regression from the current pre-release, and this is affecting almost every inline completion suggestion spanning multiple lines. This is happening because, for inline completion item acceptance:

  1. First vscode internally accepts the completion and replace in editor and
  2. Our custom acceptEdit replaces the replaced text from vscode

Linear Issue Link

Before
Suggestion:
image

On Acceptance:
image

After
Replaces the correct suggestion without suffix duplication:
image

Test plan

Inline Examples from the cody-chat-eval repo

@hitesh-1997 hitesh-1997 marked this pull request as draft January 9, 2025 23:31
await editor.edit(editBuilder => {
editBuilder.replace(activeRequest.codeToReplaceData.range, activeRequest.prediction)
})
if (this.activeRequest && this.hasInlineDecorationOnly()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@umpox @valerybugakov Added this condition which helps fix the issue. Seems like vscode internally replaces the text and then this event again replaces the updated text, causing the issue.

Copy link
Member

Choose a reason for hiding this comment

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

Pushed a small update to precompute hasInlineDecorationOnly before the handleDidHideSuggestion call.

@valerybugakov valerybugakov marked this pull request as ready for review January 10, 2025 02:39
Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

TY!

@sourcegraph-release-bot
Copy link
Collaborator

The backport to jb-v7.8.x failed at https://github.com/sourcegraph/cody/actions/runs/12711107455:

The process '/usr/bin/git' failed with exit code 1

To backport this PR manually, you can either:

Via the sg tool

Use the sg backport command to backport your commit to the release branch.

sg backport -r jb-v7.8.x -p 6583
Via your terminal

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-jb-v7.8.x jb-v7.8.x
# Navigate to the new working tree
cd .worktrees/backport-jb-v7.8.x
# Create a new branch
git switch --create backport-6583-to-jb-v7.8.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e56f4f7f635d0a5701c725bb9b0d9396b88925a6
# Push it to GitHub
git push --set-upstream origin backport-6583-to-jb-v7.8.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-jb-v7.8.x

If you encouter conflict, first resolve the conflict and stage all files, then run the commands below:

git cherry-pick --continue
# Push it to GitHub
git push --set-upstream origin backport-6583-to-jb-v7.8.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-jb-v7.8.x
  • Follow above instructions to backport the commit.
  • Create a pull request where the base branch is jb-v7.8.x and the compare/head branch is backport-6583-to-jb-v7.8.x., click here to create the pull request.

Once the pull request has been created, please ensure the following:

  • Make sure to tag @sourcegraph/release in the pull request description.

  • kindly remove the release-blocker from this pull request.

hitesh-1997 added a commit that referenced this pull request Jan 10, 2025
…n on inline accept (#6590)

## Context

For the `auto-edits` feature, the suffix is duplicated on every inline
suffix. This is a regression from the current pre-release, and this is
affecting almost every inline completion suggestion spanning multiple
lines. This is happening because, for inline completion item acceptance:
1. First vscode internally accepts the completion and replace in editor
and
2. Our custom acceptEdit replaces the replaced text from vscode

[Linear Issue
Link](https://linear.app/sourcegraph/issue/CODY-4652/fix-duplicate-code-inserted-when-inline-completion-accepted)

**Before**
Suggestion:
<img width="325" alt="image"
src="https://github.com/user-attachments/assets/76835430-f6aa-4b03-9407-bce25e28badf"
/>

On Acceptance:
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/1c18168a-dc8f-44af-9c09-5ae8e401e41f"
/>

**After**
Replaces the correct suggestion without suffix duplication:
<img width="279" alt="image"
src="https://github.com/user-attachments/assets/b8505644-5686-4171-8351-8d054bf0946c"
/>


## Test plan
Inline Examples from the [cody-chat-eval repo
](https://github.com/sourcegraph/cody-chat-eval/blob/main/code-matching-eval/edits_experiments/examples/renderer-testing-examples/suffix-duplication-issue.ts)
 <br> Backport e56f4f7 from #6583

Co-authored-by: Hitesh Sagtani <[email protected]>
hitesh-1997 added a commit that referenced this pull request Jan 12, 2025
Adds the test case for the two issues we faced:
1. Tab not working when conflicted with edit command decorations.
[Resolves
comment](#6581 (comment))
- [test cases for PR](#6581)
2. Suffix getting duplicated because in addition to inline acceptance,
we were modifying the document again on accept - [[test case for
PR](#6583)]

## Test plan
Added test case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants