@@ -287,7 +287,7 @@ Returns unresolved completion item detail."
287
287
288
288
(defvar lsp-completion--cache nil
289
289
" Cached candidates for completion at point function.
290
- In the form of plist (prefix-pos items :lsp-items : prefix ...).
290
+ In the form of plist (prefix-pos items :prefix ...).
291
291
When the completion is incomplete, `items' contains value of :incomplete." )
292
292
293
293
(defvar lsp-completion--last-result nil
@@ -334,62 +334,47 @@ Return `nil' when fails to guess prefix."
334
334
335
335
(defun lsp-completion--to-internal (items )
336
336
" Convert ITEMS into internal form."
337
- (--> items
338
- (-map (-lambda ((item &as &CompletionItem
339
- :label
340
- :filter-text?
341
- :_emacsStartPoint start-point
342
- :score? ))
343
- `( :label ,(or (unless (lsp-falsy? filter-text?) filter-text?) label)
344
- :item , item
345
- :start-point , start-point
346
- :score , score? ))
347
- it)))
348
-
349
- (cl-defun lsp-completion--filter-candidates (items &key
350
- lsp-items
351
- markers
352
- prefix
353
- &allow-other-keys )
354
- " List all possible completions in cached ITEMS with their prefixes.
355
- We can pass LSP-ITEMS, which will be used when there's no cache.
356
- The MARKERS and PREFIX value will be attached to each candidate."
357
- (lsp--while-no-input
358
- (->>
359
- (if items
360
- (--> (let (queries fuz-queries)
361
- (-keep (-lambda ((cand &as &plist :label :start-point :score ))
362
- (let* ((query (or (plist-get queries start-point)
363
- (let ((s (buffer-substring-no-properties
364
- start-point (point ))))
365
- (setq queries (plist-put queries start-point s))
366
- s)))
367
- (fuz-query (or (plist-get fuz-queries start-point)
368
- (let ((s (lsp-completion--regex-fuz query)))
369
- (setq fuz-queries
370
- (plist-put fuz-queries start-point s))
371
- s)))
372
- (label-len (length label))
373
- (case-fold-search completion-ignore-case))
374
- (when (string-match fuz-query label)
375
- (put-text-property 0 label-len 'match-data (match-data ) label)
376
- (plist-put cand
377
- :sort-score
378
- (* (or (lsp-completion--fuz-score query label) 1e-05 )
379
- (or score 0.001 )))
380
- cand)))
381
- items))
382
- (if lsp-completion--no-reordering
383
- it
384
- (sort it (lambda (o1 o2 )
385
- (> (plist-get o1 :sort-score )
386
- (plist-get o2 :sort-score )))))
387
- ; ; TODO: pass additional function to sort the candidates
388
- (-map (-rpartial #'plist-get :item ) it))
389
- lsp-items)
390
- (-map (lambda (item ) (lsp-completion--make-item item
391
- :markers markers
392
- :prefix prefix))))))
337
+ (-map (-lambda ((item &as &CompletionItem
338
+ :label
339
+ :_emacsStartPoint start-point
340
+ :score? ))
341
+ `( :label , label
342
+ :item , item
343
+ :start-point , start-point
344
+ :score , score? ))
345
+ items))
346
+
347
+ (defun lsp-completion--filter-candidates (items )
348
+ " List all possible completions in cached ITEMS with their prefixes."
349
+ (--> (let (queries fuz-queries)
350
+ (-keep (-lambda ((cand &as &plist :label :start-point :score ))
351
+ (let* ((query (or (plist-get queries start-point)
352
+ (let ((s (buffer-substring-no-properties
353
+ start-point (point ))))
354
+ (setq queries (plist-put queries start-point s))
355
+ s)))
356
+ (fuz-query (or (plist-get fuz-queries start-point)
357
+ (let ((s (lsp-completion--regex-fuz query)))
358
+ (setq fuz-queries
359
+ (plist-put fuz-queries start-point s))
360
+ s)))
361
+ (label-len (length label))
362
+ (case-fold-search completion-ignore-case))
363
+ (when (string-match fuz-query label)
364
+ (put-text-property 0 label-len 'match-data (match-data ) label)
365
+ (plist-put cand
366
+ :sort-score
367
+ (* (or (lsp-completion--fuz-score query label) 1e-05 )
368
+ (or score 0.001 )))
369
+ cand)))
370
+ items))
371
+ (if lsp-completion--no-reordering
372
+ it
373
+ (sort it (lambda (o1 o2 )
374
+ (> (plist-get o1 :sort-score )
375
+ (plist-get o2 :sort-score )))))
376
+ ; ; TODO: pass additional function to sort the candidates
377
+ (-map (-rpartial #'plist-get :item ) it)))
393
378
394
379
(defconst lsp-completion--kind->symbol
395
380
'((1 . text)
@@ -589,9 +574,13 @@ Returns resolved completion item details."
589
574
((or done? result) result)
590
575
((and (not lsp-completion-no-cache)
591
576
same-session?
592
- (listp (cl-second lsp-completion--cache)))
593
- (setf result (apply #'lsp-completion--filter-candidates
594
- (cdr lsp-completion--cache))))
577
+ (cl-second lsp-completion--cache))
578
+ (setf result (cl-destructuring-bind (_ items &key markers prefix) lsp-completion--cache
579
+ (-map
580
+ (lambda (item )
581
+ (lsp-completion--make-item item :markers markers :prefix prefix))
582
+ (lsp--while-no-input
583
+ (lsp-completion--filter-candidates items))))))
595
584
(t
596
585
(-let* ((resp (lsp-request-while-no-input
597
586
" textDocument/completion"
@@ -614,7 +603,12 @@ Returns resolved completion item details."
614
603
:_emacsStartPoint
615
604
(or (lsp-completion--guess-prefix item)
616
605
bounds-start)))
617
- it))))
606
+ it)
607
+ ; ; remove items with no label and filterText
608
+ (-remove
609
+ (-lambda ((&CompletionItem :filter-text? :label ))
610
+ (and (lsp-falsy? filter-text?) (lsp-falsy? label)))
611
+ it))))
618
612
(markers (list bounds-start (copy-marker (point ) t )))
619
613
(prefix (buffer-substring-no-properties bounds-start (point )))
620
614
(lsp-completion--no-reordering (not lsp-completion-sort-initial-results)))
@@ -625,17 +619,18 @@ Returns resolved completion item details."
625
619
((and done? (not (seq-empty-p items)))
626
620
(lsp-completion--to-internal items))
627
621
((not done?) :incomplete ))
628
- :lsp-items nil
629
622
:markers markers
630
623
:prefix prefix)
631
- result (lsp-completion--filter-candidates
632
- (cond (done?
633
- (cl-second lsp-completion--cache))
634
- (lsp-completion-filter-on-incomplete
635
- (lsp-completion--to-internal items)))
636
- :lsp-items items
637
- :markers markers
638
- :prefix prefix))))))
624
+ result (-map
625
+ (lambda (item )
626
+ (lsp-completion--make-item item :markers markers :prefix prefix))
627
+ ; ; Prevent company from flickering. See #2148.
628
+ (lsp--while-no-input
629
+ (->> (if (or (and done? (cl-second lsp-completion--cache))
630
+ (and lsp-completion-filter-on-incomplete
631
+ (lsp-completion--to-internal items)))
632
+ (lsp-completion--filter-candidates items)
633
+ items)))))))))
639
634
(:interrupted lsp-completion--last-result)
640
635
(`, res (setq lsp-completion--last-result res))))))
641
636
(list
0 commit comments