printer: vimgrep now only prints one line

It turns out that the vimgrep format really only wants one line per
match, even when that match spans multiple lines.

We continue to support the previous behavior (print all lines in a
match) in the `grep-printer` crate. We add a new option to enable the
"only print the first line" behavior, and unconditionally enable it in
ripgrep. We can do that because the option has no effect in single-line
mode, since, well, in that case matches are guaranteed to span one line
anyway.

Fixes #1866
This commit is contained in:
Andrew Gallant
2021-05-30 21:36:35 -04:00
parent 578e1992fa
commit fc31aedcf3
5 changed files with 140 additions and 12 deletions

View File

@@ -917,10 +917,12 @@ rgtest!(r1866, |dir: Dir, mut cmd: TestCommand| {
"test",
]);
// vimgrep only wants the first line of each match, even when a match
// spans multiple lines.
//
// See: https://github.com/BurntSushi/ripgrep/issues/1866
let expected = "\
test:1:1:foobar
test:2:1:foobar
test:3:1:foo quux
test:3:5:foo quux
";
eqnice!(expected, cmd.stdout());