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 8 and 9

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.
3e4ddeda899f0e5d97f02ed070d7525662ee33c5 Michelle
Uses for else clause and .items() instead of .keys() for searching the
mapping
97a6bd3547ff2c3af0708640538d75ef4a55f1c8 Michelle
Logs an error if a mapped lexer does not exist in Pygments
13f279fa09f30803a02621e13192942b95e80460 Michelle
Removed trailing whitespace
d27cc3d581a53a7fd414db5efc820cba92ba9fb3 Michelle
Properly imports mapping from settings.py
8eb445508de1a38aae178bc59477b585f681bbd6 Michelle
fixed string formatting for logged error
dafacdae4c204636121480ab9b3821ffec9ff889 Michelle
Made CUSTOM_PYGMENTS_LEXERS a class attribute (this makes it easier
to modify during testing)
45754bd19bf4ae4ae6f9582e725557ddf0e3c976 Michelle
took out print statement from testing
5fb349b3f4d0adb8a4f0c0b25d3df3611a446220 Michelle
Added unit tests for apply_pygment, testing that default
custom mapping works and that mapping to a non existant class logs an error
c29591ba2ab98206ea65f12b248826d2e5ad5eac Michelle
Modified doc formatting and changed default test to instead
test if using a custom mapping overrides the guessing function to determine a lexer
f853203d6bcadd51d4e9dcfe9561607034023ab7 Michelle
fixed flake8 issues
f734b34e8ddc5eca2a3000f71feab356c0541cfd Michelle
fixed one last flake8 indent issue
d3dd8e59f73f2c246e6f04ab57c4b2dbfaa87f4b Michelle
better logging message, fixed formatting issues, removed mapping attribute an...
5e248bac7d732347961213f7a83934a07c604426 Michelle
fixed a couple flake8 issues
d1a3b05fd934f96b700bb87b60e2613e89df833f Michelle
moved mapping to siteconfig instead of settings.py
02756419d83742c1b0181d806bdb57b3cd6661aa Michelle
initial form for mapping in diff viewer settings
fbd7700720326e780e696c44181650451beaad95 Michelle
added test for empty mapping
faa04403111580a7b8494fc726904764887bac9a Michelle
create LexersMappingWidget and using in diff_settings.py for now to test
48047abe632054dd35db53369725cb063e7f3ff4 Michelle
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
This diff has been split across 4 pages: 1 2 3 4 >
.browserslistrc
AUTHORS
dev-requirements.txt
reviewboard/diffviewer/tests/test_forms.py
reviewboard/extensions/hooks.py
reviewboard/hostingsvcs/tests/test_assembla.py
reviewboard/integrations/__init__.py
reviewboard/reviews/models/review_request.py
reviewboard/reviews/tests/test_review_request.py
reviewboard/scmtools/core.py
reviewboard/scmtools/fixtures/test_scmtools.json
reviewboard/scmtools/tests/test_bazaar.py
reviewboard/scmtools/tests/test_cvs.py
reviewboard/scmtools/tests/test_git.py
reviewboard/scmtools/tests/test_hg.py
reviewboard/scmtools/tests/test_perforce.py
reviewboard/scmtools/tests/test_svn.py
reviewboard/scmtools/tests/testcases.py
reviewboard/static/rb/js/.jshintrc
reviewboard/static/rb/js/collections/baseCollection.es6.js
This diff has been split across 4 pages: 1 2 3 4 >
Loading...