From b82b920420c937cd2d3180f9f0a1ee5a4297c524 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 8 Feb 2025 21:06:33 +0200 Subject: [PATCH 1/3] attempt to fix syslog error highlighting --- assets/syntaxes/02_Extra/log.sublime-syntax | 24 +++++++-------- .../syntaxes/02_Extra/syslog.sublime-syntax | 30 ++++++++++--------- .../syntax-tests/source/Syslog/example.syslog | 1 + 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/assets/syntaxes/02_Extra/log.sublime-syntax b/assets/syntaxes/02_Extra/log.sublime-syntax index a68c7e83..0ce01f10 100644 --- a/assets/syntaxes/02_Extra/log.sublime-syntax +++ b/assets/syntaxes/02_Extra/log.sublime-syntax @@ -38,21 +38,21 @@ contexts: scope: markup.underline.link.scheme.log push: url-host log_level_lines: - - match: ^(?=.*{{error}}) + - match: (?=.*{{error}}) push: - - error_line + - error_line_meta - main_pop_at_eol - - match: ^(?=.*{{warning}}) + - match: (?=.*{{warning}}) push: - - warning_line + - warning_line_meta - main_pop_at_eol - - match: ^(?=.*{{info}}) + - match: (?=.*{{info}}) push: - - info_line + - info_line_meta - main_pop_at_eol - - match: ^(?=.*{{debug}}) + - match: (?=.*{{debug}}) push: - - debug_line + - debug_line_meta - main_pop_at_eol log_levels: - match: '{{error}}' @@ -63,16 +63,16 @@ contexts: scope: markup.info.log - match: '{{debug}}' scope: markup.info.log - error_line: + error_line_meta: - meta_scope: meta.annotation.error-line.log - include: immediately_pop - warning_line: + warning_line_meta: - meta_scope: meta.annotation.warning-line.log - include: immediately_pop - info_line: + info_line_meta: - meta_scope: meta.annotation.info-line.log - include: immediately_pop - debug_line: + debug_line_meta: - meta_scope: meta.annotation.debug-line.log - include: immediately_pop immediately_pop: diff --git a/assets/syntaxes/02_Extra/syslog.sublime-syntax b/assets/syntaxes/02_Extra/syslog.sublime-syntax index 1efad346..b1e10cca 100644 --- a/assets/syntaxes/02_Extra/syslog.sublime-syntax +++ b/assets/syntaxes/02_Extra/syslog.sublime-syntax @@ -31,22 +31,24 @@ contexts: structured-data: - match: '\[' scope: punctuation.section.mapping.begin.syslog - push: - - match: \] - scope: punctuation.section.mapping.end.syslog - pop: true - - match: \w+ - scope: variable.parameter.syslog - - match: = - scope: keyword.operator.assignment.syslog - push: - - match: '[^\s\]]+' - scope: constant.other.syslog - pop: true - - match: (?=\]) - pop: true + push: structured-data-contents - match: (?=\S) set: text + structured-data-contents: + - match: \] + scope: punctuation.section.mapping.end.syslog + pop: true + - match: \w+ + scope: variable.parameter.syslog + - match: = + scope: keyword.operator.assignment.syslog + push: structured-data-assignment + structured-data-assignment: + - match: '[^\s\]]+' + scope: constant.other.syslog + pop: true + - match: (?=\]) + pop: true text: - match: $ pop: true diff --git a/tests/syntax-tests/source/Syslog/example.syslog b/tests/syntax-tests/source/Syslog/example.syslog index 9dc82e7c..5b7e575b 100644 --- a/tests/syntax-tests/source/Syslog/example.syslog +++ b/tests/syntax-tests/source/Syslog/example.syslog @@ -14,3 +14,4 @@ Aug 11 13:36:34 192.168.220.5 nginx: 2021/08/11 13:36:34 [debug] 2031#2031: epol Aug 11 21:31:08 ::1 nginx: 2021/08/11 21:31:08 [debug] 760831#760831: epoll add event: fd:6 op:1 ev:10000001 Aug 11 21:40:31 hostname-here scop hello Aug 16 21:38:21 hostname-here systemd[1]: Finished Cleanup of Temporary Directories. +2025-02-08 20:52:11.039 - setfont: ERROR kdfontop.c:183 put_font_kdfontop: Unable to load such font with such kernel version From c0898dedb123b7c2a3ecea5c95c02b84dca26ba9 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 8 Feb 2025 21:14:56 +0200 Subject: [PATCH 2/3] fix meta scope ordering to come before constant.numeric scope for times --- assets/syntaxes/02_Extra/syslog.sublime-syntax | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/syntaxes/02_Extra/syslog.sublime-syntax b/assets/syntaxes/02_Extra/syslog.sublime-syntax index b1e10cca..01ed58db 100644 --- a/assets/syntaxes/02_Extra/syslog.sublime-syntax +++ b/assets/syntaxes/02_Extra/syslog.sublime-syntax @@ -8,10 +8,10 @@ scope: text.log.syslog contexts: main: - match: ^(\w+\s+\d+)\s+(\d{2}:\d{2}:\d{2}) - scope: meta.datetime.syslog constant.numeric.syslog + scope: meta.datetime.syslog captures: - 1: meta.date.syslog - 2: meta.time.syslog + 1: meta.date.syslog constant.numeric.syslog + 2: meta.time.syslog constant.numeric.syslog push: loghost - match: ^ push: text From 27ba45ded7c24266c1d1b2547c2539516c5604c9 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 9 Feb 2025 12:56:53 +0200 Subject: [PATCH 3/3] patch Monokai Extended theme for better Syslog error highlighting --- CHANGELOG.md | 1 + assets/patches/Monokai-Extended.tmTheme.patch | 19 +++++++++-- doc/assets.md | 2 +- .../syntax-tests/highlighted/Log/example.log | 2 +- .../highlighted/Syslog/example.syslog | 33 ++++++++++--------- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61103651..71c8b749 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Add syntax mapping for `paru` configuration files #3182 (@cyqsimon) - Add support for [Idris 2 programming language](https://www.idris-lang.org/) #3150 (@buzden) - Add syntax mapping for `nix`'s '`flake.lock` lockfiles #3196 (@odilf) +- Improve (Sys)log error highlighting, see #3205 (@keith-hall) ## Themes diff --git a/assets/patches/Monokai-Extended.tmTheme.patch b/assets/patches/Monokai-Extended.tmTheme.patch index 106b584d..ece5d49c 100644 --- a/assets/patches/Monokai-Extended.tmTheme.patch +++ b/assets/patches/Monokai-Extended.tmTheme.patch @@ -21,11 +21,26 @@ index 9c2aa3e..180cbbf 100644 Invalid scope - invalid -+ invalid, markup.error ++ invalid, meta.annotation.error-line settings background -@@ -1042,7 +1042,7 @@ +@@ -1038,11 +1038,22 @@ + #f8f8f0 + + ++ ++ name ++ Error ++ scope ++ markup.error ++ settings ++ ++ foreground ++ #dd2020 ++ ++ + name Invalid deprecated scope diff --git a/doc/assets.md b/doc/assets.md index a06a1e67..032a7883 100644 --- a/doc/assets.md +++ b/doc/assets.md @@ -26,7 +26,7 @@ in the `.sublime-syntax` format. 4. Re-compile `bat`. At compilation time, the `syntaxes.bin` file will be stored inside the `bat` binary. -5. Use `bat --list-languages` to check if the new languages are available. +5. Use `bat --list-languages` to check if the new languages are available. You may want to do something like `export PATH="`pwd`/target/debug:$PATH"` to ensure the locally compiled version is the one being used. 6. Add a syntax test for the new language. See [below](#Syntax-tests) for details. diff --git a/tests/syntax-tests/highlighted/Log/example.log b/tests/syntax-tests/highlighted/Log/example.log index f0e9754a..57e0e9a3 100644 --- a/tests/syntax-tests/highlighted/Log/example.log +++ b/tests/syntax-tests/highlighted/Log/example.log @@ -1,3 +1,3 @@ 2021-03-06 23:22:21.392 https://[2001:db8:4006:812::200e]:8080/path/the%20page.html 2021-03-06 23:22:21 https://example.com:8080/path/the%20page(with_parens).html -2022-03-16T17:41:02.519 helix_term::application [WARN] unhandled window/showMessage: ShowMessageParams { typ: Error, message: "rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/zeta/dev/raytracer/Cargo.toml, cargo 1.61.0-nightly (65c8266 2022-03-09): Failed to run `\"cargo\" \"metadata\" \"--format-version\" \"1\" \"--manifest-path\" \"/home/zeta/dev/raytracer/Cargo.toml\" \"--filter-platform\" \"wasm32-unknown-unknown\"`: `cargo metadata` exited with an error: Updating crates.io index\nerror: failed to select a version for `parking_lot`.\n ... required by package `raytracer v0.1.0 (/home/zeta/dev/raytracer)`\nversions that meet the requirements `^0.12.0` are: 0.12.0\n\nthe package `raytracer` depends on `parking_lot`, with features: `wasm-bindgen` but `parking_lot` does not have these features.\n\n\nfailed to select a version for `parking_lot` which could resolve this conflict\n" } +2022-03-16T17:41:02.519 helix_term::application [WARN] unhandled window/showMessage: ShowMessageParams { typ: Error, message: "rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/zeta/dev/raytracer/Cargo.toml, cargo 1.61.0-nightly (65c8266 2022-03-09): Failed to run `\"cargo\" \"metadata\" \"--format-version\" \"1\" \"--manifest-path\" \"/home/zeta/dev/raytracer/Cargo.toml\" \"--filter-platform\" \"wasm32-unknown-unknown\"`: `cargo metadata` exited with an error: Updating crates.io index\nerror: failed to select a version for `parking_lot`.\n ... required by package `raytracer v0.1.0 (/home/zeta/dev/raytracer)`\nversions that meet the requirements `^0.12.0` are: 0.12.0\n\nthe package `raytracer` depends on `parking_lot`, with features: `wasm-bindgen` but `parking_lot` does not have these features.\n\n\nfailed to select a version for `parking_lot` which could resolve this conflict\n" } diff --git a/tests/syntax-tests/highlighted/Syslog/example.syslog b/tests/syntax-tests/highlighted/Syslog/example.syslog index 0c200c33..78c45a12 100644 --- a/tests/syntax-tests/highlighted/Syslog/example.syslog +++ b/tests/syntax-tests/highlighted/Syslog/example.syslog @@ -1,16 +1,17 @@ -Apr 4 00:00:01 hostname-here systemd[1]: logrotate.service: Succeeded. -Apr 4 00:00:01 hostname-here systemd[1]: Finished Rotate log files. -Apr 4 00:00:01 hostname-here colord[920]: failed to get session [pid 137485]: No data available -Apr 4 00:00:21 hostname-here kernel: [55604.908232] audit: type=1400 audit(1617483621.094:28): apparmor="DENIED" operation="capable" profile="/usr/sbin/cups-browsed" pid=59311 comm="cups-browsed" capability=23 capname="sys_nice" -Apr 4 00:01:38 hostname-here systemd-resolved[721]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP. -Apr 4 00:04:46 hostname-here ntpd[952]: Soliciting pool server 255.76.59.37 -Apr 4 00:05:21 hostname-here ntpd[952]: ::1 local addr 0:0:0:0:0:0:0:1 ->  -Apr 4 00:06:29 hostname-here ntpd[952]: receive: Unexpected origin timestamp 0xe414a8d1.82e825f5 does not match aorg 0xe414a8d5.82c50d8c from server@127.0.0.1 xmt 0xe414a8d1.e671d7c4 -Apr 4 09:30:01 hostname-here CRON[89278]: (root) CMD ([ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi) -Apr 4 16:32:07 hostname-here NetworkManager[740]:  [1617629527.1101] manager: NetworkManager state is now CONNECTED_GLOBAL -Apr 4 22:00:45 hostname-here dbus-daemon[1094]: [session uid=1000 pid=1094] Successfully activated service 'io.github.celluloid_player.Celluloid' -Aug 11 13:29:06 hostname-here insomnia_insomnia.desktop[142666]: 13:29:06.316 › [updater] Updater not running platform=linux dev=false -Aug 11 13:36:34 192.168.220.5 nginx: 2021/08/11 13:36:34 [debug] 2031#2031: epoll add event: fd:6 op:1 ev:00002001 -Aug 11 21:31:08 ::1 nginx: 2021/08/11 21:31:08 [debug] 760831#760831: epoll add event: fd:6 op:1 ev:10000001 -Aug 11 21:40:31 hostname-here scop hello -Aug 16 21:38:21 hostname-here systemd[1]: Finished Cleanup of Temporary Directories. +Apr 4 00:00:01 hostname-here systemd[1]: logrotate.service: Succeeded. +Apr 4 00:00:01 hostname-here systemd[1]: Finished Rotate log files. +Apr 4 00:00:01 hostname-here colord[920]: failed to get session [pid 137485]: No data available +Apr 4 00:00:21 hostname-here kernel: [55604.908232] audit: type=1400 audit(1617483621.094:28): apparmor="DENIED" operation="capable" profile="/usr/sbin/cups-browsed" pid=59311 comm="cups-browsed" capability=23 capname="sys_nice" +Apr 4 00:01:38 hostname-here systemd-resolved[721]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP. +Apr 4 00:04:46 hostname-here ntpd[952]: Soliciting pool server 255.76.59.37 +Apr 4 00:05:21 hostname-here ntpd[952]: ::1 local addr 0:0:0:0:0:0:0:1 ->  +Apr 4 00:06:29 hostname-here ntpd[952]: receive: Unexpected origin timestamp 0xe414a8d1.82e825f5 does not match aorg 0xe414a8d5.82c50d8c from server@127.0.0.1 xmt 0xe414a8d1.e671d7c4 +Apr 4 09:30:01 hostname-here CRON[89278]: (root) CMD ([ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi) +Apr 4 16:32:07 hostname-here NetworkManager[740]:  [1617629527.1101] manager: NetworkManager state is now CONNECTED_GLOBAL +Apr 4 22:00:45 hostname-here dbus-daemon[1094]: [session uid=1000 pid=1094] Successfully activated service 'io.github.celluloid_player.Celluloid' +Aug 11 13:29:06 hostname-here insomnia_insomnia.desktop[142666]: 13:29:06.316 › [updater] Updater not running platform=linux dev=false +Aug 11 13:36:34 192.168.220.5 nginx: 2021/08/11 13:36:34 [debug] 2031#2031: epoll add event: fd:6 op:1 ev:00002001 +Aug 11 21:31:08 ::1 nginx: 2021/08/11 21:31:08 [debug] 760831#760831: epoll add event: fd:6 op:1 ev:10000001 +Aug 11 21:40:31 hostname-here scop hello +Aug 16 21:38:21 hostname-here systemd[1]: Finished Cleanup of Temporary Directories. +2025-02-08 20:52:11.039 - setfont: ERROR kdfontop.c:183 put_font_kdfontop: Unable to load such font with such kernel version