company-lsp
company-lsp copied to clipboard
Slow completion for rust strings and comments
When company runs completion either using company-idle-delay
or manually in the comments or strings it will hang emacs for up to several seconds. It looks like it makes a very generic query to the lsp server for every character I type.
On emacs-26 it works even worse because it spents 50% of the time in lsp--read-json
, but I managed to fix it by using emacs-devel
and use-native-json
param for lsp-rust
client.
- timer-event-handler 1253 20%
- apply 1248 20%
- company-idle-begin 1044 17%
- company-auto-begin 976 16%
- company--perform 976 16%
- company--begin-new 976 16%
- company-calculate-candidates 976 16%
- company--fetch-candidates 976 16%
- company-call-backend-raw 973 16%
- apply 973 16%
- company-capf 973 16%
- completion-all-completions 973 16%
- completion--nth-completion 973 16%
- completion--some 973 16%
- #<compiled 0x1bf2da1> 973 16%
- completion-basic-all-completions 353 5%
- completion-pcm--all-completions 353 5%
- all-completions 353 5%
- #<compiled 0x1bf2a61> 353 5%
- #<compiled 0x17a4605> 353 5%
+ lsp--send-request 346 5%
+ seq-map 4 0%
file-truename 3 0%
- completion-pcm-all-completions 331 5%
- completion-pcm--find-all-completions 331 5%
- completion-pcm--all-completions 331 5%
- all-completions 331 5%
- #<compiled 0x1bd761d> 331 5%
- #<compiled 0x17a4605> 331 5%
+ lsp--send-request 325 5%
+ seq-map 6 0%
+ completion-emacs22-all-completions 289 4%
+ sit-for 3 0%
+ company-post-command 68 1%
+ sp-show--pair-function 148 2%
+ #<compiled 0x1d93bf5> 12 0%
+ #<compiled 0x202bad> 11 0%
+ show-paren-function 10 0%
+ savehist-autosave 4 0%
+ timer-activate-when-idle 3 0%
#57 is adding native JSON support. I don't think there is much company-lsp
can do if the bottle neck is JSON parsing. Is it possible to configure Rust language server to return fewer completion results?
I think it would be nice to prevent completion in strings in comments, but I'm not sure if this is possible.
I think company-lsp already does that. Is it not working?
The profile I've showed in the first post is made by typing random letters in the top level comment. lsp/rust related config:
(use-package lsp-mode)
(use-package lsp-ui
:config
(setq lsp-ui-sideline-delay 0.5))
(use-package lsp-rust
:config
(require 'lsp-ui)
(add-hook 'lsp-mode-hook 'lsp-ui-mode))
(use-package company-lsp
:config
(push 'company-lsp company-backends)
(setq company-lsp-enable-snippet nil))
(use-package rust-mode
:config
(add-hook 'rust-mode-hook #'lsp-rust-enable))
(use-package flycheck-rust
:config (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))
(use-package company
:config
(setq company-tooltip-limit 10
company-idle-delay 0.05
company-minimum-prefix-length 2
company-show-numbers t
company-tooltip-align-annotations t))
As @tigersoldier soldier said, it looks like company-lsp doesn't trigger in comments or strings. I had the same problem, however, and I narrowed it down to flyspell
and company-capf
. What I did was to remove company-capf
from the company backends in rust-mode
and it works now. This is the ilne I added:
(add-hook 'rust-mode-hook
(lambda () (setq company-backends
(delete 'company-capf company-backends))))
(add-hook 'rust-mode-hook (lambda () (setq company-backends (delete 'company-capf company-backends))))
This helps, thanks!