rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 176 forks source link

Cannot setup LSP formatting and treesitter together #516

Closed lerouxrgd closed 4 months ago

lerouxrgd commented 4 months ago

Hello,

Here is my current config:

(use-package rust-mode
  :hook (rust-mode . lsp-deferred)
  :init
  (setq rust-mode-treesitter-derive t)
  :config
  (setq rust-format-on-save t
        rust-after-save-method 'lsp-format-buffer))

Then in rust-mode (when editing a Rust file), the format on save is not happening.

Strangely, it says:

run-hooks: Symbol’s function definition is void: rust-after-save-method

I keep having the same message if I try too change what is in the :init and :config statements.

ccqpein commented 4 months ago

I have the same issue and I even don't config the rust-format-on-save. I found the rust-after-save-hook is rust-after-save-method. Looks like #515 move rust-after-save-hook to rust-common.el, and the rust-after-save-method actually in rust-rustfmt.el.

Does rust-common.el forgot import the rust-format?

psibi commented 4 months ago

Does rust-common.el forgot import the rust-format?

You're right. Does this PR make it work: https://github.com/rust-lang/rust-mode/pull/517 ?

ccqpein commented 4 months ago

@psibi Unfortunately, it doesn't, I try add rust-rustfmt in rust-common and it fixed on my side.

modified   rust-common.el
@@ -4,6 +4,8 @@
 ;; rust-common code for both prog-mode and tree-sitter one

 ;;; Code:
+(require 'rust-rustfmt)
+
 (defcustom rust-before-save-hook 'rust-before-save-method
   "Function for formatting before save."
   :type 'function
psibi commented 4 months ago

@ccqpein Cool, want to send a PR with your changes ?

ccqpein commented 4 months ago

I just gave the PR #519 . cc @lerouxrgd does the PR fix the issue on your side too?