ahrefs / atd

Static types for JSON APIs
Other
308 stars 53 forks source link

atddiff (and other tools): show snippets of code when reporting errors #380

Open mjambon opened 8 months ago

mjambon commented 8 months ago

When using atddiff to compare two revisions of the same file with git (git difftool -x atddiff), we don't have a convenient copy of each file at hand. They are passed to atddiff as temporary files but once atddiff exits, they're lost. Currently, atddiff, like all the other atd tools, only prints error locations as

File "path/to/file.atd", line 42, characters 13-17:

This works fine when the IDE parses the error message and opens the file at the correct location. In other situations, it requires obtaining a copy of the file and opening it manually. It is tedious in the following situations:

To improve the situation, I think we should print a few lines of context, with some highlight for the region of the error. I did this before and it is sufficiently hard to do well that a standalone library may be warranted. Features of such a library should include: