12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- local status, formatter = pcall(require, "formatter")
- if not status then
- vim.notify("没有找到 formatter")
- return
- end
- formatter.setup({
- filetype = {
- lua = {
- function()
- return {
- exe = "stylua",
- args = {
- -- "--config-path "
- -- .. os.getenv("XDG_CONFIG_HOME")
- -- .. "/stylua/stylua.toml",
- "-",
- },
- stdin = true,
- }
- end,
- },
- rust = {
- -- Rustfmt
- function()
- return {
- exe = "rustfmt",
- args = { "--emit=stdout" },
- stdin = true,
- }
- end,
- },
- javascript = {
- -- prettier
- function()
- return {
- exe = "prettier",
- args = { "--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)), "--single-quote" },
- stdin = true,
- }
- end,
- },
- },
- })
- -- format on save
- vim.api.nvim_exec(
- [[
- augroup FormatAutogroup
- autocmd!
- autocmd BufWritePost *.js,*.rs,*.lua FormatWrite
- augroup END
- ]],
- true
- )
|