From: João Távora Date: Sat, 6 Jul 2024 09:17:42 +0000 (+0100) Subject: Eglot: support deprecated MarkedString (bug#71353) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=45e0f547338527b553b4af95f4c8ebe9e5e0514a;p=emacs.git Eglot: support deprecated MarkedString (bug#71353) * lisp/progmodes/eglot.el: Make a markdown code block if MarkedString passed. (cherry picked from commit 74b82e6802e65ff0ec1ac3bbc680b5db9a7f1c89) --- 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)