From 45e0f547338527b553b4af95f4c8ebe9e5e0514a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sat, 6 Jul 2024 10:17:42 +0100 Subject: [PATCH] Eglot: support deprecated MarkedString (bug#71353) * lisp/progmodes/eglot.el: Make a markdown code block if MarkedString passed. (cherry picked from commit 74b82e6802e65ff0ec1ac3bbc680b5db9a7f1c89) --- lisp/progmodes/eglot.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 599371d951c..9c51e9b578d 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1871,15 +1871,25 @@ Doubles as an indicator of snippet support." (unless (bound-and-true-p yas-minor-mode) (yas-minor-mode 1)) (apply #'yas-expand-snippet args))))) -(defun eglot--format-markup (markup) - "Format MARKUP according to LSP's spec." - (pcase-let ((`(,string ,mode) - (if (stringp markup) (list markup 'gfm-view-mode) - (list (plist-get markup :value) - (pcase (plist-get markup :kind) - ("markdown" 'gfm-view-mode) - ("plaintext" 'text-mode) - (_ major-mode)))))) + (defun eglot--format-markup (markup) + "Format MARKUP according to LSP's spec. +MARKUP is either an LSP MarkedString or MarkupContent object." + (let (string mode language) + (cond ((stringp markup) + (setq string markup + mode 'gfm-view-mode)) + ((setq language (plist-get markup :language)) + ;; Deprecated MarkedString + (setq string (concat "```" language "\n" + (plist-get markup :value) "\n```") + mode 'gfm-view-mode)) + (t + ;; MarkupContent + (setq string (plist-get markup :value) + mode (pcase (plist-get markup :kind) + ("markdown" 'gfm-view-mode) + ("plaintext" 'text-mode) + (_ major-mode))))) (with-temp-buffer (setq-local markdown-fontify-code-blocks-natively t) (insert string) -- 2.39.2