`-U` merges adjacent matches: `-o`, `--vimgrep`, `--count-matches` and `--json` report one match instead of two
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 85/100
Línea de trabajo
Empieza en tgrep-cli/src/matching.rs, especialmente en group_spans_by_line, FileMatches::find y match_count; después, lee la prueba existente group_spans_merges_overlapping_ranges_on_one_line. Ejecuta los comandos de reproducción con el patrón a contra aa en modo multilínea y añade pruebas de regresión para los modos de salida afectados. El trabajo estará listo cuando las coincidencias contiguas permanezcan separadas y las pruebas confirmen que el recuento y la salida coinciden.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
With -U/--multiline, matches that touch each other on the same line are merged into one span. -o, --vimgrep, --count-matches and --json then report fewer, longer matches than ripgrep. --stats still counts them correctly, so the counts tgrep reports disagree with each other.
Without -U the same search reports each match separately, as ripgrep does.
Reproduce
mkdir repro && cd repro
printf 'aa\n' > a.txt
tgrep --no-index -U -o -n a a.txt
tgrep --no-index -U --vimgrep a a.txt
tgrep --no-index -U --count-matches a a.txt
tgrep --no-index -U --json a a.txt
tgrep --no-index -U --stats a a.txt
tgrep --no-index -o -n a a.txt # control: without -U
| Query | Actual: tgrep | Expected: rg 15.1.0 |
|---|---|---|
-U -o -n |
1:aa |
1:a, 1:a |
-U --vimgrep |
a.txt:1:1:aa |
a.txt:1:1:aa, a.txt:1:2:aa |
-U --count-matches |
1 |
2 |
-U --json |
one submatch aa (0–2); "matches":1 |
two submatches a (0–1, 1–2); "matches":2 |
-U --stats |
2 matches (1 matched lines) |
— |
-o -n (no -U) |
1:a, 1:a |
1:a, 1:a |
The README states that under -U, "--vimgrep reports one row per match, on its starting line".
Environment
- tgrep 1.1.0, built from 1120aca (current
main) with rustc 1.95.0 (59807616e 2026-04-14) - Windows 11 Pro (build 28000); the code involved is platform-independent
- Same results with
--no-index, with a local index, and throughtgrep serve(checked for-oand--count-matches)
Cause
In multiline mode, FileMatches::find passes the regex spans to group_spans_by_line, which merges a span into the previous one when span.0 <= last.1:
So the touching spans (0, 1) and (1, 2) become (0, 2). match_totals counts the spans before merging, which is why --stats says 2. match_count, used by --count-matches, and the per-match output of -o, --vimgrep and --json use the merged spans.
Possible fix
Regex matches never overlap, so merging only needs to join spans that really overlap: span.0 < last.1 keeps touching matches apart and still satisfies group_spans_merges_overlapping_ranges_on_one_line. Alternatively, keep the original spans for per-match output and --count-matches, and merge only for highlighting.
A regression test could check the queries above for aa with pattern a.
- Lenguaje dominante
- Rust
- Estrellas
- 3.4k
- Forks
- 138
- Merge medio
- 12 h 47 min
- PR fusionados (30 d)
- 30
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/tgrep
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 57/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/tgrep
Issues similares
-
[Feature] 设置里面的同步功能Abiertoenhancement user-priority/P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
agent:triaged bug bughunt pm:npm priority:p1
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
SocketDev/socket-patch#1127 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día