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

Using --max-count and --context together does not correctly display syntax highlighting for matched characters #2843

Open
1 task done
5HT2 opened this issue Jun 24, 2024 · 0 comments

Comments

@5HT2
Copy link

5HT2 commented Jun 24, 2024

Please tick this box to confirm you have reviewed the above.

  • I have a different issue.

What version of ripgrep are you using?

ripgrep 14.1.0

features:-simd-accel,+pcre2
simd(compile):+NEON
simd(runtime):+NEON

PCRE2 10.42 is available (JIT is available)

How did you install ripgrep?

Homebrew

What operating system are you using ripgrep on?

$ sw_vers
ProductName:		macOS
ProductVersion:		14.2.1
BuildVersion:		23C71
$ uname -r
23.2.0

Describe your bug.

Using both of these flags together produces the expected output, for example, 2 lines of context with 1 match, but still highlights other matches that were not included due to --max-count.

Because these matches are only being included because of --context, it's unintuitive and confusing to the user to also highlight the text for the matches that weren't actually included.

Related: #1380

What are the steps to reproduce the behavior?

Run rg Pro -m 1 -C 2 therapeutic.txt, you can find this file here:
https://github.com/5HT2C/doses-logger/blob/master/therapeutic.txt

It's also fairly easy to produce a less specific test case yourself on any type of sorted data (where you are just matching the beginning and have context enabled).

What is the actual behavior?

Notice how the lines are also suffixed with : before the line number instead of -.

image

What is the expected behavior?

I feel like this would be much more intuitive:

image

I do understand that there is an argument against the behavior I am proposing, wherein a user might be confused by non-highlighted matches, but I feel like that would be encountered less often than the current behavior, and in the proposed case the issue would lie in "user has forgotten they set the --max-context flag" rather than the program's behavior being inconsistent / confusing.

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

No branches or pull requests

1 participant