Edgar Herrador (@eherrador) header
Edgar Herrador (@eherrador) profile picture

✨ AI Engineer ✨ Innovation with impact

México
Joined November 2007
The whole file is too much context. The diff hunk is too little. I built a third option: walk the AST from the changed bytes up to the smallest enclosing method/class. 100% resolution rate, 71.8% median size reduction on real PRs. Thread 🧵
1
19
Important caveat, in the paper: 100% resolution ≠ "always tight." TS's definition set is broad, so almost everything resolves to something. The real signal is the reduction distribution — it's bimodal, not clustered near the mean. Full breakdown in the paper.
1
8
5) class/struct/interface should be the last resort, not a first-class target — a floating comment shouldn't pull in the whole class. 6. export class Foo {} is still a class. TS registers export_statement as a valid unit too, so this needs a special case.
1
13
Ran it on 175 real file changes from 37 merged PRs in nestjs/nest (public TS repo, 76.7k⭐): 175/175 resolved a definition node. Median line reduction: 71.8% vs. whole-file.
1
15
3) A doc comment sits before the method it documents, not inside it. Edit both together and your range starts before the node even begins. 4. A pure insertion at a blank line collapses to nothing when you trim whitespace — unless you keep it as a zero-width point.
1
7
Sounds trivial. Wasn't. The naive version silently degrades back to whole-class context on real diffs unless you handle 6 specific edge cases. Each one cost me a real production failure before I found it.
1
4
1. Diff padding lies about the boundary — for short methods it spills into the neighbor, so nothing contains the padded range and you escalate to the class. 2. A trailing ; on a field edit isn't part of the node in some grammars — off-by-one byte, same escalation.
1
3
The whole file is always "enough" — and usually way too much. A one-line fix in a 500-line file buries the signal in noise. Costly for a reviewer's attention, and literally costly for LLM fine-tuning: every irrelevant token dilutes the training signal.
1
12
The fix: parse the file with Tree-sitter, walk the AST from the changed byte range up to the smallest enclosing definition — method, function, class, or field. Not padding. Not the whole file. The actual unit that changed.
1
13
The problem: a unified diff hunk pads the real change with ~3 arbitrary lines of context on each side. For a short method, that padding spills into the neighbor. For a big method, it doesn't even cover the signature. Structurally, it's noise.
1
10
Important caveat, in the paper: 100% resolution ≠ "always tight." TS's definition set is broad, so almost everything resolves to something. The real signal is the reduction distribution — it's bimodal, not clustered near the mean. Full breakdown in the paper.
1
5