mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-23 03:20:26 +10:00
Moving to Doom Emacs!
This commit is contained in:
83
.emacs.d/modules/lang/rust/README.org
Normal file
83
.emacs.d/modules/lang/rust/README.org
Normal file
@@ -0,0 +1,83 @@
|
||||
#+TITLE: lang/rust
|
||||
#+DATE: June 5, 2019
|
||||
#+SINCE: v3.0.0
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#hacks][Hacks]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#features][Features]]
|
||||
- [[#keybinds][Keybinds]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#enable-rust-analyzer][Enable rust-analyzer]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
|
||||
* Description
|
||||
This module adds support for the Rust language and integration for its tools,
|
||||
e.g. ~cargo~.
|
||||
|
||||
+ Code completion (~racer~)
|
||||
+ Syntax checking (~flycheck~)
|
||||
+ LSP support (for rls and rust-analyzer) (~rustic~)
|
||||
+ Snippets
|
||||
|
||||
** Module Flags
|
||||
+ ~+lsp~ to add support Language server protocol.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/brotzeit/rustic][rustic]]
|
||||
+ [[https://github.com/racer-rust/emacs-racer][racer]]* (unless =+lsp=)
|
||||
|
||||
** Hacks
|
||||
+ rustic has been modified /not/ to automatically install lsp-mode or elgot if
|
||||
they're missing. Doom expects you to enable the =:tools lsp= module yourself.
|
||||
+ rustic's LSP integration has been disabled in favor of the rls/rust-analyzer
|
||||
support provider by the lsp-mode package.
|
||||
|
||||
* Prerequisites
|
||||
This module only requires ~rust~, which can be acquired through =rustup=:
|
||||
|
||||
~curl https://sh.rustup.rs -sSf | sh~
|
||||
|
||||
Optionally, this module also uses the following programs:
|
||||
|
||||
+ =racer= (if not using LSP): ~cargo +nightly install racer~ (requires rust nightly)
|
||||
+ =RLS= or =rust-analyzer= (for LSP users)
|
||||
+ =rustfmt= for ~:editor format~: ~rustup component add rustfmt-preview~
|
||||
+ The following commands require:
|
||||
+ ~cargo-process-check~: ~cargo install cargo-check~
|
||||
+ ~cargo-process-clippy~: ~rustup component add clippy-preview~
|
||||
|
||||
* Features
|
||||
This module also supports LSP, if you have [[https://github.com/rust-lang/rls][the Rust Language Server]] or
|
||||
[[https://github.com/rust-analyzer/rust-analyzer][rust-analyzer]] installed. To enable it, you must enable the =:tools lsp= module
|
||||
and the ~+lsp~ flag on this module.
|
||||
|
||||
** Keybinds
|
||||
| Binding | Description |
|
||||
|---------------------+-----------------------------|
|
||||
| ~<localleader> b a~ | ~cargo audit~ |
|
||||
| ~<localleader> b b~ | ~cargo build~ |
|
||||
| ~<localleader> b B~ | ~cargo bench~ |
|
||||
| ~<localleader> b c~ | ~cargo check~ |
|
||||
| ~<localleader> b C~ | ~cargo clippy~ |
|
||||
| ~<localleader> b d~ | ~cargo doc~ |
|
||||
| ~<localleader> b n~ | ~cargo update~ |
|
||||
| ~<localleader> b o~ | ~cargo outdated~ |
|
||||
| ~<localleader> b r~ | ~cargo run~ |
|
||||
| ~<localleader> t a~ | ~cargo test~ |
|
||||
| ~<localleader> t t~ | ~run current test~ |
|
||||
|
||||
* TODO Configuration
|
||||
** Enable rust-analyzer
|
||||
You'll need [[https://github.com/rust-analyzer/rust-analyzer][rust-analyzer]] installed on your system, then add the following to
|
||||
=$DOOMDIR/config.el=:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(setq lsp-rust-server 'rust-analyzer)
|
||||
#+END_SRC
|
||||
|
||||
* TODO Troubleshooting
|
||||
26
.emacs.d/modules/lang/rust/autoload.el
Normal file
26
.emacs.d/modules/lang/rust/autoload.el
Normal file
@@ -0,0 +1,26 @@
|
||||
;;; lang/rust/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; TODO (defun +rust/run-cargo () (interactive))
|
||||
|
||||
;;;###autoload
|
||||
(defun +rust-cargo-project-p ()
|
||||
"Return t if this is a cargo project."
|
||||
(locate-dominating-file buffer-file-name "Cargo.toml"))
|
||||
|
||||
;;;###autoload
|
||||
(defun +rust-racer-lookup-documentation (identifier)
|
||||
"A `+lookup/documentation' handler for Rust + Racer."
|
||||
(let ((buf (racer--describe identifier)))
|
||||
(when buf
|
||||
(pop-to-buffer buf)
|
||||
t)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Custom Cargo commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +rust/cargo-audit ()
|
||||
"Run 'cargo audit' for the current project."
|
||||
(interactive)
|
||||
(rustic-run-cargo-command "cargo audit -f"))
|
||||
64
.emacs.d/modules/lang/rust/config.el
Normal file
64
.emacs.d/modules/lang/rust/config.el
Normal file
@@ -0,0 +1,64 @@
|
||||
;;; lang/rust/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(after! projectile
|
||||
(add-to-list 'projectile-project-root-files "Cargo.toml"))
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! rustic
|
||||
:mode ("\\.rs$" . rustic-mode)
|
||||
:commands rustic-run-cargo-command rustic-cargo-outdated
|
||||
:config
|
||||
(set-docsets! 'rustic-mode "Rust")
|
||||
|
||||
(setq rustic-indent-method-chain t
|
||||
rustic-flycheck-setup-mode-line-p nil
|
||||
;; use :editor format instead
|
||||
rustic-format-trigger nil
|
||||
;; REVIEW `rust-ordinary-lt-gt-p' is terribly expensive in large rust
|
||||
;; buffers, so we disable it, but only for evil users, because it
|
||||
;; affects `forward-sexp' and its ilk. See
|
||||
;; https://github.com/rust-lang/rust-mode/issues/288.
|
||||
rustic-match-angle-brackets (not (featurep! :editor evil))
|
||||
;; We use the superior default client provided by `lsp-mode', not the
|
||||
;; one rustic-mode sets up for us.
|
||||
rustic-lsp-client nil)
|
||||
|
||||
(add-hook 'rustic-mode-hook #'rainbow-delimiters-mode)
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(add-hook 'rustic-mode-local-vars-hook #'lsp!))
|
||||
|
||||
(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
|
||||
:desc "current test" "t" #'rustic-cargo-current-test)))
|
||||
|
||||
|
||||
(use-package! racer
|
||||
:unless (featurep! +lsp)
|
||||
:hook (rustic-mode . racer-mode)
|
||||
:init
|
||||
;; Fix #2132: `racer' depends on `rust-mode', which tries to modify
|
||||
;; `auto-mode-alist'. We make extra sure that doesn't stick, especially when a
|
||||
;; buffer is reverted, as it is after rustfmt is done wiht it.
|
||||
(after! rust-mode
|
||||
(setq auto-mode-alist (delete '("\\.rs\\'" . rust-mode) auto-mode-alist)))
|
||||
:config
|
||||
(set-lookup-handlers! 'rustic-mode
|
||||
:definition '(racer-find-definition :async t)
|
||||
:documentation '+rust-racer-lookup-documentation))
|
||||
31
.emacs.d/modules/lang/rust/doctor.el
Normal file
31
.emacs.d/modules/lang/rust/doctor.el
Normal file
@@ -0,0 +1,31 @@
|
||||
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||
;;; lang/rust/doctor.el
|
||||
|
||||
(assert! (or (not (featurep! +lsp))
|
||||
(featurep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(unless (executable-find "rustc")
|
||||
(warn! "Couldn't find rustc binary"))
|
||||
|
||||
(unless (executable-find "cargo")
|
||||
(warn! "Couldn't find cargo binary"))
|
||||
|
||||
(if (featurep! +lsp)
|
||||
(let ((lsp-server 'rls))
|
||||
(when (require 'rustic nil t)
|
||||
(setq lsp-server rustic-lsp-server))
|
||||
(pcase lsp-server
|
||||
(`rust-analyzer
|
||||
(unless (executable-find "ra_lsp_server")
|
||||
(warn! "Couldn't find rust analyzer (ra_lsp_server)")))
|
||||
(`rls
|
||||
(unless (executable-find "rls")
|
||||
(warn! "Couldn't find rls")))))
|
||||
(when (require 'racer nil t)
|
||||
;; racer
|
||||
(unless (file-exists-p racer-cmd)
|
||||
(warn! "Couldn't find the racer binary at `racer-cmd'"))
|
||||
;; rust source code (rustup component add rust-src)
|
||||
(unless (file-directory-p racer-rust-src-path)
|
||||
(warn! "Couldn't find Rust's source code at RUST_SRC_PATH or `racer-rust-src-path'"))))
|
||||
6
.emacs.d/modules/lang/rust/packages.el
Normal file
6
.emacs.d/modules/lang/rust/packages.el
Normal file
@@ -0,0 +1,6 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/rust/packages.el
|
||||
|
||||
(package! rustic)
|
||||
(unless (featurep! +lsp)
|
||||
(package! racer))
|
||||
Reference in New Issue
Block a user