syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.69k stars 4.9k forks source link

Rust LSP Auto-completion Does Not Expand Correctly #12766

Closed BigBeautifulBro closed 3 years ago

BigBeautifulBro commented 5 years ago

Description :octocat:

When using the Rust layer with auto-completion and LSP as the company backend, selecting a completion from the dropdown list does not work properly when the completion candidate is a function with one or more parameters. In this situation when using M-x company-complete, after selecting a candidate, the selection's yasnippet template is incorrectly pasted as-is without expansion. This issue also occurs when attempting to a select a candidate by just typing a couple letters, waiting for the autocompletion list without using M-x company-complete, and then selecting a candidate.

Auto-completion works properly and as expected when using M-x company-lsp instead of M-x company-complete.

If the solution is that users should use M-x company-lsp when using Rust with LSP as the company backend, please document this. This was not obvious to me, and I thought you should be using M-x company-complete.

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart: The text "replace(${1:from: P}, ${2:to: &str})" is pasted literally as a completion with the user's cursor at the end of this text. The user is not able to edit the parameters as a yasnippet expansion.

Expected behaviour: :heart: :smile: The text "replace(from: P, to: &str)" should be pasted as a completion with the user's cursor in the first parameter allowing them to edit the parameters as a yasnippet expansion.

System Info :computer:

BigBeautifulBro commented 5 years ago

For others that are having this issue, an easy temporary work around is to just disable the automatic completion pop-up and change the bind for company-complete in rust mode:

; Under dotspacemacs-configuration-layers
; Ensure auto-completion-idle-delay is nil to prevent automatic completion pop-up
(auto-completion :variables
                      auto-completion-enable-help-tooltip t
                      auto-completion-enable-snippets-in-popup nil
                      auto-completion-return-key-behavior 'complete
                      auto-completion-tab-key-behavior nil
                      auto-completion-idle-delay nil
                      :disabled-for org erc)

...
; Under dotspacemacs/user-config
  (global-set-key (kbd "C-.") 'company-complete)
  (define-key spacemacs-rust-mode-map-root-map
    (kbd "C-.") 'company-lsp)
MarcoIeni commented 4 years ago

Hi, I reproduced your problem but for me it works, I am using rust-analyzer. Peek 2020-04-14 11-48

As you can see from my config I copy-pasted your auto-complete settings

System Info :computer:

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

lebensterben commented 3 years ago

Closing since