Skip to content

Commit

Permalink
feat(neovim): disabled formatting on save
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed May 5, 2024
1 parent 1c2eb38 commit de1c36e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
10 changes: 9 additions & 1 deletion roles/neovim/files/lua/aome/core/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ local mappings = {
["<leader>d"] = { '"_d', "Deletes into the void register" },

["<leader>fm"] = {
vim.lsp.buf.format,
function()
vim.lsp.buf.format {
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = 0,
}
end,
"Formats current buffer if lsp available",
},

Expand Down
27 changes: 1 addition & 26 deletions roles/neovim/files/lua/custom/plugins/lsp/none-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ return {
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
local code_actions = null_ls.builtins.code_actions

-- to setup format on save
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})

-- configure null_ls
null_ls.setup {
-- add package.json as identifier for root (for typescript monorepos)
Expand All @@ -26,7 +23,7 @@ return {
"Makefile",
".git",
"package.json",
-- "selene.toml",
"selene.toml",
".luacheck"
),
-- setup formatters & linters
Expand Down Expand Up @@ -59,28 +56,6 @@ return {
},
require "none-ls.diagnostics.eslint_d",
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_client.supports_method "textDocument/formatting" then
vim.api.nvim_clear_autocmds {
group = augroup,
buffer = bufnr,
}
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format {
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = bufnr,
}
end,
})
end
end,
}
end,
}

0 comments on commit de1c36e

Please sign in to comment.