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`.
|
* Replace `yank-pop` key-binding to `counse-yank-pop` for `ivy-mode`.
|
||||||
* The keybinding for `proced` is now enabled unconditionally.
|
* The keybinding for `proced` is now enabled unconditionally.
|
||||||
* Replace prelude-go backend with `lsp` instead of unmaintained tools
|
* 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
|
### Bugs fixed
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,7 @@ following packages in your system:
|
||||||
* `rustc` (Rust compiler)
|
* `rustc` (Rust compiler)
|
||||||
* `cargo` (Rust package manager)
|
* `cargo` (Rust package manager)
|
||||||
* `rustfmt` (Rust tool for formatting code)
|
* `rustfmt` (Rust tool for formatting code)
|
||||||
* `racer` (Rust completion tool, not necessary if `prelude-lsp` is enabled)
|
* `rust-analyzer` (Rust Language Server, required for `prelude-lsp` feature)
|
||||||
* `rls` (Rust Language Server, if the `prelude-lsp` feature is enabled)
|
|
||||||
|
|
||||||
## Rust Mode
|
## 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
|
`rust-mode`. Whenever you are editing Rust code run <kbd>C-h m</kbd> to
|
||||||
look at the Rust mode key bindings.
|
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
|
## Syntax checking
|
||||||
|
|
||||||
Prelude ships with [Flycheck](https://github.com/flycheck/flycheck),
|
Prelude ships with [Flycheck](https://github.com/flycheck/flycheck),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
;;; prelude-rust.el --- Emacs Prelude: Rust programming support.
|
;;; 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.
|
;; This file is not part of GNU Emacs.
|
||||||
|
|
||||||
|
@ -32,37 +32,49 @@
|
||||||
;; You may need to install the following packages on your system:
|
;; You may need to install the following packages on your system:
|
||||||
;; * rustc (Rust Compiler)
|
;; * rustc (Rust Compiler)
|
||||||
;; * cargo (Rust Package Manager)
|
;; * cargo (Rust Package Manager)
|
||||||
;; * racer (Rust Completion Tool)
|
|
||||||
;; * rustfmt (Rust Tool for formatting code)
|
;; * 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
|
(prelude-require-packages '(rust-mode
|
||||||
cargo
|
cargo
|
||||||
flycheck-rust
|
flycheck-rust
|
||||||
|
tree-sitter
|
||||||
|
tree-sitter-langs
|
||||||
|
yasnippet
|
||||||
ron-mode))
|
ron-mode))
|
||||||
|
|
||||||
(unless (featurep 'prelude-lsp)
|
(require 'tree-sitter)
|
||||||
(prelude-require-packages '(racer)))
|
(require 'tree-sitter-langs)
|
||||||
|
|
||||||
(setq rust-format-on-save t)
|
|
||||||
|
|
||||||
(with-eval-after-load 'rust-mode
|
(with-eval-after-load 'rust-mode
|
||||||
(add-hook 'rust-mode-hook 'cargo-minor-mode)
|
(add-hook 'rust-mode-hook 'cargo-minor-mode)
|
||||||
(add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
|
(add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
|
||||||
|
|
||||||
(if (featurep 'prelude-lsp)
|
;; enable lsp for rust, by default it uses rust-analyzer as lsp server
|
||||||
(add-hook 'rust-mode-hook 'lsp)
|
(add-hook 'rust-mode-hook 'lsp)
|
||||||
(add-hook 'rust-mode-hook 'racer-mode)
|
|
||||||
(add-hook 'racer-mode-hook 'eldoc-mode))
|
;; 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 ()
|
(defun prelude-rust-mode-defaults ()
|
||||||
(unless (featurep 'prelude-lsp)
|
;; format on save
|
||||||
(local-set-key (kbd "C-c C-d") 'racer-describe)
|
(setq rust-format-on-save t)
|
||||||
(local-set-key (kbd "C-c .") 'racer-find-definition)
|
|
||||||
(local-set-key (kbd "C-c ,") 'pop-tag-mark))
|
;; 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
|
;; Prevent #! from chmodding rust files to be executable
|
||||||
(remove-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
|
(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
|
;; CamelCase aware editing operations
|
||||||
(subword-mode +1))
|
(subword-mode +1))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue