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

Add lsp-organize-imports to before-save-hook always affect other buffers or modes. #4621

Open
3 tasks done
oodzchen opened this issue Nov 25, 2024 · 0 comments
Open
3 tasks done
Labels

Comments

@oodzchen
Copy link

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

I'm using doomemacs to write my golang project, which contains some typescript (tsx) code. I've configured the before-save-hook to automatic organize go package imports, the config is

(add-hook! 'go-mode-hook
  (add-hook 'before-save-hook #'lsp-organize-imports :local))

But every time when I open a tsx file after open the go files, the lsp-organize-imports always run on the typescript-tsx-mode, which makes the save process really slow, because I've already use prettierjs to format the tsx code, no need for the lsp formatting. And if I open the tsx file first without open go files, everything works fine, there's no lsp formatting for tsx code.

I've tried disable lsp-format globally with (setq +format-with-lsp nil), it's not working. Also tried remove the hook in typescript-tsx-mode with

(add-hook! 'typescript-tsx-mode-hook
  (remove-hook 'before-save-hook #'lsp-organize-imports :local))

still not working.

Is there anyway to configure lsp-organize-imports for go-mode without affecting other modes?

Steps to reproduce

  1. Install doomemacs and enable editor: (format +onsave) and tools: lsp
  2. Configure to add lsp-organize-imports to before-save-hook under go-mode-hook
  3. Open a go file in go project
  4. Open a tsx file in a frontend project
  5. Edit the tsx file and save

Expected behavior

The tsx file should save fast without run lsp-organize-imports

Which Language Server did you use?

gopls and ts-ls

OS

Linux

Error callstack

No response

Anything else?

No response

@oodzchen oodzchen added the bug label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant