Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot setup LSP formatting and treesitter together #516

Closed
lerouxrgd opened this issue Feb 25, 2024 · 5 comments · Fixed by #519
Closed

Cannot setup LSP formatting and treesitter together #516

lerouxrgd opened this issue Feb 25, 2024 · 5 comments · Fixed by #519

Comments

@lerouxrgd
Copy link

lerouxrgd commented Feb 25, 2024

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
Copy link
Contributor

ccqpein commented Feb 26, 2024

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
Copy link
Member

psibi commented Feb 26, 2024

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

You're right. Does this PR make it work: #517 ?

@ccqpein
Copy link
Contributor

ccqpein commented Feb 26, 2024

@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
Copy link
Member

psibi commented Feb 26, 2024

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

@ccqpein
Copy link
Contributor

ccqpein commented Feb 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants