54 lines
1.1 KiB
Lua
54 lines
1.1 KiB
Lua
local prettier = function()
|
|
return {
|
|
exe = Get_project_node_modules_path() .. "/.bin/prettier",
|
|
args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
|
|
stdin = true,
|
|
}
|
|
end
|
|
|
|
local goimports = function()
|
|
local args = {}
|
|
|
|
local mod_path = Get_project_go_module_path()
|
|
if mod_path ~= "" then
|
|
table.insert(args, "-local")
|
|
table.insert(args, mod_path)
|
|
end
|
|
|
|
return {
|
|
exe = "goimports",
|
|
args = args,
|
|
stdin = true,
|
|
}
|
|
end
|
|
|
|
require("formatter").setup({
|
|
log_level = vim.log.levels.INFO,
|
|
filetype = {
|
|
javascript = { prettier },
|
|
typescript = { prettier },
|
|
typescriptreact = { prettier },
|
|
go = { goimports },
|
|
|
|
-- https://github.com/JohnnyMorganz/StyLua
|
|
-- cargo install stylua --features lua54
|
|
lua = {
|
|
require("formatter.filetypes.lua").stylua,
|
|
},
|
|
},
|
|
})
|
|
|
|
-- TODO: use vim.api.nvim_create_augroup()
|
|
vim.api.nvim_exec2(
|
|
[[
|
|
augroup FormatAutogroup
|
|
autocmd!
|
|
autocmd BufWritePost *.js,*.ts,*.tsx,*.go,*.lua silent FormatWrite
|
|
augroup END
|
|
]],
|
|
{ output = true }
|
|
)
|
|
|
|
local bufnr = vim.fn.bufnr("%")
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>F", "<Cmd>silent Format<CR>", { noremap = true, silent = true })
|