Skip to content

Commit a195d47

Browse files
authored
Introduce lsp-completion-passthrough-try-completion for lsp-passthrough (#4544)
This makes is less "passthrough", but it checks that the string proposed by completion-basic-try-completion is actually a proper prefix of all the available completions. Otherwise no expansion. Which makes it more conservative.
1 parent 78c194d commit a195d47

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lsp-completion.el

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,20 @@ The CLEANUP-FN will be called to cleanup."
755755
"Disable LSP completion support."
756756
(lsp-completion-mode -1))
757757

758+
(defun lsp-completion-passthrough-try-completion (string table pred point)
759+
(let* ((completion-ignore-case t)
760+
(try (completion-basic-try-completion string table pred point))
761+
(newstr (car try))
762+
(newpoint (cdr try))
763+
(beforepoint (and try (substring newstr 0 newpoint))))
764+
(if (and beforepoint
765+
(string-prefix-p
766+
beforepoint
767+
(try-completion "" table pred)
768+
t))
769+
try
770+
(cons string point))))
771+
758772
(defun lsp-completion-passthrough-all-completions (_string table pred _point)
759773
"Passthrough all completions from TABLE with PRED."
760774
(defvar completion-lazy-hilit-fn)
@@ -790,7 +804,7 @@ The CLEANUP-FN will be called to cleanup."
790804
(setf (alist-get 'lsp-capf completion-category-defaults) '((styles . (lsp-passthrough))))
791805
(make-local-variable 'completion-styles-alist)
792806
(setf (alist-get 'lsp-passthrough completion-styles-alist)
793-
'(completion-basic-try-completion
807+
'(lsp-completion-passthrough-try-completion
794808
lsp-completion-passthrough-all-completions
795809
"Passthrough completion."))
796810

0 commit comments

Comments
 (0)