neovim-confs/lua/plex/plugins/extras/formatting/prettier.lua

54 lines
1.2 KiB
Lua
Raw Normal View History

2023-09-06 00:26:45 +02:00
-- This is part of LazyVim's code, with my modifications.
-- See: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/formatting/prettier.lua
return {
{
2023-09-15 11:49:26 +02:00
"williamboman/mason.nvim",
2023-09-06 00:26:45 +02:00
opts = function(_, opts)
2023-09-15 11:49:26 +02:00
if type(opts.ensure_installed) == "table" then
table.insert(opts.ensure_installed, "prettierd")
2023-09-06 00:26:45 +02:00
end
end,
},
{
2023-09-15 11:49:26 +02:00
"mhartington/formatter.nvim",
2023-09-06 00:26:45 +02:00
optional = true,
2023-09-15 11:49:26 +02:00
keys = {
{ "<Leader>ff", "<cmd>Format<CR>", desc = "Use Formatter" },
},
2023-09-06 00:26:45 +02:00
opts = function(_, opts)
opts = opts or {}
local filetypes = {
-- FIXME:add more filetypes
2023-09-15 11:49:26 +02:00
json = { require("formatter.defaults.prettierd") },
rust = {
rustfmt = function()
return {
exe = "rustfmt",
args = { "--emit=std ut" },
stdin = true,
}
end,
},
["*"] = {
-- "formatter.filetypes.any" defines default configurations for any
-- filetype
require("formatter.filetypes.any").remove_trailing_whitespace,
},
2023-09-06 00:26:45 +02:00
}
2023-09-15 11:49:26 +02:00
opts.filetype = vim.tbl_extend("keep", opts.filetype or {}, filetypes)
2023-09-06 00:26:45 +02:00
end,
},
{
2023-09-15 11:49:26 +02:00
"jose-elias-alvarez/null-ls.nvim",
2023-09-06 00:26:45 +02:00
optional = true,
opts = function(_, opts)
2023-09-15 11:49:26 +02:00
local nls = require("null-ls")
2023-09-06 00:26:45 +02:00
table.insert(opts.sources, nls.builtins.formatting.prettierd)
end,
},
}