Skip to content

Commit

Permalink
[WORKAROUND]Fix tons of unrelated completion candidates shown when a …
Browse files Browse the repository at this point in the history
…candidate is fulfilled.

See emacs-lsp/lsp-python-ms#79
  • Loading branch information
seagle0128 committed Jan 15, 2020
1 parent d94b424 commit 0d8a2d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lisp/init-ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 35 additions & 1 deletion lisp/init-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -150,6 +183,7 @@
("M-<f5>" . 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)))
Expand Down

0 comments on commit 0d8a2d8

Please sign in to comment.