]> code.delx.au - gnu-emacs-elpa/commitdiff
company-update-candidates: Don't be fooled by a few prefix completions
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 23 Nov 2014 03:36:15 +0000 (05:36 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 23 Nov 2014 03:36:25 +0000 (05:36 +0200)
...among non-prefix ones.

Obsoletes https://github.com/abingham/emacs-ycmd/pull/92.

`company-complete-common' was likewise too eager; this fixes it.

company-tests.el
company.el

index 26e98e2a98c0e481e40333c96ad67c81e09ba051..08b846388a35908fba6edc4943751202662e82ba 100644 (file)
       (should (eq t (company--good-prefix-p "abc")))
       (should (eq t (company--good-prefix-p '("bar" . t)))))))
 
+(ert-deftest company-common-with-non-prefix-completion ()
+  (let ((company-backend #'ignore)
+        (company-prefix "abc")
+        company-candidates
+        company-candidates-length
+        company-candidates-cache
+        company-common)
+    (company-update-candidates '("abc" "def-abc"))
+    (should (null company-common))
+    (company-update-candidates '("abc" "abe-c"))
+    (should (null company-common))
+    (company-update-candidates '("abcd" "abcde" "abcdf"))
+    (should (equal "abcd" company-common))))
+
 (ert-deftest company-multi-backend-with-lambdas ()
   (let ((company-backend
          (list (lambda (command &optional arg &rest ignore)
index a44f1507b3f8937ae8e2215e17d6052d3c3d549c..6ad5c66dcdc146bd927684c757394a1bc322e623 100644 (file)
@@ -1084,14 +1084,11 @@ can retrieve meta-data for them."
     ;; We want to support non-prefix completion, so filtering is the
     ;; responsibility of each respective backend, not ours.
     ;; On the other hand, we don't want to replace non-prefix input in
-    ;; `company-complete-common'.
+    ;; `company-complete-common', unless it's the sole candidate.
     (setq company-common
           (if (cdr company-candidates)
-              (let ((common (try-completion company-prefix company-candidates)))
-                (if (eq common t)
-                    ;; Mulple equal strings, probably with different
-                    ;; annotations.
-                    company-prefix
+              (let ((common (try-completion "" company-candidates)))
+                (when (string-prefix-p company-prefix common)
                   common))
             (car company-candidates)))))