branch: master commit 307b62063c2376e6432d7ed9c4e79f25c50edabf Author: Dmitry Gutov <dgu...@yandex.ru> Commit: Dmitry Gutov <dgu...@yandex.ru>
Simplify how async backends are called (WIP) Aiming to fix #510 and #654, but no visible improvement yet. --- company-clang.el | 4 +++- company.el | 37 ++++++++++++------------------------- test/async-tests.el | 1 + 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/company-clang.el b/company-clang.el index 90a372e..43ecc8e 100644 --- a/company-clang.el +++ b/company-clang.el @@ -343,7 +343,9 @@ passed via standard input." (if (string-match "\\`:[^:]" anno) (company-template-objc-templatify anno) (company-template-c-like-templatify - (concat arg anno)))))))) + (concat arg anno)))))) + ;; FIXME: Remove, this is just for testing. + (no-cache t))) (provide 'company-clang) ;;; company-clang.el ends here diff --git a/company.el b/company.el index 68fcaaa..173266d 100644 --- a/company.el +++ b/company.el @@ -1220,36 +1220,23 @@ can retrieve meta-data for them." (let* ((non-essential (not (company-explicit-action-p))) (c (if company--manual-action (company-call-backend 'candidates prefix) - (company-call-backend-raw 'candidates prefix))) - res) + (company-call-backend-raw 'candidates prefix)))) (if (not (eq (car c) :async)) c - (let ((buf (current-buffer)) - (win (selected-window)) - (tick (buffer-chars-modified-tick)) - (pt (point)) - (backend company-backend)) + (let ((res 'none)) (funcall (cdr c) (lambda (candidates) - (if (not (and candidates (eq res 'done))) - ;; There's no completions to display, - ;; or the fetcher called us back right away. - (setq res candidates) - (setq company-backend backend - company-candidates-cache - (list (cons prefix - (company--preprocess-candidates candidates)))) - (unwind-protect - (company-idle-begin buf win tick pt) - (unless company-candidates - (setq company-backend nil - company-candidates-cache nil))))))) - ;; FIXME: Relying on the fact that the callers - ;; will interpret nil as "do nothing" is shaky. - ;; A throw-catch would be one possible improvement. - (or res - (progn (setq res 'done) nil))))) + (setq res candidates))) + (while (and (eq res 'none) + (not (input-pending-p t))) + ;; FIXME: This still leads to flickers. + ;; Apparently sit-for triggers redisplay anyway. + (sleep-for company-async-wait)) + ;; (if (listp res) + ;; (message "res len is %s" (length res)) + ;; (message "none")) + (and (consp res) res))))) (defun company--preprocess-candidates (candidates) (cl-assert (cl-every #'stringp candidates)) diff --git a/test/async-tests.el b/test/async-tests.el index 48ebdfb..889ff13 100644 --- a/test/async-tests.el +++ b/test/async-tests.el @@ -66,6 +66,7 @@ (let (company-frontends company-transformers (company-backends (list 'company-async-backend))) + ;; FIXME: Remove such tests? (company-idle-begin (current-buffer) (selected-window) (buffer-chars-modified-tick) (point)) (should (null company-candidates))