54 lines
1.7 KiB
EmacsLisp
54 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
|
|
)
|
|
)
|
|
)
|
|
|
|
(add-to-list 'major-mode-remap-alist '(rust-mode . rust-ts-mode))
|
|
|
|
(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)))
|
|
)
|
|
)
|
|
(when-linux
|
|
(tree-sitter-hl-mode +1)
|
|
)
|
|
(add-hook 'before-save-hook 'eglot-format-buffer nil 'local)
|
|
))
|
|
)
|
|
:config
|
|
(treesit-install-language-grammar 'rust)
|
|
;; Add keybindings for interacting with Cargo
|
|
(use-package cargo
|
|
:hook (rust-ts-mode . cargo-minor-mode))
|
|
)
|
|
|
|
(provide 'lang-rust)
|