mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
feat(language/rust): major improvements to Rust dev experience
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"GOPRIVATE"
|
||||
"GOENV_GOPATH_PREFIX"
|
||||
"GOENV_VERSION"
|
||||
"RUST_BACKTRACE"
|
||||
"MallocNanoZone"))
|
||||
(exec-path-from-shell-arguments '("-l"))
|
||||
(exec-path-from-shell-check-startup-files nil)
|
||||
|
||||
@@ -30,20 +30,61 @@
|
||||
(rust-mode . siren-lsp-rust-mode-setup)
|
||||
|
||||
:preface
|
||||
(defun siren-lsp-rust-mode-setup ()
|
||||
(defun siren-lsp-rust-mode-setup ()
|
||||
(lsp-format-buffer-on-save-mode t)
|
||||
(lsp-organize-imports-on-save-mode t)
|
||||
(lsp-deferred)))
|
||||
(lsp)
|
||||
|
||||
;; Disable semantic tokens as it typically causes an annoying delay with the
|
||||
;; syntax highlighting as you type. Essentially all new text is a very faded
|
||||
;; out grey color for the first 1-2 seconds as you type.
|
||||
(lsp-semantic-tokens-mode -1))
|
||||
|
||||
;; Fixes for eldoc, see:
|
||||
;; - https://github.com/emacs-lsp/lsp-mode/pull/1740
|
||||
;; - https://github.com/scturtle/dotfiles/blob/b7fdc06ca4ef4fd60170ac4ef57e3d1c9cf9a498/doom_emacs/.doom.d/config.el#L62-L77
|
||||
|
||||
;; extract and show short signature for rust-analyzer
|
||||
(cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql rust-analyzer)))
|
||||
(let* ((value (if lsp-use-plists (plist-get contents :value) (gethash "value" contents)))
|
||||
(groups (--partition-by (s-blank? it) (s-lines (s-trim value))))
|
||||
(sig_group (if (s-equals? "```rust" (car (-third-item groups)))
|
||||
(-third-item groups)
|
||||
(car groups)))
|
||||
(sig (--> sig_group
|
||||
(--drop-while (s-equals? "```rust" it) it)
|
||||
(--take-while (not (s-equals? "```" it)) it)
|
||||
(--map (s-trim it) it)
|
||||
(s-join " " it))))
|
||||
(lsp--render-element (concat "```rust\n" sig "\n```"))))
|
||||
|
||||
;; do not cache the shitty result from rust-analyzer
|
||||
(advice-add #'lsp-eldoc-function :after (lambda (&rest _) (setq lsp--hover-saved-bounds nil))))
|
||||
|
||||
(use-package cargo
|
||||
:hook (rust-mode . cargo-minor-mode))
|
||||
:hook (rust-mode . cargo-minor-mode)
|
||||
:general
|
||||
(:keymaps 'rust-mode-map
|
||||
"C-c , a" 'cargo-process-test))
|
||||
|
||||
(use-package cargo-transient
|
||||
:general
|
||||
(:keymaps 'rust-mode-map
|
||||
"C-'" 'cargo-transient
|
||||
"C-c C-," 'cargo-transient)
|
||||
|
||||
:custom
|
||||
(cargo-transient-compilation-buffer-name-function
|
||||
'cargo-transient-project-prefixed-buffer-name))
|
||||
|
||||
(use-package flycheck-rust
|
||||
:after rust-mode
|
||||
:hook (flycheck-mode . flycheck-rust-setup))
|
||||
|
||||
(use-package rust-playground
|
||||
:defer t)
|
||||
:defer t
|
||||
:general
|
||||
(:keymaps 'rust-playground-mode-map
|
||||
"C-<return>" 'rust-playground-exec))
|
||||
|
||||
(provide 'siren-rust)
|
||||
;;; siren-rust.el ends here
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
(use-package conf-toml-mode
|
||||
:straight (:type built-in)
|
||||
:mode "\\.toml\\'"
|
||||
:mode "\\.toml\\'" "Cargo\\.lock\\'"
|
||||
:hook (conf-toml-mode . siren-toml-mode-setup)
|
||||
|
||||
:preface
|
||||
|
||||
Reference in New Issue
Block a user