🔧 Updated nvim with native prettier

This commit is contained in:
tomit4 2026-03-03 09:13:25 -08:00
parent 049818537e
commit b1c8c84752
6 changed files with 121 additions and 36 deletions

View file

@ -0,0 +1,35 @@
return {
"nvimtools/none-ls.nvim",
config = function()
local group = vim.api.nvim_create_augroup("lsp_format_on_save", { clear = false })
local event = "BufWritePre" -- or "BufWritePost"
local async = event == "BufWritePost"
require("null-ls").setup({
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.keymap.set("n", "<Leader>f", function()
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
end, { buffer = bufnr, desc = "[lsp] format" })
-- format on save
vim.api.nvim_clear_autocmds({ buffer = bufnr, group = group })
vim.api.nvim_create_autocmd(event, {
buffer = bufnr,
group = group,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr, async = async })
end,
desc = "[lsp] format on save",
})
end
if client.supports_method("textDocument/rangeFormatting") then
vim.keymap.set("x", "<Leader>f", function()
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
end, { buffer = bufnr, desc = "[lsp] format" })
end
end,
})
end,
}

View file

@ -0,0 +1,33 @@
return {
"MunifTanjim/prettier.nvim",
config = function()
require("prettier").setup({
bin = "prettierd", -- or `'prettierd'` (v0.23.3+)
filetypes = {
"css",
"graphql",
--"html",
"javascript",
"javascriptreact",
"json",
"less",
-- "markdown",
"scss",
"typescript",
"typescriptreact",
"yaml",
},
cli_options = {
trailingComma = "all",
tabWidth = 4,
printWidth = 80,
semi = false,
jsxSingleQuote = true,
singleQuote = true,
bracketSpacing = true,
bracketSameLine = true,
arrowParens = "avoid",
},
})
end,
}