Remove company-lsp fallback

Issues with ts-ls and gopls have been reportedly resolved upstream, so
we are fully committing to company-capf as LSP's chosen backend.
This commit is contained in:
Henrik Lissner 2020-05-02 22:38:36 -04:00
parent 62b626f7b7
commit b3c957065c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 8 additions and 72 deletions

View file

@ -1,21 +1,5 @@
;;; tools/lsp/config.el -*- lexical-binding: t; -*- ;;; tools/lsp/config.el -*- lexical-binding: t; -*-
(defvar +lsp-company-backend 'company-lsp
"What backend to use for lsp-driven autocompletion.
This can be overridden by `+lsp-capf-blacklist'.
While `company-capf' does not require the `company-lsp' package and should offer
better performance, it has been integrated into lsp only recently and as of
02/25/2020 is known to cause issues with some language servers. If you wish to
use `company-capf' in general but fall back to `company-lsp' for specific
language servers, set `+lsp-company-backend' to `company-capf' and add the
excluded servers' identifiers to `+lsp-capf-blacklist'.")
(defvar +lsp-capf-blacklist '(ts-ls gopls)
"Language servers listed here will always use the `company-lsp' backend,
irrespective of what `+lsp-company-backend' is set to.")
(defvar +lsp-defer-shutdown 3 (defvar +lsp-defer-shutdown 3
"If non-nil, defer shutdown of LSP servers for this many seconds after last "If non-nil, defer shutdown of LSP servers for this many seconds after last
workspace buffer is closed. workspace buffer is closed.
@ -57,7 +41,9 @@ working on that project after closing the last buffer.")
lsp-enable-semantic-highlighting nil lsp-enable-semantic-highlighting nil
;; Don't modify our code without our permission ;; Don't modify our code without our permission
lsp-enable-indentation nil lsp-enable-indentation nil
lsp-enable-on-type-formatting nil) lsp-enable-on-type-formatting nil
;; capf is the preferred completion mechanism for lsp-mode now
lsp-prefer-capf t)
:config :config
(set-popup-rule! "^\\*lsp-help" :size 0.35 :quit t :select t) (set-popup-rule! "^\\*lsp-help" :size 0.35 :quit t :select t)
@ -117,26 +103,11 @@ This also logs the resolved project root, if found, so we know where we are."
(defun +lsp-init-company-h () (defun +lsp-init-company-h ()
(if (not (bound-and-true-p company-mode)) (if (not (bound-and-true-p company-mode))
(add-hook 'company-mode-hook #'+lsp-init-company-h t t) (add-hook 'company-mode-hook #'+lsp-init-company-h t t)
(let ((preferred-backend +lsp-company-backend)) ;; Ensure `company-capf' is at the front of `company-backends'
(lsp-foreach-workspace
(when (memq (lsp--client-server-id (lsp--workspace-client lsp--cur-workspace))
+lsp-capf-blacklist)
(setq preferred-backend 'company-lsp)))
(if (eq 'company-capf preferred-backend)
;; use capf backend
(progn
(setq-local lsp-enable-completion-at-point t)
(setq-local lsp-prefer-capf t)
(setq-local company-backends (setq-local company-backends
(cons 'company-capf (remq 'company-capf company-backends)))) (cons 'company-capf
;; use company-lsp backend (may need to be loaded first) (remq 'company-capf company-backends)))
(require 'company-lsp) (remove-hook 'company-mode-hook #'+lsp-init-company-h t)))
(setq-local lsp-enable-completion-at-point nil)
(setq-local lsp-prefer-capf nil)
(setq-local company-backends
(cons 'company-lsp (remq 'company-capf company-backends)))
(setq-default company-lsp-cache-candidates 'auto))
(remove-hook 'company-mode-hook #'+lsp-init-company-h t))))
(defun +lsp-init-flycheck-or-flymake-h () (defun +lsp-init-flycheck-or-flymake-h ()
"Set up flycheck-mode or flymake-mode, depending on `lsp-diagnostic-package'." "Set up flycheck-mode or flymake-mode, depending on `lsp-diagnostic-package'."
(pcase lsp-diagnostic-package (pcase lsp-diagnostic-package
@ -212,39 +183,6 @@ auto-killed (which is a potentially expensive process)."
:references 'lsp-ui-peek-find-references))) :references 'lsp-ui-peek-find-references)))
(use-package! company-lsp
:defer t
:config
(setq company-lsp-cache-candidates 'auto)
;; HACK Fix tigersoldier/company-lsp#128 causing company-lsp results to
;; display candidates that are unrelated to the prefix. Source:
;; emacs-lsp/lsp-python-ms#79
(add-to-list 'company-lsp-filter-candidates '(mspyls . t))
(defadvice! +company---fix-lsp-caching-on-competion-a (response prefix)
:override #'company-lsp--on-completion
(let* ((incomplete (and (hash-table-p response) (gethash "isIncomplete" response)))
(items (cond ((hash-table-p response) (gethash "items" response))
((sequencep response) response)))
(candidates (mapcar (lambda (item)
(company-lsp--make-candidate item prefix))
(lsp--sort-completions items)))
(server-id (lsp--client-server-id (lsp--workspace-client lsp--cur-workspace)))
(should-filter (or
;; CHANGE BEGIN
(eq company-lsp-cache-candidates t)
;; CHANGE END
(and (null company-lsp-cache-candidates)
(company-lsp--get-config company-lsp-filter-candidates server-id)))))
(when (null company-lsp--completion-cache)
(add-hook 'company-completion-cancelled-hook #'company-lsp--cleanup-cache nil t)
(add-hook 'company-completion-finished-hook #'company-lsp--cleanup-cache nil t))
(when (eq company-lsp-cache-candidates 'auto)
(company-lsp--cache-put prefix (company-lsp--cache-item-new candidates incomplete)))
(if should-filter
(company-lsp--filter-candidates candidates prefix)
candidates))))
(use-package! helm-lsp (use-package! helm-lsp
:when (featurep! :completion helm) :when (featurep! :completion helm)
:commands helm-lsp-workspace-symbol helm-lsp-global-workspace-symbol) :commands helm-lsp-workspace-symbol helm-lsp-global-workspace-symbol)

View file

@ -3,8 +3,6 @@
(package! lsp-mode :pin "d0096ccf22e0e70eaad6cc99e5ae4bd9fc81f75f") (package! lsp-mode :pin "d0096ccf22e0e70eaad6cc99e5ae4bd9fc81f75f")
(package! lsp-ui :pin "242dfe859c3497c456eaacfd84942e12419529fe") (package! lsp-ui :pin "242dfe859c3497c456eaacfd84942e12419529fe")
(when (featurep! :completion company)
(package! company-lsp :pin "f921ffa0cdc542c21dc3dd85f2c93df4288e83bd"))
(when (featurep! :completion ivy) (when (featurep! :completion ivy)
(package! lsp-ivy :pin "81e81ced99829358674c5a6bbe2c3e15cecd4ed8")) (package! lsp-ivy :pin "81e81ced99829358674c5a6bbe2c3e15cecd4ed8"))
(when (featurep! :completion helm) (when (featurep! :completion helm)