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-edit): Support unified diff and refactor diff format #7000

Merged
merged 21 commits into from
Feb 20, 2025

Conversation

umpox
Copy link
Contributor

@umpox umpox commented Feb 7, 2025

https://linear.app/sourcegraph/issue/CODY-4921/auto-edit-support-unified-diff-format-for-image-generations

AutoEditUnifiedDiff.mov

Description

This PR:

  • Adds support for a unified diff format with a different UI. This will be useful for other editors where we do not have support for decorations or will not have it for the MVP
  • Refactors the image generator feature to use DecorationInfo instead of AddedLinesDecorationInfo. This means we can easily port this to the inline decorator in a follow up PR.
  • Generally refactors much of the canvas/highlighting/diff logic. This was necessary to simplify this code as much as possible, as porting to DecorationInfo and supporting deletions here adds a lot of checks/edge cases.

Test plan

@umpox umpox force-pushed the tr/image-unified-diff branch from bbe228c to 6082a72 Compare February 13, 2025 11:36
@umpox umpox force-pushed the tr/image-unified-diff branch from 6082a72 to 84951e4 Compare February 13, 2025 11:38
@umpox umpox marked this pull request as ready for review February 13, 2025 16:13
@umpox umpox marked this pull request as draft February 13, 2025 16:15
@umpox umpox force-pushed the tr/image-unified-diff branch 2 times, most recently from 9339e00 to 663cab5 Compare February 19, 2025 15:37
@umpox umpox force-pushed the tr/image-unified-diff branch from 663cab5 to 247f27b Compare February 19, 2025 15:38
@umpox umpox changed the title feat(auto-edit): Support unified diff feat(auto-edit): Support unified diff and refactor diff format Feb 19, 2025
@umpox umpox marked this pull request as ready for review February 19, 2025 16:56
@umpox umpox requested a review from valerybugakov February 19, 2025 17:18
@umpox umpox requested a review from hitesh-1997 February 19, 2025 17:18
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.

Great work! Tested it locally and added a couple of minor suggestions inline.

Comment on lines +112 to +114
// TODO: Log these errors, useful to see if we run into issues where we're not correctly
// initializing the canvas
throw new Error('Canvas not initialized')
Copy link
Member

Choose a reason for hiding this comment

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

We should figure out why Sentry error reporting isn't working right now. It'd be helpful to check if this issue occurs on users' machines.

Comment on lines +67 to +70
syntaxHighlights.push({
range: [startPos, endPos],
color: token.color || DEFAULT_HIGHLIGHT_COLORS[theme],
})
Copy link
Member

Choose a reason for hiding this comment

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

The contrast on the light theme seems a bit low. Might be because I'm used to a higher-contrast color theme.

Screenshot 2025-02-20 at 16 14 15

It's a bit better for the dark theme:

Screenshot 2025-02-20 at 16 19 39

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it looks much better with the Monokai Dimmed dark theme:

Screenshot 2025-02-20 at 16 23 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's tricky because, the background image of the suggestion comes from your theme, but the syntax highlighting is hardcoded to a specific dark/light theme.

Some of the options we have:

  1. Use a hardcoded background color for light/dark themes. I think we do this for chat right now. Solves the issue with a highlighting mismatch, but maybe becomes a visual annoyance in the users editor.

  2. Find some way to get the users' theme colours. There's no built-in way that VS Code provides to do this, but maybe we could read the file system and the users settings to extract theme data.

@olafurpg
Copy link
Member

@sourcegraph review

Copy link

@sourcegraph-review-agent-eap sourcegraph-review-agent-eap bot left a comment

Choose a reason for hiding this comment

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

@olafurpg Looking good! I've reviewed the code and found no issues to report.

@umpox
Copy link
Contributor Author

umpox commented Feb 20, 2025

many thanks bot

@umpox umpox merged commit 869a625 into main Feb 20, 2025
22 checks passed
@umpox umpox deleted the tr/image-unified-diff branch February 20, 2025 11: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.

3 participants