Skip to content

Conversation

gerhardol
Copy link
Member

@gerhardol gerhardol commented Sep 27, 2024

Fixes #11843
Depends on #11862

Proposed changes

  • feat: Avoid coloring moved lines

Use heuristics to select which lines that are candidates to
mark inlines for, avoid lines that Git has detected
as moved lines.
(the change is not complete, a few parts required from the second commit, to be squashed befor merge)

  • feat: Only parse diff files once

Only parse the document for added/removed lines once, by using
the DiffLineInfo info parsed for the linenumbering.
Previously, the document was parsed many times every time the
highlighting (including searching and marking) was changed.
This simplifies the code.

Test methodology

Some kind of tests will be added for the gap change, the other visible change has updated tests.

Merge strategy

Rebase


✒️ I contribute this code under The Developer Certificate of Origin.

@gerhardol gerhardol marked this pull request as draft September 27, 2024 22:58
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

review of first commit:

  • test CanGetAddedMovedDiffInfo needs to be adapted

Comment on lines 26 to 27
public override void AddTextHighlighting(IDocument document)
=> document.MarkerStrategy.AddMarkers(_textMarkers);
Copy link
Member

Choose a reason for hiding this comment

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

❔ Move to a base class?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be TextHighlightService, but there are no textMerkers there.
So overridden in Diff (base), Grep and Difftastic.


namespace GitUI.Editor.Diff;

public struct Segment : ISegment
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the interface?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a TextEditor interface

Copy link
Member Author

Choose a reason for hiding this comment

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

There is one implementation in externals\ICSharpCode.TextEditor\Project\Src\Document\AbstractSegment.cs
Dis not use it due to the name.
The class is only used in this file.

@mstv
Copy link
Member

mstv commented Sep 28, 2024

The first commit does not detect / skip all moved lines. This is fixed up by the second commit. But the first commit should correctly handle all cases.

You have provided another example commit with commit 1e5d99a, file src/app/GitUI/Editor/Diff/DiffHighlightService.cs, lines 210 / 180 ff.

first commit 4aed061:

image

second commit 30da54f:

image

@gerhardol
Copy link
Member Author

* test `CanGetAddedMovedDiffInfo` needs to be adapted

fixed (diff file was added as a displaycase for #119330 and I updated the file after your comments and missed to add this test to my playlist...)

The first commit does not detect / skip all moved lines. This is fixed up by the second commit. But the first commit should correctly handle all cases.

I would rather squash the commits, there are too many changes that will not be used.

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

I would prefer to split the PR after the second commit.

The second commit should remove ref found from GetBlockOfLines already.
maxLine rather is endLine.

public override bool IsSearchMatch(DiffViewerLineNumberControl lineNumbersControl, int indexInText)
=> lineNumbersControl.GetLineInfo(indexInText)?.LineType is DiffLineType.Header;

public override string[] GetFullDiffPrefixes() => _diffFullPrefixes;
Copy link
Member

Choose a reason for hiding this comment

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

❔ Why move GetXxx behind IsYyy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean the order of functions (unchanged, other code in between was changed) or the IsSearch call (FileViewer uses that)?

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean the order of functions

Yes, (GetGitCommandConfiguration and) IsSearchMatch should have been / be moved behind GetFullPrefixes.

unchanged

Only visible in BC after manually matching the lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

no change now

@gerhardol
Copy link
Member Author

I would prefer to split the PR after the second commit.

Can do that after #11862 is merged.

@gerhardol gerhardol force-pushed the feature/difflineinfo-coloring branch from 755675e to d8e6ef8 Compare October 7, 2024 19:53
@gerhardol
Copy link
Member Author

Rebased on #11862 dropped the "gap" part (except the refactoring) and the cache part.

@gerhardol gerhardol force-pushed the feature/difflineinfo-coloring branch from dc68fcc to a03ef88 Compare October 14, 2024 19:33
@gerhardol gerhardol marked this pull request as ready for review October 14, 2024 19:34
@gerhardol gerhardol force-pushed the feature/difflineinfo-coloring branch from 55f1758 to b49e180 Compare October 15, 2024 20:47
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

👍

@gerhardol
Copy link
Member Author

Plan to squash and merge this in two days.
May separate the delimiters change.
As the first commit is not enough, I will squash the commits (do not bother to switch the order, that would fix this too)

Only parse the document for added/removed lines once, by using
the DiffLineInfo info parsed for the linenumbering.
Previously, the document was parsed many times every time the
highlighting (including searching and marking) was changed.
This simplifies the code.
Use heuristics to select which lines that are candidates to
mark inlines for, avoid lines that Git has detected
as moved lines.
@gerhardol gerhardol force-pushed the feature/difflineinfo-coloring branch from 0a9358a to 58af311 Compare October 18, 2024 20:56
@gerhardol gerhardol merged commit 38d2fe4 into gitextensions:master Oct 19, 2024
4 checks passed
@gerhardol gerhardol deleted the feature/difflineinfo-coloring branch October 19, 2024 19:34
@RussKie RussKie added this to the 5.1 milestone Oct 29, 2024
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.

Made up diff coloring (with low contrast)
3 participants