diff --git a/lisp/init-ivy.el b/lisp/init-ivy.el index b6b3720a9..1c993a1e7 100644 --- a/lisp/init-ivy.el +++ b/lisp/init-ivy.el @@ -394,7 +394,8 @@ This is for use in `ivy-re-builders-alist'." (defun ivy--regex-pinyin (str) "The regex builder wrapper to support pinyin." (or (pinyin-to-utf8 str) - (ivy-prescient-non-fuzzy str) + (and (fboundp 'ivy-prescient-non-fuzzy) + (ivy-prescient-non-fuzzy str)) (ivy--regex-plus str))) (defun my-pinyinlib-build-regexp-string (str) diff --git a/lisp/init-lsp.el b/lisp/init-lsp.el index 720e5e8f9..701823ea8 100644 --- a/lisp/init-lsp.el +++ b/lisp/init-lsp.el @@ -133,7 +133,40 @@ ;; Completion (use-package company-lsp - :init (setq company-lsp-cache-candidates 'auto)) + :init (setq company-lsp-cache-candidates 'auto) + :config + ;; WORKAROUND:Fix tons of unrelated completion candidates shown + ;; when a candidate is fulfilled + ;; @see https://github.com/emacs-lsp/lsp-python-ms/issues/79 + (add-to-list 'company-lsp-filter-candidates '(mspyls)) + + (defun my-company-lsp--on-completion (response prefix) + "Handle completion RESPONSE. + +PREFIX is a string of the prefix when the completion is requested. + +Return a list of strings as the completion candidates." + (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 (eq company-lsp-cache-candidates 'auto) + (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) + ;; Only cache candidates on auto mode. If it's t company caches the + ;; candidates for us. + (company-lsp--cache-put prefix (company-lsp--cache-item-new candidates incomplete))) + (if should-filter + (company-lsp--filter-candidates candidates prefix) + candidates))) + (advice-add #'company-lsp--on-completion :override #'my-company-lsp--on-completion)) ;; Ivy integration (use-package lsp-ivy @@ -150,6 +183,7 @@ ("M-" . dap-hydra)) :hook ((after-init . dap-mode) (dap-mode . dap-ui-mode) + (dap-session-created . (lambda (_args) (dap-hydra))) (dap-stopped . (lambda (_args) (dap-hydra))) (python-mode . (lambda () (require 'dap-python)))