Add a setting for mapping file extensions to syntax highlighters for diffs

Review Request #11821 — Created Sept. 24, 2021 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

Previously, we guess what syntax highlighting to apply to files in the diff
viewer given their data and file extension. Sometimes this guess would be wrong,
and we have no way of setting what type of syntax highlighting gets applied to
files. This change adds a setting for mapping file extensions to pygments
lexers (the syntax highlighters), namely
reviewboard.admin.siteconfig.diffviewer_custom_pygments_lexers. If a mapping
is not defined for a certain file extension, we revert to the old behaviour
of guessing which lexer to use given the filename and file contents.

Adds reviewboard.admin.form_widgets.LexersMappingWidget which partly
handles the UI for modifying this mapping.

  • Created unit tests for the mapping in
    reviewboard.diffviewer.tests.test_raw_diff_chunk_generator.
    Ran all unit tests in reviewboard.diffviewer with success
  • Created the unit tests for the LexersMappingWidget in
    reviewboard.admin.tests.test_lexers_mapping_widget.
    Ran all unit tests in reviewboard.admin.tests with success.

Commits

Files