jose-elias-alvarez / null-ls.nvim

Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
Other
3.64k stars 791 forks source link

auto formatting on save issue #102

Closed ghost closed 3 years ago

ghost commented 3 years ago

FAQ

Issues

Neovim Version

NVIM v0.6.0-dev+131-g2c60f7c99

Steps to reproduce

Setup autoformatting on save, using builtin stylua, open a lua file, make changes that would trigger stylua (eg. add multiple empty lines)

Expected behavior

On save, should trigger stylua and save the file

Actual behavior

Triggers stylua but doesn't save the file

Debug log

|| received LSP request for method initialize || received LSP notification for method initialized || received LSP notification for method textDocument/didOpen || running generators for method NULL_LS_DIAGNOSTICS || no generators available || received diagnostics from generators || {} || LSP Attached || received LSP notification for method textDocument/didChange || running generators for method NULL_LS_DIAGNOSTICS || no generators available || received diagnostics from generators || {} || received LSP notification for method textDocument/didChange || running generators for method NULL_LS_DIAGNOSTICS || no generators available || received diagnostics from generators || {} || "lua/plugins/null_ls/config.lua" 39L, 742C written || received LSP request for method textDocument/formatting || running generators for method NULL_LS_FORMATTING || spawning command stylua with args: || { "-s", "-" } || error output: nil || output: local au = require "utils.augroup" || local null = require "null-ls" || local b = null.builtins || null.config { || debug = true, || sources = { || b.formatting.stylua, || b.formatting.black, || b.formatting.rustfmt, || b.formatting.shfmt.with { || filetypes = { "sh", "zsh", ".zshrc" }, || }, || b.formatting.clang_format.with { || filetypes = { "c", "cpp" }, || }, || b.formatting.dart_format, || b.formatting.gofmt, || b.formatting.goimports, || }, || } || require("lspconfig")["null-ls"].setup { || onattach = function(, _) || au("null_auto_formatting", { || { || events = { "BufWritePost" }, || modifiers = { "" }, || command = vim.lsp.buf.formatting, || }, || }) || end, || root_dir = vim.loop.cwd, || } || received edits from generators || { { || col = 1, || end_col = 1, || end_row = 41, || row = 1, || text = 'local au = require "utils.augroup"\nlocal null = require "null-ls"\nlocal b = null.builtins\n\nnull.config {\n debug = true,\n sources = {\n b.formatting.stylua,\n b.formatting.black,\n b.formatting.rustfmt,\n b.formatting.shfmt.with {\n filetypes = { "sh", "zsh", ".zshrc" },\n },\n b.formatting.clang_format.with {\n filetypes = { "c", "cpp" },\n },\n b.formatting.dart_format,\n b.formatting.gofmt,\n b.formatting.goimports,\n },\n}\n\nrequire("lspconfig")["null-ls"].setup {\n onattach = function(, _)\n au("null_auto_formatting", {\n {\n events = { "BufWritePost" },\n modifiers = { "" },\n command = vim.lsp.buf.formatting,\n },\n })\n end,\n root_dir = vim.loop.cwd,\n}\n' || } } || successfully applied edits || received LSP notification for method textDocument/didChange || running generators for method NULL_LS_DIAGNOSTICS || no generators available || received diagnostics from generators || {}

Help

No

Implementation help

No response

ghost commented 3 years ago

I'm so sorry, I used BufWritePost instead of BufWritePre. I must have changed it mistakenly while messing with my config. Also I was using formatting instead of formatting_sync closing.