Skip to content

Add an option to skip leading context lines for a more correct parse #160

@jnareb

Description

@jnareb

The from-repo subcommand of the diff-annotate script supports the --use-repo option,
which makes the script retrieve pre-/post-image contents from the repository, and use it for lexing with Pygments,
instead of using the post-image excerpt (fragment) of the code extracted from the patch / changeset.

The goal of that option is to avoid mis-parse (by Pygments), and mis-attribution of lines,
if the code fragment (post-image extracted from patch) starts in the middle of the code constructs.
For example:

  • multi-line comment in C, C++, Java
  • docstring in Python, Bash, Kotlin

This approach is not possible for when we don't have the repo, or don't have the information about the commit
(or pre-/post-image contents, via extended diff header, like for example index f4b1722757..a3765ae0f1 100644).

Add an option which makes the diff-annotate script to try to parse reconstructed pre- and post-image,
with trimmed leading context lines - as for annotation we need to have correct parse only for added and deleted lines.
This can be done with some error-resistant parser, like parso, by finding the parse with least percentage of errors.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions