52 lines
1.7 KiB
EmacsLisp
52 lines
1.7 KiB
EmacsLisp
(require 'common-lsp)
|
|
(require 'util-tree-sitter)
|
|
|
|
(defun locate-rust-analyzer ()
|
|
"Find rust-analyzer."
|
|
(let ((rust-analyzer-paths (list (locate-rust-analyzer-rustup) (locate-rust-analyzer-ansible-built))))
|
|
(let ((first-non-nill-path (seq-find (lambda (elt) elt) rust-analyzer-paths)))
|
|
first-non-nill-path
|
|
)
|
|
)
|
|
)
|
|
|
|
(defun locate-rust-analyzer-rustup ()
|
|
"Find rust-analyzer through rustup."
|
|
(run-command-in-directory nil "rustup" "which" "rust-analyzer")
|
|
)
|
|
|
|
(defun locate-rust-analyzer-ansible-built ()
|
|
"Find rust-analyzer where the ansible playbook built it."
|
|
(let ((rust-analyzer-path "/opt/rust-analyzer/target/release/rust-analyzer"))
|
|
(when (file-exists-p rust-analyzer-path)
|
|
rust-analyzer-path
|
|
)
|
|
)
|
|
)
|
|
|
|
(use-package rust-mode
|
|
:pin nongnu
|
|
:mode "\\.rs\\'"
|
|
: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)
|
|
))
|
|
)
|
|
:init
|
|
(add-to-list 'major-mode-remap-alist '(rust-mode . rust-ts-mode))
|
|
(add-to-list 'treesit-language-source-alist '(rust "https://github.com/tree-sitter/tree-sitter-rust"))
|
|
(unless (treesit-ready-p 'yaml) (treesit-install-language-grammar 'rust))
|
|
:config
|
|
;; Add keybindings for interacting with Cargo
|
|
(use-package cargo
|
|
:hook (rust-ts-mode . cargo-minor-mode))
|
|
)
|
|
|
|
(provide 'lang-rust)
|