Skip to content

Commit

Permalink
Introduce lsp-completion-passthrough-try-completion for lsp-passthrough
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgutov committed Sep 12, 2024
1 parent dd61303 commit 9b0d9b1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lsp-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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."))

Expand Down

0 comments on commit 9b0d9b1

Please sign in to comment.