lsp-mode icon indicating copy to clipboard operation
lsp-mode copied to clipboard

company-minimum-prefix-length isn't taken into account when backspacing

Open haoyuan80s opened this issue 5 years ago • 14 comments

I have (setq company-minimum-prefix-length 1). The company starts after I type one letter, but keep triggering after I delete the letter (it is slow to complete with zero length prefix). Any fix for that?


After typing one letter: image After deleting that letter: image

haoyuan80s avatar May 19 '20 00:05 haoyuan80s

Company without lsp-mode works well.

haoyuan80s avatar May 19 '20 00:05 haoyuan80s

(use-package company-lsp
  :ensure t)
(push 'company-lsp company-backends)

Adding company-lsp fixed the issue but it is no longer supported. Any fix without using company-lsp?

haoyuan80s avatar May 19 '20 01:05 haoyuan80s

Seems to happen when I use csharp lsp-mode. I have (setq company-minimum-prefix-length 2) but it triggers after one character and keep triggering after delete.

Screen Shot 2564-07-14 at 22 13 07 Screen Shot 2564-07-14 at 22 13 13

suzuki11109 avatar Jul 14 '21 15:07 suzuki11109

What's your lsp-mode version? Can you take io trace when this happens?

kiennq avatar Jul 15 '21 15:07 kiennq

@kiennq FYI it reproduces with lsp-start-plain.el

yyoncho avatar Jul 15 '21 16:07 yyoncho

Does it only happen with csharp language server?

kiennq avatar Jul 15 '21 17:07 kiennq

@kiennq FYI it reproduces with lsp-start-plain.el

disregard that, I though that I am in another issue.

yyoncho avatar Jul 15 '21 17:07 yyoncho

@kiennq So far I see this problem only in csharp. I tried again with lsp-start-plain.el and the behaviour is kind of improved. I think this happen when company-yasnippets is enabled. After I disable yasnippets, the candidates are more relevant but company-minimum-prefix-length is still not working (company triggered after typing 1 character even though company-minimum-prefix-length is 2).

suzuki11109 avatar Jul 16 '21 02:07 suzuki11109

I found out the problem, csharp language server is sending space as trigger character, that's why the automatic completion is triggered even if you type with 1 character (you or Emacs must have insert spaces before the current symbol). Since space as trigger character is too invasive, I think we can help a new custom setting/defvar to specify the character that will be omitted from the trigger characters list. @yyoncho WDYT?

kiennq avatar Jul 16 '21 03:07 kiennq

Same with https://github.com/merrickluo/lsp-tailwindcss/ Since tailwindcss language server is using space as trigger char as well, it would trigger completion even with 1 space and with tons of tailwind css classes to complete, the typing becomes extremely slow

dsdshcym avatar Sep 13 '21 12:09 dsdshcym

Some thing like this might help

(advice-add #'lsp-completion--looking-back-trigger-characterp
            :filter-args
            (lambda (r) (seq-remove (lambda (it) (equal it " ")) r))
            '((name . --filter-spaces)))

kiennq avatar Sep 13 '21 14:09 kiennq

I see that happening in both Scala and Haskell and the workaround does not help.

dmvianna avatar Mar 28 '23 01:03 dmvianna

I think I'm hitting the same behaviour with company and lsp:

Despite 'company-minimum-prefix-length' set to '3', completion happens even with 0 characters.

sunilw avatar Sep 23 '23 03:09 sunilw