From a982f0fe043c31aca1a11a663c41c33b76ef0c19 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 16 Apr 2013 06:24:53 +0400 Subject: [PATCH] company--multi-backend-adapter: Use each respective backend's prefix --- NEWS.md | 3 +++ company-tests.el | 19 +++++++++++++++++++ company.el | 6 +++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 91064a45e..b63d5ed5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ ## Next +* Candidates from grouped back-ends are retrieved more accurately: each + `candidates` command receives in the second argument the respective value the + back-end returned to the `prefix` command. * `company-auto-complete` is disabled by default. * `company-auto-complete-chars` default value includes fewer syntax classes. * In expanded function calls, arguments skipped by the user default to "argN". diff --git a/company-tests.el b/company-tests.el index 309d8f1f8..657486b09 100644 --- a/company-tests.el +++ b/company-tests.el @@ -159,6 +159,25 @@ (should (null company-candidates)) (should (null (company-explicit-action-p)))))) +(ert-deftest company-multi-backend-adapter-uses-respective-prefixes () + ;; And ignores the second argument. + (let ((company-backend + (list (lambda (command &optional arg) + (case command + (prefix "bar") + (candidates (mapcar (lambda (tail) (concat arg "-" tail)) + '("a" "b" "c"))))) + (lambda (command &optional arg) + (case command + (prefix "foo-bar") + (candidates (mapcar (lambda (tail) (concat arg "-" tail)) + '("d" "e")))))))) + (should (equal (sort '("bar-a" "bar-b" "bar-c" "foo-bar-d" "foo-bar-e") + 'string<) + (company-call-backend 'candidates "hubba-hubba"))))) + +;; Pseudo-Tooltip + (ert-deftest company-pseudo-tooltip-does-not-get-displaced () (with-temp-buffer (save-window-excursion diff --git a/company.el b/company.el index 9f13518f0..3fa83534a 100644 --- a/company.el +++ b/company.el @@ -658,9 +658,9 @@ keymap during active completions (`company-active-map'): (case command (candidates (loop for backend in backends - when (equal (funcall backend 'prefix) - (car args)) - append (apply backend 'candidates args))) + for prefix = (funcall backend 'prefix) + when prefix + append (funcall backend 'candidates prefix))) (sorted nil) (duplicates t) (otherwise -- 2.39.2