Locate rust-analyzer on the /home/talexander/.pyenv/shims:/opt/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin.

This commit is contained in:
Tom Alexander 2023-09-09 02:47:20 -04:00
parent d229447149
commit db5b400408
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 27 additions and 9 deletions

View File

@ -1,2 +1,3 @@
.idea
.python-version
.dir-locals.el

View File

@ -3,7 +3,7 @@
(defun locate-rust-analyzer ()
"Find rust-analyzer."
(let ((rust-analyzer-paths (list (locate-rust-analyzer-rustup) (locate-rust-analyzer-ansible-built))))
(let ((rust-analyzer-paths (list (locate-rust-analyzer-rustup) (locate-rust-analyzer-ansible-built) (locate-rust-analyzer-in-path))))
(let ((first-non-nil-path (seq-find (lambda (elt) elt) rust-analyzer-paths)))
first-non-nil-path
)
@ -24,6 +24,11 @@
)
)
(defun locate-rust-analyzer-in-path ()
"Find rust-analyzer in $PATH."
(executable-find "rust-analyzer")
)
(use-package rust-ts-mode
:pin manual
:mode (
@ -32,14 +37,14 @@
:commands (rust-ts-mode)
:hook (
(rust-ts-mode . (lambda ()
(eglot-ensure)
(let ((rust-analyzer-command (locate-rust-analyzer)))
(when rust-analyzer-command
(add-to-list 'eglot-server-programs (cons 'rust-ts-mode (list rust-analyzer-command)))
)
)
(add-hook 'before-save-hook 'eglot-format-buffer nil 'local)
))
(eglot-ensure)
(let ((rust-analyzer-command (locate-rust-analyzer)))
(when rust-analyzer-command
(add-to-list 'eglot-server-programs `(rust-ts-mode . (,rust-analyzer-command)))
)
)
(add-hook 'before-save-hook 'eglot-format-buffer nil 'local)
))
)
:init
(add-to-list 'major-mode-remap-alist '(rust-mode . rust-ts-mode))
@ -63,5 +68,17 @@
(unless (treesit-ready-p 'toml) (treesit-install-language-grammar 'toml))
)
;; Set additional rust-analyzer settings:
;;
;; (add-to-list 'eglot-server-programs `(rust-ts-mode . (,rust-analyzer-command :initializationOptions (:cargo (:features "all")))))
;;
;; In addition to the above, directory-specific settings can be written to a .dir-locals.el with the contents:
;;
;; (
;; (rust-ts-mode . ((eglot-workspace-configuration
;; . (:rust-analyzer (:cargo (:features "compare"))))
;; ))
;; )
(provide 'lang-rust)