rust: Improved LSP Rust server switch functionality

Currently, when `lsp` backend is used for `rust` layer, `SPC m s s` is bound to
`lsp-rust-switch-server`, which temporarily changes the preferred LSP server
for `rust-mode`, but it DOES NOT switch the running LSP server. Users need to
call `lsp-workspace-restart` to finish the switching.

This PR introduced a new function `spacemacs//lsp-rust-switch-server`, which is
a wrapper for the two aforementioned functions
This commit is contained in:
Lucius Hu 2021-03-15 15:17:03 -04:00 committed by duianto
parent 9e4845b913
commit d6eb0f9fe6
3 changed files with 9 additions and 3 deletions

View file

@ -3320,6 +3320,7 @@ files (thanks to Daniel Nicolai)
- Added/Updated instructions on external dependencies, =cargo-edit=,
=cargo-audit=, =rustfmt=, and =clippy= (thanks to Lucius Hu)
- Added support for Rusty Object Notation (RON) (thanks to Daniel Hutzley)
- Improved LSP Rust server switch functionality (thanks to Lucius Hu)
**** Sailfish-Developer
- Key bindings:
- Added =sailfish-scratchbox= key bindings (thanks to Victor Polevoy):

View file

@ -81,8 +81,7 @@ To choose the experimental [[https://github.com/rust-analyzer/rust-analyzer][rus
#+END_SRC
**** Switch to another LSP server
If both =rls= and =rust-analyzer= server are installed, you can press ~SPC m s s~ to select
another LSP server backend, and press ~SPC m b r~ to restart the LSP server to finish the switching.
If both =rls= and =rust-analyzer= server are installed, you can press ~SPC m s s~ to switch to another LSP server backend.
**** Autocompletion
To enable auto-completion, ensure that the =auto-completion= layer is enabled.

View file

@ -40,6 +40,12 @@
(message (concat "`lsp' layer is not installed, "
"please add `lsp' layer to your dotfile.")))
(defun spacemacs//lsp-rust-switch-server ()
"Switch between rust-analyzer and rls."
(interactive)
(lsp-rust-switch-server)
(call-interactively 'lsp-workspace-restart))
(defun spacemacs//rust-setup-lsp ()
"Setup lsp backend"
(if (configuration-layer/layer-used-p 'lsp)
@ -47,7 +53,7 @@
(lsp)
(spacemacs/declare-prefix-for-mode 'rust-mode "ms" "switch")
(spacemacs/set-leader-keys-for-major-mode 'rust-mode
"ss" 'lsp-rust-switch-server))
"ss" 'spacemacs//lsp-rust-switch-server))
(spacemacs//lsp-layer-not-installed-message)))
(defun spacemacs//rust-setup-lsp-dap ()