2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/rust/config.el -*- lexical-binding: t; -*-
|
2015-09-30 12:28:52 -04:00
|
|
|
|
2019-10-19 15:25:29 -04:00
|
|
|
(after! projectile
|
|
|
|
(add-to-list 'projectile-project-root-files "Cargo.toml"))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! rustic
|
2019-11-07 12:49:30 -05:00
|
|
|
:mode ("\\.rs$" . rustic-mode)
|
2020-04-10 02:00:52 -04:00
|
|
|
:init
|
|
|
|
(after! org-src
|
2020-07-15 00:09:40 -04:00
|
|
|
(defalias 'org-babel-execute:rust #'org-babel-execute:rustic)
|
2021-05-02 17:26:01 -04:00
|
|
|
(add-to-list 'org-src-lang-modes '("rust" . rustic))
|
|
|
|
(add-to-list 'org-babel-tangle-lang-exts '("rustic" . "rs")))
|
2019-07-09 17:54:18 +02:00
|
|
|
:config
|
2021-05-02 17:26:01 -04:00
|
|
|
(setq rustic-indent-method-chain t)
|
|
|
|
|
2019-11-07 12:49:30 -05:00
|
|
|
(set-docsets! 'rustic-mode "Rust")
|
2020-02-27 21:55:12 -05:00
|
|
|
(set-popup-rule! "^\\*rustic-compilation" :vslot -1)
|
2019-11-07 12:49:30 -05:00
|
|
|
|
2021-05-02 17:26:01 -04:00
|
|
|
;; 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)
|
2020-03-08 17:30:50 -04:00
|
|
|
rustic-format-trigger nil)
|
2019-07-09 18:50:50 +02:00
|
|
|
|
2021-05-02 17:26:01 -04:00
|
|
|
;; 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))
|
2019-11-23 16:00:14 -05:00
|
|
|
|
2021-05-02 17:26:01 -04:00
|
|
|
;; 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.
|
2020-05-01 11:01:11 +02:00
|
|
|
(when (featurep! +lsp)
|
2021-05-02 17:26:01 -04:00
|
|
|
(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)))
|
2020-05-01 11:01:11 +02:00
|
|
|
|
2019-11-23 16:00:14 -05:00
|
|
|
(map! :map rustic-mode-map
|
|
|
|
:localleader
|
|
|
|
(:prefix ("b" . "build")
|
|
|
|
:desc "cargo audit" "a" #'+rust/cargo-audit
|
|
|
|
:desc "cargo build" "b" #'rustic-cargo-build
|
|
|
|
:desc "cargo bench" "B" #'rustic-cargo-bench
|
|
|
|
:desc "cargo check" "c" #'rustic-cargo-check
|
|
|
|
:desc "cargo clippy" "C" #'rustic-cargo-clippy
|
|
|
|
:desc "cargo doc" "d" #'rustic-cargo-doc
|
|
|
|
:desc "cargo fmt" "f" #'rustic-cargo-fmt
|
|
|
|
:desc "cargo new" "n" #'rustic-cargo-new
|
|
|
|
:desc "cargo outdated" "o" #'rustic-cargo-outdated
|
|
|
|
:desc "cargo run" "r" #'rustic-cargo-run)
|
|
|
|
(:prefix ("t" . "cargo test")
|
|
|
|
:desc "all" "a" #'rustic-cargo-test
|
2019-12-21 14:08:57 -05:00
|
|
|
:desc "current test" "t" #'rustic-cargo-current-test))
|
|
|
|
|
2020-01-28 20:37:51 -05:00
|
|
|
;; If lsp/elgot isn't available, it attempts to install lsp-mode via
|
2020-02-20 18:13:22 -05:00
|
|
|
;; package.el. Doom manages its own dependencies through straight so disable
|
|
|
|
;; this behavior to avoid package-not-initialized errors.
|
2020-02-20 18:19:59 -05:00
|
|
|
(defadvice! +rust--dont-install-packages-a (&rest _)
|
2020-01-28 20:37:51 -05:00
|
|
|
:override #'rustic-install-lsp-client-p
|
|
|
|
(message "No LSP server running")))
|
2019-11-07 12:49:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
(use-package! racer
|
|
|
|
:unless (featurep! +lsp)
|
2020-08-12 18:52:14 -04:00
|
|
|
:hook (rustic-mode-local-vars . racer-mode)
|
2019-12-02 16:34:11 -05:00
|
|
|
:init
|
2019-12-30 18:23:56 -05:00
|
|
|
;; HACK Fix #2132: `racer' depends on `rust-mode', which tries to modify
|
|
|
|
;; `auto-mode-alist'. We make extra sure that doesn't stick, especially
|
2020-05-18 16:50:10 -07:00
|
|
|
;; when a buffer is reverted, as it is after rustfmt is done with it.
|
2019-12-02 16:34:11 -05:00
|
|
|
(after! rust-mode
|
2019-12-03 20:41:17 -05:00
|
|
|
(setq auto-mode-alist (delete '("\\.rs\\'" . rust-mode) auto-mode-alist)))
|
2019-11-07 12:49:30 -05:00
|
|
|
:config
|
|
|
|
(set-lookup-handlers! 'rustic-mode
|
|
|
|
:definition '(racer-find-definition :async t)
|
|
|
|
:documentation '+rust-racer-lookup-documentation))
|