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:
@@ -7,6 +7,7 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'siren-company)
|
||||
(require 'siren-yasnippet)
|
||||
|
||||
(use-package cape
|
||||
:after company
|
||||
@@ -14,9 +15,6 @@
|
||||
(lsp-completion-mode . siren-cape-capf-lsp-mode-setup)
|
||||
|
||||
:preface
|
||||
(defalias 'siren-yasnippet-capf
|
||||
(cape-company-to-capf 'company-yasnippet))
|
||||
|
||||
(defun siren-cape-capf-lsp-mode-setup ()
|
||||
(siren-cape-capf-add-hooks t))
|
||||
|
||||
@@ -25,11 +23,13 @@
|
||||
;; Use `siren-prepend' function instead of `add-hook' to ensure our custom
|
||||
;; completion functions are listed before `lsp-completion-at-point'.
|
||||
(siren-prepend completion-at-point-functions 'cape-file)
|
||||
(siren-prepend completion-at-point-functions 'siren-yasnippet-capf))
|
||||
(siren-prepend completion-at-point-functions 'yasnippet-capf))
|
||||
;; (siren-prepend completion-at-point-functions
|
||||
;; (cape-capf-super #'lsp-completion-at-point #'yasnippet-capf))
|
||||
|
||||
(defun siren-cape-capf-remove-hooks (&optional local)
|
||||
(remove-hook 'completion-at-point-functions 'siren-yasnippet-capf local)
|
||||
(remove-hook 'completion-at-point-functions 'cape-file local))
|
||||
(remove-hook 'completion-at-point-functions 'cape-file local)
|
||||
(remove-hook 'completion-at-point-functions 'yasnippet-capf local))
|
||||
|
||||
:init
|
||||
(siren-cape-capf-add-hooks))
|
||||
|
||||
@@ -41,56 +41,5 @@
|
||||
:if window-system
|
||||
:hook (company-mode . company-box-mode))
|
||||
|
||||
(use-package company-yasnippet
|
||||
:straight company
|
||||
|
||||
:preface
|
||||
(defgroup siren-company-yasnippet nil
|
||||
"Siren specific tweaks to company-yasnippet."
|
||||
:group 'company)
|
||||
|
||||
(defcustom siren-company-yasnippet-exact-match-only nil
|
||||
"Only match completion when it is a exact match for a snippet key.
|
||||
|
||||
This allows company-yasnippet to be used before company-capf / lsp, allowing
|
||||
snippets to be easily used when exactly typing out a snippet key."
|
||||
:type 'boolean
|
||||
:group 'siren-company-yasnippet)
|
||||
|
||||
:custom
|
||||
(siren-company-yasnippet-exact-match-only t)
|
||||
|
||||
:config
|
||||
;; Dirty hack to optionally enable company-yasnippet to only match exact
|
||||
;; snippet keys.
|
||||
(defun company-yasnippet--completions-for-prefix (prefix key-prefix tables)
|
||||
(cl-mapcan
|
||||
(lambda (table)
|
||||
(let ((keyhash (yas--table-hash table))
|
||||
(requirement (yas--require-template-specific-condition-p))
|
||||
res)
|
||||
(when keyhash
|
||||
(maphash
|
||||
(lambda (key value)
|
||||
(when (and (stringp key)
|
||||
(if siren-company-yasnippet-exact-match-only
|
||||
(string-equal key-prefix key)
|
||||
(string-prefix-p key-prefix key)))
|
||||
(maphash
|
||||
(lambda (name template)
|
||||
(when (yas--template-can-expand-p
|
||||
(yas--template-condition template) requirement)
|
||||
(push
|
||||
(propertize key
|
||||
'yas-annotation name
|
||||
'yas-template template
|
||||
'yas-prefix-offset (- (length key-prefix)
|
||||
(length prefix)))
|
||||
res)))
|
||||
value)))
|
||||
keyhash))
|
||||
res))
|
||||
tables)))
|
||||
|
||||
(provide 'siren-company)
|
||||
;;; siren-company.el ends here
|
||||
|
||||
Reference in New Issue
Block a user