feat: add formatter.nvim
This commit is contained in:
@@ -15,15 +15,15 @@ local on_attach = function(_, bufnr)
|
||||
-- bmap('K', vim.lsp.buf.hover, 'Hover docs');
|
||||
bmap('<C-k>', vim.lsp.buf.signature_help, 'Signature docs');
|
||||
|
||||
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, {});
|
||||
-- vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
-- vim.lsp.buf.format()
|
||||
-- end, {});
|
||||
|
||||
local format_is_enabled = true;
|
||||
vim.api.nvim_buf_create_user_command('AutoFormatToggle', function()
|
||||
format_is_enabled = not format_is_enabled;
|
||||
print('Setting autoformatting to:' .. tostring(format_is_enabled));
|
||||
end, {});
|
||||
-- local format_is_enabled = true;
|
||||
-- vim.api.nvim_buf_create_user_command('AutoFormatToggle', function()
|
||||
-- format_is_enabled = not format_is_enabled;
|
||||
-- print('Setting autoformatting to:' .. tostring(format_is_enabled));
|
||||
-- end, {});
|
||||
end
|
||||
|
||||
require('which-key').register({
|
||||
@@ -86,3 +86,38 @@ require('mason-lspconfig').setup_handlers({
|
||||
});
|
||||
end
|
||||
});
|
||||
|
||||
local formatter_util = require("formatter.util")
|
||||
vim.api.nvim_create_augroup("__formatter__", { clear = true })
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
group = "__formatter__",
|
||||
command = ":FormatWrite",
|
||||
})
|
||||
require("formatter").setup({
|
||||
logging = true,
|
||||
log_level = vim.log.levels.WARN,
|
||||
filetype = {
|
||||
lua = {
|
||||
require("formatter.filetypes.lua").stylua,
|
||||
function()
|
||||
return {
|
||||
exe = "stylua",
|
||||
args = {
|
||||
"--search-parent-directories",
|
||||
"--stdin-filepath",
|
||||
formatter_util.escape_path(formatter_util.get_current_buffer_file_path()),
|
||||
"--",
|
||||
"-",
|
||||
},
|
||||
stdin = true,
|
||||
}
|
||||
end,
|
||||
},
|
||||
nix = {
|
||||
require("formatter.filetypes.nix").alejandra,
|
||||
},
|
||||
["*"] = {
|
||||
require("formatter.filetypes.any").remove_trailing_whitespace,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
|
||||
"conform.nvim": { "branch": "master", "commit": "75e7c5c7eb5fbd53f8b12dc420b31ec70770b231" },
|
||||
"fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" },
|
||||
"formatter.nvim": { "branch": "master", "commit": "ad246d34ce7a32f752071ed81b09b94e6b127fad" },
|
||||
"friendly-snippets": { "branch": "main", "commit": "69a2c1675b66e002799f5eef803b87a12f593049" },
|
||||
"gitsigns.nvim": { "branch": "main", "commit": "3e6e91b09f0468c32d3b96dcacf4b947f037ce25" },
|
||||
"hover.nvim": { "branch": "main", "commit": "bbd59ddfae4e64459944acf2abcda4d81ba8bac6" },
|
||||
|
||||
@@ -196,6 +196,7 @@ return {
|
||||
event = { 'InsertLeave', 'TextChanged', },
|
||||
opts = {},
|
||||
},
|
||||
{ 'mhartington/formatter.nvim' },
|
||||
{ 'tpope/vim-fugitive', },
|
||||
{ 'tpope/vim-rhubarb', },
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user