author | template | root_file |
---|---|---|
yyoncho |
comment.html |
docs/manual-language-docs/lsp-rust-analyzer.md |
NOTE: If you are using rustic-mode
, you have to change rustic-lsp-server
instead of lsp-rust-server
, since it also supports eglot as a lightweight alternative to lsp-mode.
-
lsp-rust-server
Choose LSP server (default is rust-analyzer) -
lsp-rust-switch-server
Switch priorities of lsp servers
Display syntax tree for current buffer
Display status information for rust-analyzer
Join selected lines into one, smartly fixing up whitespace and trailing commas
before:
after:
lsp-rust-analyzer-inlay-hints-mode
enables displaying of inlay hints
Additionally, lsp-rust-analyzer-server-display-inlay-hints
must be set to t
in order for inlay hints to render.
NOTE: the inlay hints interact badly with the lsp-ui sideline, because it doesn't seem to consider the overlays in its width calculation, which often leads to lines wrapping around.
lsp-rust-analyzer-expand-macro
expand macro call at point recursively
Use your own function for displaying macro expansion by customizing lsp-rust-analyzer-macro-expansion-method
Formatted and highlighted result with the default function of rustic.
Get a list of possible auto import candidates with lsp-execute-code-action
To support refactorings that require snippet insertion(eg. generating
derive clause etc), make sure that you have enabled yasnippet
and
yas-minor-mode
. If you are using use-package
, you can do something
like this:
(use-package yasnippet
:ensure t
:hook ((lsp-mode . yas-minor-mode)))
lsp-rust-analyzer-open-cargo-toml
opens the Cargo.toml closest to the current file. Calling it with a universal argument will open the Cargo.toml in another window.
Corresponds to the rust-analyzer LSP extension
lsp-rust-analyzer-open-external-docs
opens external documentation related to the current position in a browser.
Corresponds to the rust-analyzer LSP extension
lsp-rust-analyzer-related-tests
find all tests related to the current position, asks for user completion and executes the selected test in a compilation buffer.
Corresponds to the rust-analyzer LSP extension
In the example below, first you see that:
-
On the left, the function
check_infer
is defined, on the right another file is opened with many test functions, some of which callcheck_infer
. With the cursor oncheck_infer
, calllsp-rust-analyzer-related-tests
and selectinfer_pattern_match_slice
with fuzzy matching. The test is executed on the right with compilation major mode -
Move the cursor to
fn ellipsize
and attempt to find related tests to no avail. Confirm that the function is indeed untested by using swiper and finding one place in the file, where the function is called
- Rust Analyzer does not support disabling snippets - rust-lang/rust-analyzer#2518
This unmerged PR contains an example method that allows modifying the signature that is displayed by eldoc.
The following is an example configuration for using lsp-mode with a remote rust-analyzer server:
(with-eval-after-load "lsp-rust"
(lsp-register-client
(make-lsp-client
:new-connection (lsp-tramp-connection "rust-analyzer")
:remote? t
:major-modes '(rust-mode rustic-mode)
:initialization-options 'lsp-rust-analyzer--make-init-options
:notification-handlers (ht<-alist lsp-rust-notification-handlers)
:action-handlers (ht ("rust-analyzer.runSingle" #'lsp-rust--analyzer-run-single))
:library-folders-fn (lambda (_workspace) lsp-rust-analyzer-library-directories)
:after-open-fn (lambda ()
(when lsp-rust-analyzer-server-display-inlay-hints
(lsp-rust-analyzer-inlay-hints-mode)))
:ignore-messages nil
:server-id 'rust-analyzer-remote)))