[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 6f82596b490 1/2: Fix Eglot's snippet insertion to follow the ma
From: |
João Távora |
Subject: |
emacs-29 6f82596b490 1/2: Fix Eglot's snippet insertion to follow the manual |
Date: |
Fri, 17 Mar 2023 10:16:37 -0400 (EDT) |
branch: emacs-29
commit 6f82596b49055ad17447ee6dd51c433bd2758621
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Fix Eglot's snippet insertion to follow the manual
The manual states that YASnippet must only be installed to be useful.
Before this change, it would only work if the user happened to have
manually activated it before with 'yas-global-mode' or somesuch.
This makes Eglot's Yasnippet-activating behaviour similar to its
Flymake-activating behaviour.
* lisp/progmodes/eglot.el (eglot-client-capabilities): Consult
eglot--stay-out-of.
(eglot--snippet-expansion-fn): Turn on yas-minor-mod eon demand.
(eglot-completion-at-point): Simplify.
---
lisp/progmodes/eglot.el | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 52bba717a67..68d07c7178a 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -758,7 +758,9 @@ treated as in `eglot--dbind'."
:completion (list :dynamicRegistration :json-false
:completionItem
`(:snippetSupport
- ,(if (eglot--snippet-expansion-fn)
+ ,(if (and
+ (not (eglot--stay-out-of-p
'yasnippet))
+ (eglot--snippet-expansion-fn))
t
:json-false)
:deprecatedSupport t
@@ -1626,9 +1628,11 @@ If optional MARKER, return a marker instead"
(defun eglot--snippet-expansion-fn ()
"Compute a function to expand snippets.
Doubles as an indicator of snippet support."
- (and (boundp 'yas-minor-mode)
- (symbol-value 'yas-minor-mode)
- 'yas-expand-snippet))
+ (and (fboundp 'yas-minor-mode)
+ (lambda (&rest args)
+ (with-no-warnings
+ (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."
@@ -2887,8 +2891,7 @@ for which LSP on-type-formatting should be requested."
;; it'll be adjusted. If no usable
;; insertText at all, label is best,
;; too.
- (cond ((or (and (eql insertTextFormat 2)
- (eglot--snippet-expansion-fn))
+ (cond ((or (eql insertTextFormat 2)
textEdit
(null insertText)
(string-empty-p insertText))