microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.22k stars 29.29k forks source link

Git diff highlighting is broken sometimes #28249

Closed MA-Maddin closed 7 years ago

MA-Maddin commented 7 years ago
Extension Author Version
file-icons file-icons 1.0.3
Angular2 johnpapa 2.2.3
java redhat 0.2.0 ;

I don't know how it is called, but the green and blue "code changes highlighting" on the left seems broken in some situations.

I already have saved the file multiple times, restarted VS Code, restarted PC.

See this video: https://www.youtube.com/watch?v=AQuVR_SeUB4

Maybe related with #27715

Steps to Reproduce: I don't yet know how to reproduce it.

joaomoreno commented 7 years ago

They aren't broken. It's just how the diff algorithm works. We never implemented heuristics for it. @alexandrudima can provide more details.

alexdima commented 7 years ago

@MA-Maddin Text diff algorithms in general, and also the one in VSCode, are implemented using an algorithm known as LCS (Longest Common Substring). This means that the diff algorithm will try to identify the most amount of matching lines and then will map the non-matched lines to either deletes or inserts.

Sometimes, there are multiple LCSs between two list of lines (between two files). Some of them are more human pleasing, or reflect the actual inserted lines, some do not.

This is, unfortunately, the state-of-the-art when using an LCS diff algorithm. Better algorithms include doing a diff on the AST, but we don't have that. i.e. we are similar to git in this respect.