From 33d61f832580f1afdb6181aedce1c16e90a0a93c Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Tue, 29 Aug 2023 13:35:30 +0200 Subject: [PATCH] Font lock JSON messages in the lsp-log buffer --- lsp-mode.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lsp-mode.el b/lsp-mode.el index 01da57662b..072a30a918 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -3142,6 +3142,22 @@ TYPE can either be `incoming' or `outgoing'" :type type :body body)) +(defun lsp--log-font-lock-json (body) + "Font lock JSON BODY." + (with-temp-buffer + (insert body) + ;; We set the temp buffer file-name extension to .json and call `set-auto-mode' + ;; so the users configured json mode is used which could be + ;; `json-mode', `json-ts-mode', `jsonian-mode', etc. + (let ((buffer-file-name "lsp-log.json")) + (delay-mode-hooks + (set-auto-mode) + (if (fboundp 'font-lock-ensure) + (font-lock-ensure) + (with-no-warnings + (font-lock-fontify-buffer))))) + (buffer-string))) + (defun lsp--log-entry-pp (entry) (cl-assert (lsp--log-entry-p entry)) (pcase-let (((cl-struct lsp--log-entry timestamp method id type process-time @@ -3169,7 +3185,7 @@ TYPE can either be `incoming' or `outgoing'" (if (memq type '(incoming-resp ougoing-resp)) "Result: " "Params: ") - (json-encode body) + (lsp--log-font-lock-json (json-encode body)) "\n\n\n")) (setq str (propertize str 'mouse-face 'highlight 'read-only t)) (insert str)))