Skip to content

Commit 2e5f23a

Browse files
authored
If table is a function, only passthrough if its result is non-nil (emacs-lsp#4684)
* If table is a function, only passthrough if its result is non-nil * Let non-empty hash tables pass through as well
1 parent 0252be2 commit 2e5f23a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lsp-completion.el

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,19 @@ The return is nil or in range of (0, inf)."
850850
"Disable LSP completion support."
851851
(lsp-completion-mode -1))
852852

853-
(defun lsp-completion-passthrough-try-completion (string table _pred point)
854-
"Passthrough try function, always return the passed STRING and POINT."
855-
(when table
853+
(defun lsp-completion-passthrough-try-completion (string table pred point)
854+
"Passthrough try function.
855+
856+
If TABLE is a function, it is called with STRING, PRED and nil to get
857+
the candidates, otherwise it is treated as the candidates.
858+
859+
If the candidates is non-empty, return the passed STRING and POINT."
860+
(when (pcase table
861+
((pred functionp)
862+
(funcall table string pred nil))
863+
((pred hash-table-p)
864+
(not (hash-table-empty-p table)))
865+
(_ table))
856866
(cons string point)))
857867

858868
(defun lsp-completion-passthrough-all-completions (_string table pred _point)

0 commit comments

Comments
 (0)