branch: externals/company
commit 57a6554db750567917f1192463e2503787f9b883
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>
company-clang--parse-output: Filter out duplicates
Fixes #841
Based on a patch by Gregory Heytings.
---
NEWS.md | 2 ++
company-clang.el | 21 ++++++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index ef0773e..dd7276a 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
## Next
+* `company-clang` filters out duplicates
+ ([#841](https://github.com/company-mode/company-mode/issues/841)).
* New user option `company-tooltip-width-grow-only`.
* `company-xcode` has been removed. It has not been useful for years now.
* `company-clang` has been moved to after `company-capf` in the default value
of
diff --git a/company-clang.el b/company-clang.el
index 1460e09..df458c5 100644
--- a/company-clang.el
+++ b/company-clang.el
@@ -136,6 +136,7 @@ or automatically through a custom
`company-clang-prefix-guesser'."
(let ((pattern (format company-clang--completion-pattern
(regexp-quote prefix)))
(case-fold-search nil)
+ (results (make-hash-table :test 'equal :size (/ (point-max) 100)))
lines match)
(while (re-search-forward pattern nil t)
(setq match (match-string-no-properties 1))
@@ -144,11 +145,21 @@ or automatically through a custom
`company-clang-prefix-guesser'."
(when (string-match ":" match)
(setq match (substring match 0 (match-beginning 0)))))
(let ((meta (match-string-no-properties 2)))
- (when (and meta (not (string= match meta)))
- (put-text-property 0 1 'meta
- (company-clang--strip-formatting meta)
- match)))
- (push match lines)))
+ ;; Avoiding duplicates:
+ ;; https://github.com/company-mode/company-mode/issues/841
+ (cond
+ ;; Either meta != completion (not a macro)
+ ((not (equal match meta))
+ (puthash match meta results))
+ ;; Or it's the first time we see this completion
+ ((eq (gethash match results 'none) 'none)
+ (puthash match nil results))))))
+ (maphash
+ (lambda (match meta)
+ (when meta
+ (put-text-property 0 1 'meta (company-clang--strip-formatting meta)
match))
+ (push match lines))
+ results)
lines))
(defun company-clang--meta (candidate)