Merge pull request #1537 from chrunchyjesus/cargo-mode
lang/rust: add cargo package & keybinds
This commit is contained in:
commit
d39500f143
4 changed files with 43 additions and 19 deletions
|
@ -27,6 +27,7 @@ Add support to Rust language and cargo commands inside emacs.
|
||||||
** Plugins
|
** Plugins
|
||||||
+ [[https://github.com/rust-lang/rust-mode][Rust-mode]]
|
+ [[https://github.com/rust-lang/rust-mode][Rust-mode]]
|
||||||
+ [[https://github.com/racer-rust/emacs-racer][Racer-mode]]
|
+ [[https://github.com/racer-rust/emacs-racer][Racer-mode]]
|
||||||
|
+ [[https://github.com/racer-rust/emacs-racer][Cargo-mode]]
|
||||||
|
|
||||||
** Hacks
|
** Hacks
|
||||||
{A list of internal modifications to included packages}
|
{A list of internal modifications to included packages}
|
||||||
|
@ -39,18 +40,34 @@ To get started with Rust, you can either use =rustup= and install rust with:
|
||||||
Package manager is not recommended to install Nightly version of Rust what is
|
Package manager is not recommended to install Nightly version of Rust what is
|
||||||
required for ~racer~ from [[https://github.com/racer-rust/racer#installation][version 2.1]] (more info in [[#Troubleshooting][Troubleshooting]])
|
required for ~racer~ from [[https://github.com/racer-rust/racer#installation][version 2.1]] (more info in [[#Troubleshooting][Troubleshooting]])
|
||||||
|
|
||||||
|
Some commands require additional crates to be installed to work, e.g. ~cargo
|
||||||
|
add~.
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
rustup component add rustfmt
|
||||||
|
rustup component add cargo-check
|
||||||
|
rustup component add cargo-edit
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
* Features
|
* Features
|
||||||
This module also supports LSP, it requires installation of Rust Language Server
|
This module also supports LSP, it requires installation of Rust Language Server
|
||||||
[[https://github.com/rust-lang/rls][~RLS~]]. To enable this you need to enable ~lsp~ in ~:tools~ section in ~init.el~ file.
|
[[https://github.com/rust-lang/rls][~RLS~]]. To enable this you need to enable ~lsp~ in ~:tools~ section in ~init.el~ file.
|
||||||
|
|
||||||
Keybindings
|
Keybindings
|
||||||
|
|
||||||
| Binding | Description |
|
| Binding | Description |
|
||||||
|---------------------+---------------|
|
|---------------------+-----------------------------|
|
||||||
| ~<localleader> b b~ | ~cargo build~ |
|
| ~<localleader> b a~ | ~cargo add~ |
|
||||||
| ~<localleader> b c~ | ~cargo check~ |
|
| ~<localleader> b b~ | ~cargo build~ |
|
||||||
| ~<localleader> b r~ | ~cargo run~ |
|
| ~<localleader> b B~ | ~cargo bench~ |
|
||||||
| ~<localleader> b t~ | ~cargo test~ |
|
| ~<localleader> b c~ | ~cargo check~ |
|
||||||
|
| ~<localleader> b C~ | ~cargo clippy~ |
|
||||||
|
| ~<localleader> b d~ | ~cargo doc~ |
|
||||||
|
| ~<localleader> b r~ | ~cargo run~ |
|
||||||
|
| ~<localleader> b s~ | ~cargo search~ |
|
||||||
|
| ~<localleader> b u~ | ~cargo update~ |
|
||||||
|
| ~<localleader> t a~ | ~cargo test~ |
|
||||||
|
| ~<localleader> t f~ | ~run tests in current file~ |
|
||||||
|
| ~<localleader> t t~ | ~run current test~ |
|
||||||
|
|
||||||
* TODO Configuration
|
* TODO Configuration
|
||||||
How to configure this module, including common problems and how to address them.
|
How to configure this module, including common problems and how to address them.
|
||||||
|
|
|
@ -7,12 +7,6 @@
|
||||||
"Return t if this is a cargo project."
|
"Return t if this is a cargo project."
|
||||||
(locate-dominating-file buffer-file-name "Cargo.toml"))
|
(locate-dominating-file buffer-file-name "Cargo.toml"))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +rust-cargo-compile (command)
|
|
||||||
"TODO"
|
|
||||||
(let ((default-directory (+rust-cargo-project-p)))
|
|
||||||
(compile command)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +rust-racer-lookup-documentation (identifier)
|
(defun +rust-racer-lookup-documentation (identifier)
|
||||||
"A `+lookup/documentation' handler for Rust + Racer."
|
"A `+lookup/documentation' handler for Rust + Racer."
|
||||||
|
|
|
@ -7,13 +7,25 @@
|
||||||
(when (featurep! +lsp)
|
(when (featurep! +lsp)
|
||||||
(add-hook 'rust-mode-hook #'lsp!))
|
(add-hook 'rust-mode-hook #'lsp!))
|
||||||
|
|
||||||
(map! :map rust-mode-map
|
(def-package! cargo
|
||||||
:localleader
|
:defer t
|
||||||
:prefix "b"
|
:init
|
||||||
:desc "cargo build" "b" (λ! (+rust-cargo-compile "cargo build --color always"))
|
(map! :map rust-mode-map
|
||||||
:desc "cargo check" "c" (λ! (+rust-cargo-compile "cargo check --color always"))
|
:localleader
|
||||||
:desc "cargo run" "r" (λ! (+rust-cargo-compile "cargo run --color always"))
|
(:prefix "b"
|
||||||
:desc "cargo test" "t" (λ! (+rust-cargo-compile "cargo test --color always"))))
|
:desc "cargo add" "a" #'cargo-process-add
|
||||||
|
:desc "cargo build" "b" #'cargo-process-build
|
||||||
|
:desc "cargo bench" "B" #'cargo-process-bench
|
||||||
|
:desc "cargo check" "c" #'cargo-process-check
|
||||||
|
:desc "cargo clippy" "C" #'cargo-process-clippy
|
||||||
|
:desc "cargo doc" "d" #'cargo-process-doc
|
||||||
|
:desc "cargo run" "r" #'cargo-process-run
|
||||||
|
:desc "cargo search" "s" #'cargo-process-search
|
||||||
|
:desc "cargo update" "u" #'cargo-process-update)
|
||||||
|
(:prefix ("t" . "cargo test")
|
||||||
|
:desc "all" "a" #'cargo-process-test
|
||||||
|
:desc "current file" "f" #'cargo-process-current-file-tests
|
||||||
|
:desc "current test" "t" #'cargo-process-current-test))))
|
||||||
|
|
||||||
|
|
||||||
(def-package! racer
|
(def-package! racer
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
;;; lang/rust/packages.el
|
;;; lang/rust/packages.el
|
||||||
|
|
||||||
(package! rust-mode)
|
(package! rust-mode)
|
||||||
|
(package! cargo)
|
||||||
|
|
||||||
(when (featurep! :tools flycheck)
|
(when (featurep! :tools flycheck)
|
||||||
(package! flycheck-rust))
|
(package! flycheck-rust))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue