diff --git a/modules/lang/rust/autoload.el b/modules/lang/rust/autoload.el index 7f4fc80b5..d95e360b4 100644 --- a/modules/lang/rust/autoload.el +++ b/modules/lang/rust/autoload.el @@ -19,6 +19,7 @@ ;; ;;; Custom Cargo commands +(autoload 'rustic-run-cargo-command "rustic-cargo") ;;;###autoload (defun +rust/cargo-audit () "Run 'cargo audit' for the current project." diff --git a/modules/lang/rust/config.el b/modules/lang/rust/config.el index cb850f6e9..9e6088a6f 100644 --- a/modules/lang/rust/config.el +++ b/modules/lang/rust/config.el @@ -9,29 +9,39 @@ (use-package! rustic :mode ("\\.rs$" . rustic-mode) - :commands rustic-run-cargo-command rustic-cargo-outdated :init (after! org-src (defalias 'org-babel-execute:rust #'org-babel-execute:rustic) - (add-to-list 'org-src-lang-modes '("rust" . rustic))) + (add-to-list 'org-src-lang-modes '("rust" . rustic)) + (add-to-list 'org-babel-tangle-lang-exts '("rustic" . "rs"))) :config + (setq rustic-indent-method-chain t) + (set-docsets! 'rustic-mode "Rust") (set-popup-rule! "^\\*rustic-compilation" :vslot -1) - (setq rustic-indent-method-chain t - ;; use :editor format instead + ;; Leave automatic reformatting to the :editor format module. + (set-formatter! 'rustfmt #'rustic-format-buffer :modes '(rustic-mode)) + (setq rustic-babel-format-src-block (featurep! :editor format +onsave) rustic-format-trigger nil) - (if (featurep! +lsp) - (add-hook 'rustic-mode-local-vars-hook #'lsp!) - (setq rustic-lsp-server nil) - (after! rustic-flycheck - (add-to-list 'flycheck-checkers 'rustic-clippy))) + ;; HACK `rustic-flycheck' adds all these hooks in disruptive places. Instead, + ;; leave it to our :checkers syntax module to do all the set up properly. + (remove-hook 'rustic-mode-hook #'flycheck-mode) + (remove-hook 'rustic-mode-hook #'flymake-mode-off) + (unless (featurep! +lsp) + (add-to-list 'flycheck-checkers 'rustic-clippy)) + ;; HACK `rustic-lsp' sets up lsp-mode/eglot too early. We move it to + ;; `rustic-mode-local-vars-hook' so file/dir local variables can be used + ;; to reconfigure them. (when (featurep! +lsp) - (if (featurep! :tools lsp +eglot) - (setq rustic-lsp-client 'eglot) - (setq rustic-lsp-client 'lsp-mode))) + (remove-hook 'rustic-mode-hook #'rustic-setup-lsp) + (add-hook 'rustic-mode-local-vars-hook #'rustic-setup-lsp) + (setq rustic-lsp-client + (if (featurep! :tools lsp +eglot) + 'eglot + 'lsp-mode))) (map! :map rustic-mode-map :localleader @@ -50,15 +60,6 @@ :desc "all" "a" #'rustic-cargo-test :desc "current test" "t" #'rustic-cargo-current-test)) - ;; HACK Fixes #2541: RLS doesn't appear to support documentSymbol, but - ;; lsp-rust thinks it does, and so yields imenu population to the server. - ;; The result is an empty imenu list. Until RLS supports documentSymbol, - ;; we disable `lsp-enable-imenu' is rust+RLS buffers. - (defadvice! +rust--disable-imenu-for-lsp-mode-a (&rest _) - :before #'rustic-lsp-mode-setup - (when (eq rustic-lsp-server 'rls) - (setq-local lsp-enable-imenu nil))) - ;; If lsp/elgot isn't available, it attempts to install lsp-mode via ;; package.el. Doom manages its own dependencies through straight so disable ;; this behavior to avoid package-not-initialized errors. diff --git a/modules/lang/rust/packages.el b/modules/lang/rust/packages.el index 4737941e5..dba6ce9d5 100644 --- a/modules/lang/rust/packages.el +++ b/modules/lang/rust/packages.el @@ -1,6 +1,6 @@ ;; -*- no-byte-compile: t; -*- ;;; lang/rust/packages.el -(package! rustic :pin "d97ec8623c4c7e7ad3bb32e3d3773ba29a34bb0d") +(package! rustic :pin "ed68fd3bb410869e1a4ce3943b5913ea88d9b509") (unless (featurep! +lsp) (package! racer :pin "1e63e98626737ea9b662d4a9b1ffd6842b1c648c"))