Require rust and racer
(require 'rust-mode)
(require 'racer)
(require 'cargo)
(require 'eglot)
We format the source code on file save.
(setq rust-format-on-save t)
We configure the rust path.
(setq racer-rust-src-path
(concat (string-trim
(shell-command-to-string "rustc --print sysroot"))
"/lib/rustlib/src/rust/library"))
We setup flymake mode for rust now.
(require 'flymake-rust)
(add-hook 'rust-mode-hook 'flymake-rust-load)
Add rust related hooks
(require 'rust-mode)
(require 'eglot)
(unless (fboundp 'lsp-rust-enable)
(defun lsp-rust-enable ()
()))
(add-hook 'rust-mode-hook #'cargo-minor-mode)
(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'rust-mode-hook #'eldoc-mode)
(add-hook 'rust-mode-hook #'company-mode)
(add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
(add-hook 'rust-mode-hook #'eglot-ensure)
;;(require 'lsp-clients)
We add a couple of general eglot bindings. This is not Rust specific anymore, but as we are showcasing it here it is helpful.
(define-key eglot-mode-map (kbd "C-c h") 'eglot-help-at-point)
(define-key eglot-mode-map (kbd "C-c C-h") 'xref-find-references)
Now setup TAB to autocomplete in rust mode. Then setup clippy from cargo also