-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: add "on_save" option #66
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, I like this 👍
But there is a problem with this implementation. If there are more than 1 LSP attached to the buffer, they will overwrite each other.
If there is one LSP with on_save = false
, and one with on_save = true
, the autocommand will still be created. And on save, even the first LSP with on_save = false
will format the buffer.
We need to check if on_save
is true for each client that is attached to the buffer.
This won't happen. Because local format_options = vim.tbl_deep_extend('keep', M.format_options[vim.bo.filetype] or {}, { on_save = true }) |
67e2dd5
to
1375073
Compare
Right, sorry. It's been a while since I worked on this. Ignore what I said |
lua/lsp-format/init.lua
Outdated
vim.api.nvim_clear_autocmds { | ||
buffer = bufnr, | ||
group = group, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwriting from a different LSP is not possible 👍 , but this will still not properly work if the filetype changes.
You need to run the clear autocommands even if on_save
is false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If filetype changes, the on_attach
function will not be triggered. And the previous LSP clients are still attaching on the buffer. You can try it by :set ft=<other filetype>
after opened a file. I think this issue won't happen too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will if you use nvim-lspconfig
, which most people do. I'd like to support this.
1375073
to
91db598
Compare
User can disable formatting on save.