fix(emacs/lean-company): handle singleton candidate case

If we have a singleton auto-complete candidate (e.g. proof_irrel) and it
does not matched with input prefix (e.g. foo), we add the input
prefix (foo) as an extra candidate to prevent the
candidate (proof_irrel) from being automatically selected and completed.
This commit is contained in:
Soonho Kong 2014-09-29 17:01:42 -07:00
parent 113879a7dd
commit b538b3e0bf

View file

@ -215,6 +215,14 @@ triggers a completion immediately."
'start start
'prefix prefix)))
(defun company-lean--handle-singleton-candidate (prefix candidates)
"Handle singleton candidate. If the candidate does not start
with prefix, we add prefix itself as a candidate to prevent
from auto-completion."
(let ((candidate (car candidates)))
(cond ((s-prefix? prefix candidate) candidates)
(t `(,candidate ,prefix)))))
(defun company-lean--findp-candidates (prefix)
(let ((line-number (line-number-at-pos))
(column-number (current-column))
@ -223,7 +231,13 @@ triggers a completion immediately."
(lean-server-send-cmd-sync (lean-cmd-findp line-number prefix)
(lambda (candidates)
(lean-debug "executing continuation for FINDP")
(--map (company-lean--findp-make-candidate it prefix) candidates)))))
(setq candidates
(--map (company-lean--findp-make-candidate it prefix)
candidates))
(when (= (length candidates) 1)
(setq candidates
(company-lean--handle-singleton-candidate prefix candidates)))
candidates))))
(defun company-lean--findp-location (arg)
(lean-generate-tags)