Skip to content

Commit 3c8c960

Browse files
committed
Handle lsp-mode and eglot
1 parent 42cdb97 commit 3c8c960

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

company-fuzzy.el

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@
190190
(setq-local company-backends '(company-fuzzy-all-other-backends))
191191
(setq-local company-transformers (append company-transformers '(company-fuzzy--sort-candidates)))
192192
(advice-add 'company--insert-candidate :before #'company-fuzzy--insert-candidate)
193-
(advice-add 'company-yasnippet--completions-for-prefix :around #'company-fuzzy-yasnippet--completions-for-prefix)))
193+
(advice-add 'company-yasnippet--completions-for-prefix :around #'company-fuzzy-yasnippet--completions-for-prefix))
194+
(add-hook 'lsp-managed-mode-hook #'company-fuzzy--lsp-managed-mode nil t)
195+
(add-hook 'eglot-managed-mode-hook #'company-fuzzy--lsp-managed-mode nil t))
194196

195197
(defun company-fuzzy--disable ()
196198
"Revert all other backend back to `company-backends'."
@@ -200,7 +202,9 @@
200202
(setq company-fuzzy--recorded-backends nil
201203
company-fuzzy--backends nil)
202204
(advice-remove 'company--insert-candidate #'company-fuzzy--insert-candidate)
203-
(advice-remove 'company-yasnippet--completions-for-prefix #'company-fuzzy-yasnippet--completions-for-prefix)))
205+
(advice-remove 'company-yasnippet--completions-for-prefix #'company-fuzzy-yasnippet--completions-for-prefix))
206+
(remove-hook 'lsp-managed-mode-hook #'company-fuzzy--lsp-managed-mode t)
207+
(remove-hook 'eglot-managed-mode-hook #'company-fuzzy--lsp-managed-mode t))
204208

205209
;;;###autoload
206210
(define-minor-mode company-fuzzy-mode
@@ -611,7 +615,8 @@ Insert .* between each char."
611615
(ht-clear company-fuzzy--candidates) ; Clean up
612616
(setq company-fuzzy--is-trigger-prefix-p (company-fuzzy--trigger-prefix-p))
613617
(dolist (backend company-fuzzy--backends)
614-
(if (memq backend company-fuzzy-passthrough-backends)
618+
(if (or (company-fuzzy--lsp-passthrough backend)
619+
(memq backend company-fuzzy-passthrough-backends))
615620
(company-fuzzy--candidates-from-passthrough-backend backend)
616621
(company-fuzzy--candidates-from-backend backend)))
617622
;; Since we insert the candidates before sorting event, see function
@@ -732,6 +737,23 @@ Insert .* between each char."
732737
;; (@* "Plugins" )
733738
;;
734739

740+
(defun company-fuzzy--lsp-connected-p ()
741+
"Return non-nil if lsp is connected."
742+
(or (bound-and-true-p lsp-managed-mode)
743+
(bound-and-true-p eglot--managed-mode)))
744+
745+
(defun company-fuzzy--lsp-managed-mode (&rest _)
746+
"Hook run after LSP is enabled."
747+
(when (company-fuzzy--lsp-connected-p)
748+
;; No need to check for `company-fuzzy-mode' is on or not since this
749+
;; is hook only added when `company-fuzzy-mode' is on.
750+
(setq-local company-backends '(company-fuzzy-all-other-backends))))
751+
752+
(defun company-fuzzy--lsp-passthrough (backend)
753+
"Respect `capf' BACKEND when LSP is available."
754+
(when (memq backend '(company-capf))
755+
(company-fuzzy--lsp-connected-p)))
756+
735757
(defun company-fuzzy-yasnippet--completions-for-prefix (fnc &rest args)
736758
"Wrap around `company-yasnippet--completions-for-prefix' function in order to
737759
get all possible candidates.

0 commit comments

Comments
 (0)