From 9b0d9b1745f6dcad14365eafb066ac5b09a3559d Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 12 Sep 2024 04:22:00 +0300 Subject: [PATCH] Introduce lsp-completion-passthrough-try-completion for lsp-passthrough 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. --- lsp-completion.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lsp-completion.el b/lsp-completion.el index 0f2be89544..3453a1b606 100644 --- a/lsp-completion.el +++ b/lsp-completion.el @@ -755,6 +755,20 @@ The CLEANUP-FN will be called to cleanup." "Disable LSP completion support." (lsp-completion-mode -1)) +(defun lsp-completion-passthrough-try-completion (string table pred point) + (let* ((completion-ignore-case t) + (try (completion-basic-try-completion string table pred point)) + (newstr (car try)) + (newpoint (cdr try)) + (beforepoint (and try (substring newstr 0 newpoint)))) + (if (and beforepoint + (string-prefix-p + beforepoint + (try-completion "" table pred) + t)) + try + (cons string point)))) + (defun lsp-completion-passthrough-all-completions (_string table pred _point) "Passthrough all completions from TABLE with PRED." (defvar completion-lazy-hilit-fn) @@ -790,7 +804,7 @@ The CLEANUP-FN will be called to cleanup." (setf (alist-get 'lsp-capf completion-category-defaults) '((styles . (lsp-passthrough)))) (make-local-variable 'completion-styles-alist) (setf (alist-get 'lsp-passthrough completion-styles-alist) - '(completion-basic-try-completion + '(lsp-completion-passthrough-try-completion lsp-completion-passthrough-all-completions "Passthrough completion."))