manateelazycat / lsp-bridge

A blazingly fast LSP client for Emacs
GNU General Public License v3.0
1.46k stars 214 forks source link

lsp-bridge-code-format doesn't work with before-save-hook #1073

Closed bluzky closed 1 month ago

bluzky commented 1 month ago

Hi I've just add a hook to format code on save but it doesn't work. But when I run M-x lsp-bridge-code-format, it does format the current buffer. Do I miss anything?

Here is my config

(use-package
  elixir-ts-mode
  :mode ("\\.ex\\'" "\\.exs\\'" "\\.eex\\'")
  :hook
  (before-save . lsp-bridge-code-format)
  :config
  (add-to-list 'treesit-language-source-alist '(elixir "https://github.com/elixir-lang/tree-sitter-elixir" "master" "src"))
  )

Thanks

manateelazycat commented 1 month ago

I don't use use-package, can't help you

bluzky commented 1 month ago

I add hook manually but it still didn't work

(add-hook 'before-save-hook (lambda()
                              (message "before-save-hook")
                                (lsp-bridge-code-format)
                              (message "before-save-hook done")
                              ))

Could you please give me an example of config that work with before-save-hook?

Thanks

manateelazycat commented 1 month ago

why not use my auto-save plugin?

bluzky commented 1 month ago

I've tried auto-save plugin but the code was not formatted. I found a strange behavior, some code changes trigger format code, some change doesn't trigger. Here is my recording

https://github.com/user-attachments/assets/92b02661-2350-4a03-aba4-3253e9aedc25

Uploading REC-20241013225610.mp4…

bluzky commented 1 month ago

auto format code with idle = 3 seconds is enough for me. So I'll close this issue. Thank you