[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 0985f5f 318/486: Merge pull request #217 from Aa
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 0985f5f 318/486: Merge pull request #217 from Aankhen/add-clippy-command |
Date: |
Sat, 7 Aug 2021 09:25:44 -0400 (EDT) |
branch: elpa/rust-mode
commit 0985f5fde747f64b3fcff2661226aa4dad286e04
Merge: 60a1f36 128601b
Author: Tom Tromey <tom@tromey.com>
Commit: GitHub <noreply@github.com>
Merge pull request #217 from Aankhen/add-clippy-command
Add `rust-run-clippy' and `rust-buffer-project' with testing paraphernalia
---
rust-mode-tests.el | 7 +++++++
rust-mode.el | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
test-project/Cargo.toml | 1 +
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 6d58906..b1d51c9 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -2650,6 +2650,13 @@ extern \"rust-intrinsic\" fn five() {
"four"
"five"))))
+(when (executable-find rust-cargo-bin)
+ (ert-deftest rust-test-project-located ()
+ (lexical-let* ((test-dir (expand-file-name "test-project"
default-directory))
+ (manifest-file (expand-file-name "Cargo.toml" test-dir)))
+ (let ((default-directory test-dir))
+ (should (equal (expand-file-name (rust-buffer-project))
manifest-file))))))
+
;; If electric-pair-mode is available, load it and run the tests that use it.
If not,
;; no error--the tests will be skipped.
(require 'elec-pair nil t)
diff --git a/rust-mode.el b/rust-mode.el
index f3f799c..2c58545 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -18,9 +18,14 @@
(require 'compile)
(require 'url-vars))
+(require 'json)
+
(defvar electric-pair-inhibit-predicate)
(defvar electric-indent-chars)
+(defvar rust-buffer-project)
+(make-variable-buffer-local 'rust-buffer-project)
+
;; for GNU Emacs < 24.3
(eval-when-compile
(unless (fboundp 'setq-local)
@@ -144,6 +149,17 @@ function or trait. When nil, where will be aligned with
fn or trait."
:type 'string
:group 'rust-mode)
+(defcustom rust-cargo-bin "cargo"
+ "Path to cargo executable."
+ :type 'string
+ :group 'rust-mode)
+
+(defcustom rust-always-locate-project-on-open nil
+ "Whether to run `cargo locate-project' every time `rust-mode'
+ is activated."
+ :type 'boolean
+ :group 'rust-mode)
+
(defface rust-unsafe-face
'((t :inherit font-lock-warning-face))
"Face for the `unsafe' keyword."
@@ -1411,7 +1427,12 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(setq-local compile-command "cargo build")
- (add-hook 'before-save-hook 'rust--before-save-hook nil t))
+ (add-hook 'before-save-hook 'rust--before-save-hook nil t)
+
+ (setq-local rust-buffer-project nil)
+
+ (when rust-always-locate-project-on-open
+ (rust-update-buffer-project)))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
@@ -1548,6 +1569,30 @@ visit the new file."
(rename-file filename new-name 1)
(set-visited-file-name new-name))))))
+(defun rust-run-clippy ()
+ "Run `cargo clippy'."
+ (interactive)
+ (when (null rust-buffer-project)
+ (rust-update-buffer-project))
+ (let* ((args (list rust-cargo-bin "clippy" (concat "--manifest-path="
rust-buffer-project)))
+ ;; set `compile-command' temporarily so `compile' doesn't
+ ;; clobber the existing value
+ (compile-command (mapconcat #'shell-quote-argument args " ")))
+ (compile compile-command)))
+
+(defun rust-update-buffer-project ()
+ (setq-local rust-buffer-project (rust-buffer-project)))
+
+(defun rust-buffer-project ()
+ "Get project root if possible."
+ (with-temp-buffer
+ (let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
+ (when (/= ret 0)
+ (error "`cargo locate-project' returned %s status: %s" ret
(buffer-string)))
+ (goto-char 0)
+ (let ((output (json-read)))
+ (cdr (assoc-string "root" output))))))
+
(provide 'rust-mode)
;;; rust-mode.el ends here
diff --git a/test-project/Cargo.toml b/test-project/Cargo.toml
new file mode 100644
index 0000000..f741b14
--- /dev/null
+++ b/test-project/Cargo.toml
@@ -0,0 +1 @@
+# Dummy file needed for test
- [nongnu] elpa/rust-mode 4d651ab 295/486: Merge pull request #197 from tromey/syntax-propertize, (continued)
- [nongnu] elpa/rust-mode 4d651ab 295/486: Merge pull request #197 from tromey/syntax-propertize, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 85befb9 296/486: Merge pull request #201 from tromey/question-indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5469d9b 297/486: fix rust indentation bug, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 367a89c 299/486: Allow formatting with long lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 610fe1f 305/486: Address review comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 72c479b 311/486: Add `rust-run-clippy' and `rust-buffer-project' with testing paraphernalia., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4ec735e 300/486: Add stderr output from rustfmt on exit code 3, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9afe997 313/486: Declare `rust-buffer-project' and require `json' at runtime., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b4077f8 314/486: Add `rust-cargo-bin' custom variable., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d2bb17c 315/486: Skip `rust-test-project-located' without cargo and avoid `find-file' in test., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0985f5f 318/486: Merge pull request #217 from Aankhen/add-clippy-command,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 34cc528 319/486: Highlight question mark operator using new `rust-question-mark-face'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2a9fcd0 321/486: Add syntax highlighting and imenu support for `union`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 89320ad 323/486: Highlight interpolation in arguments to print! &c., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e48a650 329/486: Merge pull request #225 from Aankhen/add-var-colours, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6e9db46 331/486: Merge pull request #230 from tromey/fix-indentation-bug, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0e832ec 340/486: Remove `float`, `int`, and `uint` as built-in types., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 302b537 344/486: Revert #216 and Add Suggestions from #226, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b8e4908 345/486: Merge pull request #243 from iwillspeak/rust-compile-command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6bcb82b 350/486: Merge pull request #249 from brotzeit/rust--format-call, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 705f3e4 352/486: Improved font-locking for print macros, ELPA Syncer, 2021/08/07