Skip to content

Commit

Permalink
Merge pull request #1067 from kongds/master
Browse files Browse the repository at this point in the history
Remove duplicate candidates
  • Loading branch information
manateelazycat authored Oct 8, 2024
2 parents f57c8ce + 3dea1ee commit 9e21846
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion acm/acm.el
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ Only calculate template candidate when type last character."
(cancel-timer ,timer)
(setq ,timer nil)))

(defun acm-remove-duplicate-candidates (candidates lsp-labels)
"Remove elements from CANDIDATES whose labels exist in LSP-LABELS."
(cl-remove-if (lambda (candidate)
(member (plist-get candidate :label) lsp-labels))
candidates))

(defun acm-update-candidates ()
(let* ((keyword (acm-get-input-prefix))
(char-before-keyword (save-excursion
Expand All @@ -470,6 +476,7 @@ Only calculate template candidate when type last character."
(template-candidates-min-index 2)
lsp-candidates
lsp-workspace-symbol-candidates
file-words-candidates
capf-candidates
path-candidates
yas-candidates
Expand Down Expand Up @@ -521,8 +528,17 @@ Only calculate template candidate when type last character."
(setq ctags-candidates (unless (acm-in-comment-p) (acm-backend-ctags-candidates keyword))))
;; Fetch syntax completion candidates.
(setq lsp-candidates (unless (acm-in-comment-p) (acm-backend-lsp-candidates keyword)))
(setq file-words-candidates (acm-backend-search-file-words-candidates keyword))
(when acm-enable-lsp-workspace-symbol
(setq lsp-workspace-symbol-candidates (unless (acm-in-comment-p) (acm-backend-lsp-workspace-symbol-candidates keyword))))

(let ((lsp-labels (mapcar (lambda (candidate) (plist-get candidate :label)) lsp-candidates)))
;; Remove duplicates from both `lsp-workspace-symbol-candidates` and `file-words-candidates`
(setq lsp-workspace-symbol-candidates (acm-remove-duplicate-candidates lsp-workspace-symbol-candidates lsp-labels))
(setq file-words-candidates (acm-remove-duplicate-candidates file-words-candidates lsp-labels)))



(setq mode-candidates
(apply #'append (mapcar (lambda (mode-candidate-name)
(pcase mode-candidate-name
Expand All @@ -534,7 +550,7 @@ Only calculate template candidate when type last character."
("ctags-candidates" ctags-candidates)
("citre-candidates" citre-candidates)
("org-roam-candidates" org-roam-candidates)
("file-words-candidates" (acm-backend-search-file-words-candidates keyword))
("file-words-candidates" file-words-candidates)
("telega-candidates" (acm-backend-telega-candidates keyword))
))
acm-completion-mode-candidates-merge-order)))
Expand Down

0 comments on commit 9e21846

Please sign in to comment.