diff options
author | Luke Granger-Brown <git@lukegb.com> | 2020-06-14T11·37+0100 |
---|---|---|
committer | lukegb <lukegb@tvl.fyi> | 2020-06-14T17·24+0000 |
commit | 89b3ab939bd4e04ce22cc0bb8cc143dee7e2480c (patch) | |
tree | 3afcb827ab2e0a0e3c765fc2d514cd4a859b75e7 /third_party | |
parent | 5ae0e44d1b02231dff67388a7ac57cf82a14926b (diff) |
feat(gerrit): Syntax highlight rules.pl as Prolog. r/952
This adds support for overriding the detected languages based on the filename - we assume here that rules.pl will always map to a Prolog file. I could've overridden the entire default language to Prolog, since it's unlikely that we'll have any Perl here, but given the relative popularity of the two languages I opted to just override the file we know we'll have (because it's used by Gerrit itself). https://usercontent.irccloud-cdn.com/file/yhZZx1nd/highlighted_prolog.png Change-Id: I26a7e6dab191e0b80a027b026f884020a1f07178 Reviewed-on: https://cl.tvl.fyi/c/depot/+/254 Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/gerrit/default.nix | 1 | ||||
-rw-r--r-- | third_party/gerrit/syntax_highlight_rules_pl.patch | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/third_party/gerrit/default.nix b/third_party/gerrit/default.nix index 1db37afedc73..c7ab47cd66be 100644 --- a/third_party/gerrit/default.nix +++ b/third_party/gerrit/default.nix @@ -42,6 +42,7 @@ pkgs.buildBazelPackage { patches = [ ./use_detzip.patch ./syntax_highlight_nix.patch + ./syntax_highlight_rules_pl.patch ]; bazelTarget = "release"; diff --git a/third_party/gerrit/syntax_highlight_rules_pl.patch b/third_party/gerrit/syntax_highlight_rules_pl.patch new file mode 100644 index 000000000000..ccc59b6b46b4 --- /dev/null +++ b/third_party/gerrit/syntax_highlight_rules_pl.patch @@ -0,0 +1,32 @@ +diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +index 1a0bbd9f50..d8d2fa643b 100644 +--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js ++++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +@@ -102,6 +102,10 @@ const LANGUAGE_MAP = { + }; + const ASYNC_DELAY = 10; + ++const FILENAME_OVERRIDES = { ++ 'rules.pl': 'prolog', ++}; ++ + const CLASS_WHITELIST = { + 'gr-diff gr-syntax gr-syntax-attr': true, + 'gr-diff gr-syntax gr-syntax-attribute': true, +@@ -233,10 +237,16 @@ class GrSyntaxLayer extends GestureEventListeners( + } + } + ++ _basename(filename) { ++ const pieces = filename.split(/\//); ++ return pieces[pieces.length-1]; ++ } ++ + _getLanguage(diffFileMetaInfo) { + // The Gerrit API provides only content-type, but for other users of + // gr-diff it may be more convenient to specify the language directly. + return diffFileMetaInfo.language || ++ FILENAME_OVERRIDES[this._basename(diffFileMetaInfo.name)] || + LANGUAGE_MAP[diffFileMetaInfo.content_type]; + } + |