Skip to content

Commit

Permalink
Tailor completions items to the backend if necessary
Browse files Browse the repository at this point in the history
The :exit-function of the completion command doesn't get called under
special circumstances.  Fix this by altering the completion candidate.

Closes joaotavora#311.  Closes joaotavora#279.

* eglot.el (eglot--tailor-completions): New function.
(eglot-completion-at-point): Use it.
  • Loading branch information
nemethf committed Oct 6, 2019
1 parent 59ba0b1 commit 74a42ab
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,21 @@ is not active."
args)
:deferred method))))

(defun eglot--tailor-completions (items)
"Tailor completions ITEMS to the complation backend if necessary."
;; :exit-function doesn't get called under special circumstances.
;; Fix this by altering the completion candidate.
;; (github#311, github#279)
(when (and (eq this-command #'completion-at-point)
(eq (length items) 1)
(plist-get (aref items 0) :label))
(let* ((item (aref items 0))
(label (with-temp-buffer
(insert (plist-get item :label))
(goto-char 1)
(thing-at-point 'symbol t))))
(plist-put item :label label))))

(defun eglot-completion-at-point ()
"EGLOT's `completion-at-point' function."
(let* ((bounds (bounds-of-thing-at-point 'symbol))
Expand Down Expand Up @@ -1897,6 +1912,7 @@ is not active."
:deferred :textDocument/completion
:cancel-on-input t))
(items (if (vectorp resp) resp (plist-get resp :items))))
(eglot--tailor-completions items)
(setq
strings
(mapcar
Expand Down

0 comments on commit 74a42ab

Please sign in to comment.