Eglot: unbreak for treesit-less builds

* lisp/progmodes/eglot.el
(eglot--builtin-mdown-p): New helper.
(eglot--accepted-formats)
(eglot--format-markup): Use it.
This commit is contained in:
João Távora 2026-05-18 20:33:44 +01:00
parent 10e91e096d
commit 389874c533

View file

@ -726,11 +726,15 @@ This can be useful when using docker to run a language server.")
(executable-find command))) (executable-find command)))
(declare-function treesit-grammar-location "treesit.c") (declare-function treesit-grammar-location "treesit.c")
(defun eglot--builtin-mdown-p ()
(and (fboundp 'markdown-ts-view-mode)
(fboundp 'treesit-grammar-location)
(treesit-grammar-location 'markdown)))
(defun eglot--accepted-formats () (defun eglot--accepted-formats ()
(if (and (not eglot-prefer-plaintext) (if (and (not eglot-prefer-plaintext)
(or (fboundp 'gfm-view-mode) (or (fboundp 'gfm-view-mode) (eglot--builtin-mdown-p)))
(and (fboundp 'markdown-ts-view-mode)
(treesit-grammar-location 'markdown))))
["markdown" "plaintext"] ["markdown" "plaintext"]
["plaintext"])) ["plaintext"]))
@ -2237,9 +2241,7 @@ Doubles as an indicator of snippet support."
(cl-defun eglot--format-markup (cl-defun eglot--format-markup
(markup &optional mode (markup &optional mode
&aux string lang render extract &aux string lang render extract)
(built-in (and (fboundp 'markdown-ts-view-mode)
(treesit-grammar-location 'markdown))))
"Format MARKUP according to LSP's spec. "Format MARKUP according to LSP's spec.
MARKUP is either an LSP MarkedString or MarkupContent object. MARKUP is either an LSP MarkedString or MarkupContent object.
If MODE, force MODE to be used for fontifying MARKUP." If MODE, force MODE to be used for fontifying MARKUP."
@ -2261,7 +2263,7 @@ If MODE, force MODE to be used for fontifying MARKUP."
(calc2 (forced-mode) (calc2 (forced-mode)
(cond (cond
(forced-mode `(,forced-mode)) (forced-mode `(,forced-mode))
(built-in `(,#'markdown-ts-view-mode)) ((eglot--builtin-mdown-p) `(,#'markdown-ts-view-mode))
((fboundp 'gfm-view-mode) `(,#'gfm-view-mode ,#'gfm-extract)) ((fboundp 'gfm-view-mode) `(,#'gfm-view-mode ,#'gfm-extract))
(t `(#'text-mode)))) (t `(#'text-mode))))
(calc (s &optional (forced-mode mode) &aux (x (calc2 forced-mode))) (calc (s &optional (forced-mode mode) &aux (x (calc2 forced-mode)))