Skip to content

Conversation

mstv
Copy link
Member

@mstv mstv commented Jan 4, 2025

Proposed changes

  • Pass argument --show-function to git grep

Screenshots

Before

image

After

first commit with

git config --global color.grep.matchSelected "yellow reverse"

image

second commit
image

second commit with additional git config

git config --global color.grep.function "white reverse"

image

Test methodology

  • manual

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


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

@mstv mstv self-assigned this Jan 4, 2025
@@ -2388,6 +2389,7 @@ public async Task<ExecutionResult> GetGrepFileAsync(
GitArgumentBuilder args = new("grep", commandConfiguration: commandConfiguration)
{
"--line-number",
{ showFunctionName, "--show-function" },
Copy link
Member

Choose a reason for hiding this comment

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

0
This can be added in the options too, persistent
Implementation OK, will think if I want this or not

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

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

I'm fine with the change, defer to @gerhardol for the opinion.

and remove surrounding empty lines
@mstv
Copy link
Member Author

mstv commented Jan 5, 2025

I have tuned the GrepHighlightService (refer to updated PR description) in order to get a similar presentation as for diffs with

git config --global color.diff.frag "white reverse"
git config --global color.diff.func "white reverse"

image

Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

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

-1 for the removal of context
-0 to add this by default
I can get rid of this by adding --no-show-function in options, but prefer it was the other way around. It could be as --show-function is default if null, but empty is respected.
A dropdown with recent (even persistent?) and proposed options could be added. (and options for the most important settings, but avoid if possible).

@@ -90,12 +90,6 @@ private void SetText(ref string text)
{
if (line == "--")
{
if (sb.Length > 0)
Copy link
Member

Choose a reason for hiding this comment

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

With this removal there is no divider between matches, so you do not see where one match end and another start.
If there is a function, you get a "divider" but it is confusing otherwise.
You may add some other visual atleast in the lineno panel (like the diffmarkers), but I assume not in this PR

image

But you want to get rid of the extra context around the function names.
Some lookbehind parsing is needed to remove those.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have restored the empty lines if there is no function header.

get rid of this

hard words
What is the benefit of an empty line instead of one which provides useful information?
Have you ever wanted to get rid of hunk headers of diffs? I do not see why it should be different for grep.

It could be as --show-function is default if null, but empty is respected.

Works. But this would be pretty lossy because once deleted, you have to remember it or RTM in order to get it back.
Most inconvenient: A new default value will not be applied for existing users.


git config --global color.grep.matchSelected "yellow reverse"

This was just the explanation why the screenshots look as they do and a hint for users like me who find the default red color very confusing (git issue).

Copy link
Member

Choose a reason for hiding this comment

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

get rid of this
hard words
What is the benefit of an empty line instead of one which provides useful information?
Have you ever wanted to get rid of hunk headers of diffs? I do not see why it should be different for grep.

I said that I can get of this, I am a 0 on adding the function by default (I do not want it myself, I use ctrl-e and prefer that it is the same as for diff, where this can be added)
There was no intention of being offensive - everything will not be to my preference and I prefer going forward than not moving at all

But function is not always displayed, so just --show-function is not dividing matches.
The example was from 123 to 136 without any visual marker. There is no new function there, but a few lines up:

image

There is still no indication where a match ends. One way to do that is to change the lineno color, but I prefer a more visible marker.
This is still a -1

It could be as --show-function is default if null, but empty is respected.
Works. But this would be pretty lossy because once deleted, you have to remember it or RTM in order to get it back.
Most inconvenient: A new default value will not be applied for existing users.

Just throwing up ideas for what I find OK with setting this as default.
Regardless of what is the default, the override should be made accessible somehow.
Not necessarily for this PR, a non committed plan is enough

This was just the explanation why the screenshots look as they do and a hint for users like me who find the default red color very confusing (git issue).

I agree, document config or maybe change.
git-grep is not much described though in GE doc (how many really use that?)

@gerhardol
Copy link
Member

git config --global color.grep.matchSelected "yellow reverse"

red-reverse was used as default as that is what Git uses. I still lean to that, even if it not the most intuitive, I do not want another local/remote red/green switch. But this could be changed.

But it should be documented better

@gerhardol
Copy link
Member

I have pushed a change that adds the function as context and skips adjacent empty lines, with that I am satisfied.
Then the function justs add information

image
image

@mstv
Copy link
Member Author

mstv commented Jan 6, 2025

There is still no indication where a match ends.

I see. I had quickly tried to check this. But that example did not show that "git grep" uses a completely different approach than "git diff", which is surprising and confusing to me - and will be.

I have pushed a change that adds the function as context and skips adjacent empty lines, with that I am satisfied.

Thank you! SetIfUnsetInGit will be useful in other places, too.

Then the function just adds information

This is was what I wanted and expected to achieve.
Your implementation is a good compromise regarding:

Unfortunately, the git-grep approach is special. It adds context lines also before the function header (lines 9-10, 32-34). (The header line counts as context then.) Now, I have got the logic why all those separators are added or omitted.
("git diff" feels more intuitive. Maybe, I am just too used to it.)

image

and adds separators instead of the single omitted lines:

image

There is still no indication where a match ends. One way to do that is to change the lineno color, but I prefer a more visible marker.

Your implementation keeps the stand-alone separators.
For gaps around function headers, we could draw horizontal lines in a follow-up.


git-grep is not much described though in GE doc (how many really use that?)

I thought I would not use it - except for replacing the file tree.
But it is so much faster than filesystem-based searches, e.g. in VS Code & Total Commander.

@gerhardol
Copy link
Member

Adding a function name in diff willl give the same result as for git-grep, the related lines have precedence over the function name. But git-diff add a separate header.
I would prefer some separator when the line does not match, preferably also at line 92/95 in my example. This could be a separate marker like the diff marker you added. Another is a bolder color at each change (like git-diff handle moved code).

I thought I would not used it - except for replacing the file tree.
But it is so much faster than filesystem-based searches, e.g. in VS Code & Total Commander.

and it only search the repo, not the submodules.
rip-grep is great too
I have used ICSharpCode a lot more now than Visual Studio Code.

@mstv mstv merged commit 5468384 into gitextensions:master Jan 7, 2025
3 of 4 checks passed
@mstv mstv deleted the feature/grep_show_function branch January 7, 2025 22:34
@mstv mstv added this to the v5.2 milestone Jan 8, 2025
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