From b3c957065c036ad677b21aafcea5f726c303d653 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 2 May 2020 22:38:36 -0400 Subject: [PATCH] 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. --- modules/tools/lsp/config.el | 78 ++++------------------------------- modules/tools/lsp/packages.el | 2 - 2 files changed, 8 insertions(+), 72 deletions(-) diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index 8464cb76a..a59762b12 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -1,21 +1,5 @@ ;;; 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 "If non-nil, defer shutdown of LSP servers for this many seconds after last workspace buffer is closed. @@ -57,7 +41,9 @@ working on that project after closing the last buffer.") lsp-enable-semantic-highlighting nil ;; Don't modify our code without our permission 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 (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 () (if (not (bound-and-true-p company-mode)) (add-hook 'company-mode-hook #'+lsp-init-company-h t t) - (let ((preferred-backend +lsp-company-backend)) - (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 - (cons 'company-capf (remq 'company-capf company-backends)))) - ;; use company-lsp backend (may need to be loaded first) - (require 'company-lsp) - (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)))) + ;; Ensure `company-capf' is at the front of `company-backends' + (setq-local company-backends + (cons 'company-capf + (remq 'company-capf company-backends))) + (remove-hook 'company-mode-hook #'+lsp-init-company-h t))) (defun +lsp-init-flycheck-or-flymake-h () "Set up flycheck-mode or flymake-mode, depending on `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))) -(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 :when (featurep! :completion helm) :commands helm-lsp-workspace-symbol helm-lsp-global-workspace-symbol) diff --git a/modules/tools/lsp/packages.el b/modules/tools/lsp/packages.el index 79cccbf15..ceb6102fd 100644 --- a/modules/tools/lsp/packages.el +++ b/modules/tools/lsp/packages.el @@ -3,8 +3,6 @@ (package! lsp-mode :pin "d0096ccf22e0e70eaad6cc99e5ae4bd9fc81f75f") (package! lsp-ui :pin "242dfe859c3497c456eaacfd84942e12419529fe") -(when (featurep! :completion company) - (package! company-lsp :pin "f921ffa0cdc542c21dc3dd85f2c93df4288e83bd")) (when (featurep! :completion ivy) (package! lsp-ivy :pin "81e81ced99829358674c5a6bbe2c3e15cecd4ed8")) (when (featurep! :completion helm)