Update rust module (#1388)
Use rust-analyzer as lsp server and tree-sitter for syntax highlighting.
This commit is contained in:
parent
1727734002
commit
54e3d81b1f
3 changed files with 34 additions and 17 deletions
|
@ -20,6 +20,7 @@
|
|||
* Replace `yank-pop` key-binding to `counse-yank-pop` for `ivy-mode`.
|
||||
* The keybinding for `proced` is now enabled unconditionally.
|
||||
* Replace prelude-go backend with `lsp` instead of unmaintained tools
|
||||
* Use `rust-analyzer` as language server for prelude-rust and provide nicer syntax highlighting with `tree-sitter`
|
||||
|
||||
### Bugs fixed
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@ following packages in your system:
|
|||
* `rustc` (Rust compiler)
|
||||
* `cargo` (Rust package manager)
|
||||
* `rustfmt` (Rust tool for formatting code)
|
||||
* `racer` (Rust completion tool, not necessary if `prelude-lsp` is enabled)
|
||||
* `rls` (Rust Language Server, if the `prelude-lsp` feature is enabled)
|
||||
* `rust-analyzer` (Rust Language Server, required for `prelude-lsp` feature)
|
||||
|
||||
## Rust Mode
|
||||
|
||||
|
@ -21,6 +20,11 @@ Emacs comes with Rust programming support through the built-in
|
|||
`rust-mode`. Whenever you are editing Rust code run <kbd>C-h m</kbd> to
|
||||
look at the Rust mode key bindings.
|
||||
|
||||
## Syntax highlighting
|
||||
|
||||
[tree-sitter-mode](https://emacs-tree-sitter.github.io/) is used for nicer
|
||||
syntax highlighting.
|
||||
|
||||
## Syntax checking
|
||||
|
||||
Prelude ships with [Flycheck](https://github.com/flycheck/flycheck),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; prelude-rust.el --- Emacs Prelude: Rust programming support.
|
||||
;;
|
||||
;; Authors: Doug MacEachern, Manoel Vilela, Ben Alex
|
||||
;; Authors: Doug MacEachern, Manoel Vilela, Ben Alex, Daniel Gerlach
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
|
@ -32,37 +32,49 @@
|
|||
;; You may need to install the following packages on your system:
|
||||
;; * rustc (Rust Compiler)
|
||||
;; * cargo (Rust Package Manager)
|
||||
;; * racer (Rust Completion Tool)
|
||||
;; * rustfmt (Rust Tool for formatting code)
|
||||
;; * rls (Rust Language Server, if the prelude-lsp feature is enabled)
|
||||
;; * rust-analyzer as lsp server needs to be in global path, see:
|
||||
;; https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary
|
||||
|
||||
|
||||
(prelude-require-packages '(rust-mode
|
||||
cargo
|
||||
flycheck-rust
|
||||
tree-sitter
|
||||
tree-sitter-langs
|
||||
yasnippet
|
||||
ron-mode))
|
||||
|
||||
(unless (featurep 'prelude-lsp)
|
||||
(prelude-require-packages '(racer)))
|
||||
|
||||
(setq rust-format-on-save t)
|
||||
(require 'tree-sitter)
|
||||
(require 'tree-sitter-langs)
|
||||
|
||||
(with-eval-after-load 'rust-mode
|
||||
(add-hook 'rust-mode-hook 'cargo-minor-mode)
|
||||
(add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
|
||||
|
||||
(if (featurep 'prelude-lsp)
|
||||
(add-hook 'rust-mode-hook 'lsp)
|
||||
(add-hook 'rust-mode-hook 'racer-mode)
|
||||
(add-hook 'racer-mode-hook 'eldoc-mode))
|
||||
;; enable lsp for rust, by default it uses rust-analyzer as lsp server
|
||||
(add-hook 'rust-mode-hook 'lsp)
|
||||
|
||||
;; enable tree-sitter for nicer syntax highlighting
|
||||
(add-hook 'rust-mode-hook #'tree-sitter-mode)
|
||||
(add-hook 'rust-mode-hook #'tree-sitter-hl-mode)
|
||||
|
||||
(defun prelude-rust-mode-defaults ()
|
||||
(unless (featurep 'prelude-lsp)
|
||||
(local-set-key (kbd "C-c C-d") 'racer-describe)
|
||||
(local-set-key (kbd "C-c .") 'racer-find-definition)
|
||||
(local-set-key (kbd "C-c ,") 'pop-tag-mark))
|
||||
;; format on save
|
||||
(setq rust-format-on-save t)
|
||||
|
||||
;; lsp settings
|
||||
(setq
|
||||
;; enable macro expansion
|
||||
lsp-rust-analyzer-proc-macro-enable t
|
||||
lsp-rust-analyzer-experimental-proc-attr-macros t)
|
||||
|
||||
;; Prevent #! from chmodding rust files to be executable
|
||||
(remove-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
|
||||
|
||||
;; snippets are required for correct lsp autocompletions
|
||||
(yas-minor-mode)
|
||||
|
||||
;; CamelCase aware editing operations
|
||||
(subword-mode +1))
|
||||
|
||||
|
|
Loading…
Reference in a new issue