You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rtk ast-grep: the per-file cap cuts inside a structural match, so the kept output is a truncated code fragment #4016
Follow-up from #3857 (not a regression it introduced — the command is new).
ast-grep emits one path:line:content line per source line of a match, and a structural match routinely spans several — that is the stated reason the filter exists. DEFAULT_MAX_PER_FILE = 5 in src/cmds/system/ast_grep_cmd.rs counts lines, so take(max_per_file) can stop halfway through a single match:
$ ast-grep run -p 'LazyLock::new($$$)' -l rust src/cmds/system/ctest_cmd.rs | wc -l
24 # 6 matches
$ rtk ast-grep run -p 'LazyLock::new($$$)' -l rust src/cmds/system/ctest_cmd.rs
src/cmds/system/ctest_cmd.rs:24:static TEST_RE: LazyLock<Regex> = LazyLock::new(|| {
src/cmds/system/ctest_cmd.rs:25: Regex::new(
src/cmds/system/ctest_cmd.rs:26: r"(?s)^\s*(?:\d+/(\d+)\s+)?Test\s+#(\d+):\s+(.+?)\s+\.{2,}...
src/cmds/system/ctest_cmd.rs:27: )
src/cmds/system/ctest_cmd.rs:28: .expect("invalid ctest result regex")
… 19 more match line(s) in src/cmds/system/ctest_cmd.rs
The first match alone is six lines, so the reader gets five-sixths of one match and nothing else — an unbalanced fragment with its closing }); cut off. For a filter whose whole point is block-shaped hits, a file's budget is often less than one complete match.
The fix is a design call rather than a bug fix, which is why it is not part of #3857: cap by match instead of by line, grouping consecutive line runs per file (or read the match boundaries from --json and use them to segment the plain output). Either way the per-file hint should then count matches, and the wording can go back to "matches".
Verified with ast-grep 0.45.3 in Docker (node:22-trixie-slim, LC_ALL=C).
ast-grep's per-file cap counts source lines instead of matches, so take(max_per_file) can truncate mid-match; switch to counting/grouping complete matches (e.g. via --json boundaries).
📁 Relevant files
src/cmds/system/ast_grep_cmd.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
Activity
rtk-wshm-sync-bot commentedon Sep 13, 2026
🔍 Automated Triage
bugmediumSummary
ast-grep's per-file cap counts source lines instead of matches, so
take(max_per_file)can truncate mid-match; switch to counting/grouping complete matches (e.g. via --json boundaries).📁 Relevant files
src/cmds/system/ast_grep_cmd.rsTriaged automatically by wshm · This is an automated analysis, not a human review.