@@ -561,11 +561,9 @@ Others: TRIGGER-CHARS CANDIDATES"
561
561
(format " \\ (%s \\ )" (regexp-quote (char-to-string c))))
562
562
str))))
563
563
564
- (defvar lsp-completion--fuz-case-sensitiveness 20
565
- " Case sensitiveness, can be in range of [0, inf)." )
566
-
567
564
(defun lsp-completion--fuz-score (query str )
568
- " Calculate fuzzy score for STR with query QUERY."
565
+ " Calculate fuzzy score for STR with query QUERY.
566
+ The return is nil or in range of (0, inf)."
569
567
(-when-let* ((md (cddr (or (get-text-property 0 'match-data str)
570
568
(let ((re (lsp-completion--regex-fuz query)))
571
569
(when (string-match re str)
@@ -610,21 +608,23 @@ Others: TRIGGER-CHARS CANDIDATES"
610
608
" Update score variables given match range (A B)."
611
609
(setq score-numerator (+ score-numerator (- b a)))
612
610
(unless (= a len)
611
+ ; ; case mis-match will be pushed to near next rank
612
+ (unless (equal (aref query q-ind) (aref str a))
613
+ (cl-incf a 0.9 ))
613
614
(setq score-denominator
614
615
(+ score-denominator
615
616
(if (= a last-b) 0
616
- ; ; Give a higher score for match near start
617
- ( + 1 ( expt ( - a last-b 1 ) ( if ( eq last-b -1 ) 0.75 0.25 )) ))
618
- ( if ( equal ( aref query q-ind) ( aref str a)) 0
619
- lsp-completion--fuz-case-sensitiveness ))))
617
+ ( + 1 ( * ( if ( < 0 ( - a last-b 1 )) 1 -1 )
618
+ ( expt ( abs ( - a last-b 1 ))
619
+ ; ; Give a higher score for match near start
620
+ ( if ( eq last-b -1 ) 0.75 0.25 )))) ))))
620
621
(setq last-b b))))
621
- (funcall update-score start start)
622
622
(while md
623
623
(funcall update-score start (cl-first md))
624
+ ; ; Due to the way completion regex is constructed, `(eq end (+ start 1))`
625
+ (cl-incf q-ind)
624
626
(pop md)
625
- (setq start (pop md))
626
- (cl-incf q-ind))
627
- (funcall update-score len len)
627
+ (setq start (pop md)))
628
628
(unless (zerop len)
629
629
(/ score-numerator (1+ score-denominator) 1.0 ))))
630
630
0 commit comments