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.

Changes between revision 14 and 15

orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Commits

Summary ID Author
Add a setting for mapping file extensions to syntax highlighters for
diffs Adds a default mapping of file extensions to pygments lexers, which administrators may modify to define their own custom mapping. 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.
810c268b04d766208982bd9cc5772fb472ab2e50 Michelle
Uses for else clause and .items() instead of .keys() for searching the
mapping
a5a683ce294e75b13c7c4b600ab1c6b7a2d9416d Michelle
Logs an error if a mapped lexer does not exist in Pygments
6da489bde81ca3eb9df84c3bb4e79425b18b7e45 Michelle
Removed trailing whitespace
8e396cb6f373d3336d411804d2973bb2f06680be Michelle
Properly imports mapping from settings.py
23ec2199b6b867851f9d8d8163a85e9ba9898bce Michelle
fixed string formatting for logged error
5785f25b427e1b18316db43ddcc98e02ba646892 Michelle
Made CUSTOM_PYGMENTS_LEXERS a class attribute (this makes it easier
to modify during testing)
eefc9d52856d30d61963a6d34ebc76102b33bf2b Michelle
took out print statement from testing
967ef3e281d39d468ef4d9c9f360f6a1e28087ec Michelle
Added unit tests for apply_pygment, testing that default
custom mapping works and that mapping to a non existant class logs an error
33139db632f2c36deb14cc9a493c4f33cb6754fe Michelle
Modified doc formatting and changed default test to instead
test if using a custom mapping overrides the guessing function to determine a lexer
224a9d9c751d4525937d3b4cae2f85a5f09d2e6a Michelle
fixed flake8 issues
e6eed2477b86a382140fbe0d215819ea4a17c8a9 Michelle
fixed one last flake8 indent issue
9b1f2c9a68e2161a9d67cb1064ec09063e8aeb50 Michelle
better logging message, fixed formatting issues, removed mapping attribute an...
211c72f95930609b6655ad0f06f229df884d2d62 Michelle
fixed a couple flake8 issues
ad32f6009c25e8d555c19622857422236ee46f5f Michelle
moved mapping to siteconfig instead of settings.py
d7549e8107b35ceae203e9099b2a323bd7e89042 Michelle
initial form for mapping in diff viewer settings
09b9854b63f1c67e6684c300b7c9fd971a65d175 Michelle
added test for empty mapping
a36c2ee69209caa2053c1ea80431762a97cf9379 Michelle
create LexersMappingWidget and using in diff_settings.py for now to test
dfdc4468076bf6d899533efc6fb3c4b9f1088394 Michelle
create tests for lexers mapping widget
2d37e23bb79913a72a2e2c580d2023e73d7449c7 Michelle
testing listeditwidget with custom pygments lexers setting
38a50c83e212b487d4d62537b0fa64c9c6cbe2ff Michelle
add documentation and finalize code
8d4a6d7996c73bee56335d8f5ea55f16d4aee271 Michelle
no need for local site tests
19678b279aef9280842c45bebbf420098da9c9be Michelle
skip extension if its empty string since it would match any file
43a4b9f467132947149f2eb315abbcbd3cccbdb7 Michelle
fix some flake8 issues
df5ee812136e0eb9a94c4358a3288e26401d06fc Michelle
address review feedback
70eabb4e4983c7d39c06520389aaabde45d88b76 Michelle
address feedback
83df1297d190d6aa433b6a07e3acea09e499762f Michelle
fixed styling issues and uses siteconfig context
manager
8e3b46734371907145c91b86a75a4418ab332a6d Michelle
reviewboard/admin/form_widgets.py
reviewboard/admin/forms/diff_settings.py
reviewboard/admin/tests/test_lexers_mapping_widget.py
reviewboard/diffviewer/chunk_generator.py
reviewboard/diffviewer/tests/test_raw_diff_chunk_generator.py
Loading...