-
Notifications
You must be signed in to change notification settings - Fork 59
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
Use with autoformatting #12
Comments
The only general solution I see doable: What about adding a
Increase the
Perhaps you could use this plugin's hooks to auto-save after auto-formatting?
Correct me If I'm wrong but in order of execution, what you want is: Linter -> Formatting -> Auto Saving Indeed this is out of the scope of either of the three plugins. I'd recommend you write a simple function that runs the three of them, one by one, evaluating the exit status of the previous one to see if the next one can run, and bind that to a command. |
The only problem with increasing the I think adding The order of execution is correct, however, it's very specific to the language's ecosystem, so definitely out of the scope of AutoSave. All good suggestions and food for thought though! |
This is my best attempt. lsp.lua local lsp = require 'lspconfig'
local on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd({ 'User' }, {
pattern = 'format',
callback = function()
vim.cmd 'lua vim.lsp.buf.format()'
end,
})
end autocmd.lua vim.api.nvim_create_autocmd({ 'InsertLeave' }, {
pattern = '*.*',
callback = function()
vim.cmd 'doautocmd User format'
vim.cmd 'update'
end,
})
vim.api.nvim_create_autocmd({ 'TextChanged' }, {
pattern = '*.*',
callback = function()
vim.cmd 'update'
end,
})
`` |
Heya! please check #33 🎉 |
Thanks to the effort of @pocco81 , with the rewrite (#33), we can set up callbacks = { -- functions to be executed at different intervals
enabling = nil, -- ran when enabling auto-save
disabling = nil, -- ran when disabling auto-save
before_asserting_save = nil, -- ran before checking `condition`
before_saving = nil, -- ran before doing the actual save
after_saving = nil -- ran after doing the actual save
} If you want to format the code before callbacks = {
before_saving = function()
return vim.lsp.buf.format()
end
} However, currently, there is a bug (please see #56). My current workaround is to use the fork https://github.com/AnonymusRaccoon/auto-save.nvim until it's merged. Thanks guys! |
I tend to use Prettier to format my code via something like Neoformat. It works almost perfectly, however, some plugins such as nvim-ts-autotag trigger the
InsertLeave
andTextChanged
events. In the case of autotag, the autosaving and formatting means the tag is closed before I get a chance to populate it for example.Another issue is that often the saving and formatting can run before linting errors have been properly addressed, which can crash whatever code you're working on.
The only solution I've found so far is to turn off AutoSaving each time I want to change a tag, or make some changes that might result in some temporary linting errors, but that's a bit of a frustrating workflow and somewhat defeats the point of the plugin.
I was wondering if, in the first instance, it might be possible to temporarily disable the plugin whilst another plugin runs. In the case of the linting problem, perhaps something like Neoformat should run the linter before attempting to format the code, but this might end up being quite language and formatter specific.
I realise this is probably an issue that's out of the scope of what this library tries to solve using a more complex stack, but I was interested to know if you had any thoughts in regards to a workaround?
Thanks for your hard work!
The text was updated successfully, but these errors were encountered: