mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
fix(completion/yasnippet): fix completion issues caused by yasnippet
This somewhat works around some changes to cape, which I was abusing to effectively get a capf yasnippet function that would only return results on exact matches. This allows normal lsp completion to work just fine, except for exact matches against specific snippets. Now we use the yasnippet-capf package instead, no longer needing the company-yasnippet package, and hacking it to also only give a single result back, with some caveats.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'cl-lib)
|
||||
|
||||
(use-package yasnippet
|
||||
:diminish yas-minor-mode
|
||||
:hook (emacs-startup . yas-reload-all)
|
||||
@@ -22,5 +24,45 @@
|
||||
(when (not (file-exists-p skip-file))
|
||||
(make-empty-file skip-file t))))
|
||||
|
||||
(use-package yasnippet-capf
|
||||
:preface
|
||||
(defgroup siren-yasnippet-capf nil
|
||||
"Siren specific tweaks to yasnippet-capf."
|
||||
:group 'yasnippet-capf)
|
||||
|
||||
(defcustom siren-yasnippet-capf-exact-match t
|
||||
"Only return exact matches.
|
||||
|
||||
When non-nil, only exact matches will be returned by `yasnippet-capf'.
|
||||
When nil, all matches will be returned.
|
||||
|
||||
Annoyingly, when enabled this seems to hide all completion results for
|
||||
yasnippet, cause the capf function is run twice, once with the given
|
||||
prefix, and once without any at all.
|
||||
|
||||
It seems like the first call is used to determine if the next capf function
|
||||
should be used or not, and the second call is what company-mode uses to render
|
||||
completions.
|
||||
|
||||
For my use-case, this is fine, as I only want `yasnippet-capf' triggered
|
||||
for exact matches, and for everything else move on to the lsp-mode's
|
||||
`lsp-completion-at-point' function."
|
||||
:type 'boolean
|
||||
:group 'siren-yasnippet-capf)
|
||||
|
||||
(defun siren-yasnippet-capf--advice-exact-match-only (orig-fun &rest args)
|
||||
"Advice to filter out non-exact matches."
|
||||
(let ((candidates (apply orig-fun args))
|
||||
(prefix (nth 0 args)))
|
||||
(if siren-yasnippet-capf-exact-match
|
||||
(cl-remove-if-not (lambda (candidate)
|
||||
(string= prefix (substring-no-properties candidate)))
|
||||
candidates)
|
||||
candidates)))
|
||||
|
||||
:config
|
||||
(advice-add 'yasnippet-capf-candidates
|
||||
:around #'siren-yasnippet-capf--advice-exact-match-only))
|
||||
|
||||
(provide 'siren-yasnippet)
|
||||
;;; siren-yasnippet.el ends here
|
||||
|
||||
Reference in New Issue
Block a user