Skip to content

Commit

Permalink
Make lsp-completion-passthrough-try-completion more basic (#4602)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiennq authored Nov 24, 2024
1 parent 0f156f2 commit c3aa25d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
22 changes: 7 additions & 15 deletions lsp-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ The MARKERS and PREFIX value will be attached to each candidate."
(setq fuz-queries
(plist-put fuz-queries start-point s))
s)))
(label-len (length label)))
(label-len (length label))
(case-fold-search completion-ignore-case))
(when (string-match fuz-query label)
(put-text-property 0 label-len 'match-data (match-data) label)
(plist-put cand
Expand Down Expand Up @@ -701,7 +702,8 @@ Others: CANDIDATES"
"Calculate fuzzy score for STR with query QUERY.
The return is nil or in range of (0, inf)."
(-when-let* ((md (cddr (or (get-text-property 0 'match-data str)
(let ((re (lsp-completion--regex-fuz query)))
(let ((re (lsp-completion--regex-fuz query))
(case-fold-search completion-ignore-case))
(when (string-match re str)
(match-data))))))
(start (pop md))
Expand Down Expand Up @@ -776,19 +778,9 @@ The return is nil or in range of (0, inf)."
"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-try-completion (string _table _pred point)
"Passthrough try function, always return the passed STRING and POINT."
(cons string point))

(defun lsp-completion-passthrough-all-completions (_string table pred _point)
"Passthrough all completions from TABLE with PRED."
Expand Down
11 changes: 6 additions & 5 deletions test/lsp-completion-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@

(ert-deftest lsp-completion-test-fuz-score ()
(cl-labels ((do-test (query cands expected)
(should (equal
(sort cands
(lambda (l r) (> (lsp-completion--fuz-score query l)
(lsp-completion--fuz-score query r))))
expected))))
(let ((completion-ignore-case t))
(should (equal
(sort cands
(lambda (l r) (> (or (lsp-completion--fuz-score query l) 0)
(or (lsp-completion--fuz-score query r) 0))))
expected)))))
(do-test "as"
'("hashCode() : int"
"asSubclass(Class<U> clazz) : Class<? extends U>")
Expand Down

0 comments on commit c3aa25d

Please sign in to comment.