Repository navigation
fix(read): only drop a line as a block comment when it starts with the marker - #4205
Protocol-zero-0 wants to merge 1 commit into
Conversation
…e marker MinimalFilter drops whole lines but entered a block comment whenever the marker appeared anywhere in a line. A glob like "src/*.rs" opened a comment that never closed and silently removed the rest of the file, code after a trailing `/* ... */` was dropped with it, and for Python `QUERY = """` was deleted as a one-line comment, changing what the file means (rtk-ai#3425). Enter a block comment only when the line starts with the marker, and for Python treat a mid-line odd count of `"""` as opening or closing a string that is kept, so its body stays and later comments are still stripped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WcTsSr2cKxstnvgXk2bP88
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Two moderate issues remain unresolved in the filtering logic.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR updates MinimalFilter to avoid dropping code around inline markers and preserve Python triple-quoted assignments.
Changes:
- Restricts block-comment detection to line starts.
- Tracks mid-line Python triple-quoted strings.
- Adds regression tests across supported languages.
| File | Summary |
|---|---|
src/core/filter.rs |
Updates filtering logic and tests; two moderate issues remain involving leading comments with trailing code and quote-aware triple-quote detection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if *lang == Language::Python && trimmed.matches("\"\"\"").count() % 2 == 1 { | ||
| in_docstring = !in_docstring; |
|
Thanks for this, and for the careful write-up on #4196. The block-comment change here is the same one as #2397, which fixes the same So I'm closing this in favour of #2397 for the block comments and #3336 for Python. Review or comments on either are welcome there. If you find a case this PR handles and those two don't, reply here and I'll reopen. |

Fixes findings 1 and 2 of #3425 (finding 3, the docs claim for
cat/head, is separate and untouched here).Reproduced on
develop(b748a5f)Cause
MinimalFilterdrops whole lines, but it entered a block comment whenever the marker appeared anywhere in a line (trimmed.contains(start)):"src/*.rs"opened a comment that never closed, so every later line was dropped with no marker.int x = 1; /* ms */outright, code included.""", soQUERY = """was treated as a one-line comment and deleted.Fix
"""but contains an odd number of them opens or closes a triple-quoted string (QUERY = """,text"""). It's kept, and the string state is tracked so its body and closing quotes stay while comments after it are still removed.Whole-line block comments (license headers,
/* ... */blocks) and/**doc blocks behave exactly as before.Tests
Six cases in
core::filter::tests, written first and confirmed failing ondevelop(5 failed, the 2 guards passed):"src/*.rs"in Rust and'src/**/*.ts'in TypeScript keep the code after themint x = 1; /* units: ms */in C keeps the line/* ... */header is still removed (guard)QUERY = """ ... """keeps its opening line# commentafter a triple-quoted assignment is still removed, and docstring content is kept (guard)Relation to #4196
#4196 fixes the single-line docstring toggle (#1322) in the
starts_with("\"\"\"")branch; this PR doesn't touch that branch. The two interact, though: today a single-line docstring leaves the filter stuck "inside a docstring", which happens to hide finding 2 for everything after it. Once #4196 lands,s = """after a one-line docstring would start being dropped too. This PR covers that case. Checked with this file:rtk read d.py -l minimals = """is dropped, leavingmultiand a lone"""# strip meremoved,s = """keptThe two branches merge cleanly (
git merge-tree), and allcore::filtertests from both pass on the merged tree.Verification
cargo fmt --all,cargo clippy --all-targetsandcargo test --allpass locally.