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

Detecting moves in the diff editor #181902

Closed
hediet opened this issue May 9, 2023 · 6 comments
Closed

Detecting moves in the diff editor #181902

hediet opened this issue May 9, 2023 · 6 comments
Assignees
Labels
diff-editor Diff editor issues feature-request Request for new features or functionality verified Verification succeeded
Milestone

Comments

@hediet
Copy link
Member

hediet commented May 9, 2023

No description provided.

@hediet hediet added feature-request Request for new features or functionality diff-editor Diff editor issues labels May 9, 2023
@hediet hediet self-assigned this May 9, 2023
@hediet hediet added this to the May 2023 milestone May 9, 2023
@ElianCordoba
Copy link

I’m working in this problem too, although my approach is rather a 180 from myers algorithm and character by character diffing. Here is my work, still very WIP

@hediet
Copy link
Member Author

hediet commented May 22, 2023

@ElianCordoba thanks so much for reaching out!
Your approach looks very interesting! Unfortunately, VS Code does not have a solid infrastructure for ASTs, so the default diff algorithm implementation has to work without understanding of the syntax.

However, I'd like to explore the idea of allowing extensions to contribute (better/language-specific) diff algorithms.
Would you be interested in that?

I'll try to come up with some API ideas how extension contributed diff computers could look in the next couple of days.

Our default diff algorithm implementation initially will only support detecting very simple and straight forward moves that don't have additional changes. For now, the challenge of this issue is the UX.

@ElianCordoba
Copy link

Hi @hediet, thank you for taking the time to look at my work. I'm keen to contribute! I believe there is significant room for improvement in the field of text diffing.

Here are a few quick thoughts. I wanted my tool to be integrated within VSCode so you could check the diff without leaving the editor. There were two ways to do this, but neither convinced me:

  • Use API to create a view: I found this was somewhat limited. The text decorating API wasn't flexible enough to implement a somewhat complex diff UI, which involves more than just marking additions and removals with green and red text. More on this bellow.
  • Go the Iframe route: This could work but it would introduce unnecessary complexity. I'll revisit this option once my project matures, but I would prefer to use the API to leverage all the work you've put into the components.

My tool produces an array of changes, which are objects that holds the necessary infomation to, along side with the sources, render the change. These are a type, which can be deletion, addition, or move. The two ranges, and, in the case of moves a moveID.

When rendering, I take the original source code and locate the ranges to highlight them – additions in green, deletions in red. Moves affect both sources, which I color in blue.

While attempting to implement the move UX with the current API, I encountered a blocker, I couldn't figure out how to create a custom hoverable range, this was what I was trying to archive:

move-diff

For these two ranges, my plan was to color them in blue and, when any of these are hovered over, find the corresponding code with the same ID (on the opposite side) and highlight that too.

Brief note on move UX

I realized that displaying code movements required some effort to make it clear where the code had moved. If the code only moved to the line below, it would be easy to spot because it would be immediately visible. However, if the code moved to the bottom of the file, you would need a way to link the before and after, and this becomes even more crucial when multiple moves are involved.
Ideally, when you highlight a move, you could see this in the minimap and click to select the move to keep it focused. These features are especially useful when the move is far off and you have to scrolling to view the new location.
A more ambitious idea was to draw some kind of arrow linking the two ranges. Here's an example from another project that uses arrows to visually link ranges.

image

This is the website of that project

@hediet
Copy link
Member Author

hediet commented May 24, 2023

Some example.

It would be nice to show this diff.

@hediet hediet modified the milestones: May 2023, June 2023 May 26, 2023
@hediet
Copy link
Member Author

hediet commented May 31, 2023

Work in progress update:

Code_-_OSS_uQicJt9AFW

The border has to be tweaked and there should be a button to toggle alignment.

@hediet hediet modified the milestones: June 2023, July 2023 Jun 27, 2023
@hediet
Copy link
Member Author

hediet commented Jul 10, 2023

This feature is now available in the latest stable.

set "diffEditor.experimental.useVersion2": true and "diffEditor.experimental.showMoves": true to try it.

See #187432 for the remaining tasks.

@hediet hediet closed this as completed Jul 10, 2023
@hediet hediet added the verification-needed Verification of issue is requested label Jul 21, 2023
@ulugbekna ulugbekna added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Jul 25, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
diff-editor Diff editor issues feature-request Request for new features or functionality verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants