microsoft / vscode

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

Git Diff if statement braces #38214

Closed arunAtUman closed 6 years ago

arunAtUman commented 6 years ago

I made a change to a C++ file on an if statement at the end of a function I added braces to the if statement changing it from

if (condition)
    dothis;

To:

if (condition) {
    dothis;
}

Please refer to the attached pic of git diff. gitdiff_error It confusing the end of the function brace and the if statement's end brace. Hope this makes sense.

Thanks!

4 10.0.16299

Extension Author (truncated) Version
sourcetrail ast 0.0.2
githistory don 0.2.3
python ms- 0.8.0
cpptools ms- 0.14.2
python tht 0.2.3
clang-format xav 1.6.0

Steps to Reproduce:

1. 2.

Reproduces without extensions: Yes/No

roblourens commented 6 years ago

It may look more as expected if you set "diffEditor.ignoreTrimWhitespace": false.

joaomoreno commented 6 years ago

@alexandrudima I forget if we already have such heuristics in our diff algorithm.

alexdima commented 6 years ago

We have some heuristics to give a prettier diff, but none of them cover this case.

@arunAtUman For a quick explanation:

Because in most source code trailing whitespace is inconsequential, we feed all lines in a trimmed fashion to the LCS algorithm.

The LCS algorithm can return two variants for the "equal" lines: one where (A3) matches (B3), and one where (A3) matches (B4). Both variants are technically Longest Common Subsequences. It just so happens that in this case it would have looked better if (A3) would have matched (B4).

arunAtUman commented 6 years ago

Thanks for the explanation @alexandrudima! Would like to see it diff as it should but I understand if its relatively low priority

vscodebot[bot] commented 6 years ago

This iteration we focus on issue grooming. This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!