company-fuzzy
company-fuzzy copied to clipboard
Adding yasnippet as a backend, doesn't complete when calling company-complete-selection
I have something like this bound to RET on the company-active-map.
(defun j-company-expand-yasnippet-or-return ()
"Expand yas template or call RET normally.
If `yasnippet' expansion in progress, always complete selection."
(interactive)
(cond
;; `yasnippet' expansion in progress.
((yas-current-field)
(call-interactively #'company-complete-selection))
;; Check the type of the candidate.
((and company-active-map
company-selection-changed
(car company-candidates) ;; Making sure there are candidates.
(let ((candidate (nth company-selection
company-candidates)))
(or
;; This might work for `eglot'.
;; (get-text-property 0 :label candidate)
;; `company-lsp'
(get-text-property 0 'lsp-completion-item candidate)
;; `company-sourcekit'
(get-text-property 0 'sourcetext candidate)
;; `yasnippet'
(get-text-property 0 'yas-template candidate))))
(call-interactively #'company-complete-selection))
(:default
(when company-selection-changed
(company-complete-selection))
(let ((company-active-map))
(call-interactively (key-binding (kbd "RET")))))))
Without company-fuzzy, if I'm on a snippet expansion in the company-mode popup/auto complete menu, pressing RET calls company-complete-selection which then expands the snippet.
For example, in a C file.
if| popup shows with if yasnippet selection -> press ENTER
Result:
if (/cursor/) { }
When I pair the same setup with company-fuzzy.
Result:
if/cursor/
If I then, press TAB after that, snippet expands normally.
Hmmm... Interesting, without any configuration with company-fuzzy and company, does it exactly do what you want? Because it does exactly the same, you describe as default? :/
Just to clarify, you want to expand snippet when the menu is still popup?
Yeah, I didn't emacs -Q but I stripped most of my setup away and it still works as expected.
I'd actually ask what the expected behavior of company-yasnippet would be if it didn't expand upon completion.