feat(plugins,formatters): move formatters to dedicated file
This commit is contained in:
83
lua/dot/formatting.lua
Normal file
83
lua/dot/formatting.lua
Normal file
@@ -0,0 +1,83 @@
|
||||
local conform = require("conform")
|
||||
|
||||
local prettier = { "prettierd", "prettier", stop_after_first = true }
|
||||
|
||||
local function javascript_formatters(bufnr)
|
||||
local formatters = {}
|
||||
|
||||
if conform.get_formatter_info("deno_fmt", bufnr).available then
|
||||
table.insert(formatters, "deno_fmt")
|
||||
end
|
||||
|
||||
if conform.get_formatter_info("prettierd", bufnr).available then
|
||||
table.insert(formatters, "prettierd")
|
||||
elseif require("conform").get_formatter_info("prettier", bufnr).available then
|
||||
table.insert(formatters, "prettier")
|
||||
end
|
||||
|
||||
if conform.get_formatter_info("eslint_d", bufnr).available then
|
||||
table.insert(formatters, "eslint_d")
|
||||
end
|
||||
|
||||
return formatters
|
||||
end
|
||||
|
||||
conform.setup({
|
||||
formatters_by_ft = {
|
||||
css = prettier,
|
||||
gdscript = { "gdformat" },
|
||||
go = function(bufnr)
|
||||
local formatters = {}
|
||||
|
||||
if conform.get_formatter_info("gofumpt", bufnr).available then
|
||||
table.insert(formatters, "gofumpt")
|
||||
else
|
||||
table.insert(formatters, "gofmt")
|
||||
end
|
||||
|
||||
if conform.get_formatter_info("golines", bufnr).available then
|
||||
table.insert(formatters, "golines")
|
||||
end
|
||||
|
||||
if conform.get_formatter_info("goimports", bufnr).available then
|
||||
table.insert(formatters, "gofmt")
|
||||
end
|
||||
|
||||
if conform.get_formatter_info("golangci-lint").available then
|
||||
table.insert(formatters, "golangci-lint")
|
||||
end
|
||||
|
||||
return formatters
|
||||
end,
|
||||
html = prettier,
|
||||
javascript = javascript_formatters,
|
||||
javascriptreact = javascript_formatters,
|
||||
typescript = javascript_formatters,
|
||||
typescriptreact = javascript_formatters,
|
||||
json = function(bufnr)
|
||||
return #javascript_formatters(bufnr) and javascript_formatters(bufnr) or { "jq" }
|
||||
end,
|
||||
less = prettier,
|
||||
lua = { "stylua" },
|
||||
markdownn = { "mdfmt" },
|
||||
nix = { "alejandra", stop_after_first = true }, -- TODO: Support nix fmt command when flake.nix formatter is enabled
|
||||
rust = { "rustfmt", lsp_format = "fallback" },
|
||||
scss = prettier,
|
||||
sh = { "shellharden", "shfmt" },
|
||||
templ = { "templ" },
|
||||
yaml = prettier,
|
||||
xhtml = { "xmllint", "xmltidy", stop_after_first = true },
|
||||
xml = { "xmllint", "xmltidy", stop_after_first = true },
|
||||
|
||||
["*"] = { "codespell" },
|
||||
["_"] = { "trim_whitespace" },
|
||||
},
|
||||
format_on_save = {
|
||||
timeout_ms = 500,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
formaters = {
|
||||
mdfmt = { command = "mdfmt" },
|
||||
xmltidy = { inherit = false, command = "tidy", args = { "-xml", "-indent", "yes", "2", "-wrap", "100", "-" } }, -- INFO: Uses HTML Tidy
|
||||
},
|
||||
})
|
||||
@@ -36,113 +36,19 @@ lze.load({
|
||||
{
|
||||
"conform.nvim",
|
||||
after = function()
|
||||
local function js_fmt(bufnr)
|
||||
local f = {}
|
||||
|
||||
if require("conform").get_formatter_info("prettierd", bufnr).available then
|
||||
table.insert(f, "prettierd")
|
||||
elseif require("conform").get_formatter_info("prettier", bufnr).available then
|
||||
table.insert(f, "prettier")
|
||||
end
|
||||
|
||||
if require("conform").get_formatter_info("eslint_d", bufnr).available then
|
||||
table.insert(f, "eslint_d")
|
||||
end
|
||||
|
||||
if
|
||||
require("conform").get_formatter_info("deno_fmt", bufnr).available
|
||||
and (
|
||||
require("dot013.utils").is_in_cwd("deno.json")
|
||||
or require("dot013.utils").is_in_cwd("deno.jsonc")
|
||||
)
|
||||
then
|
||||
table.insert(f, "deno_fmt")
|
||||
end
|
||||
|
||||
return f
|
||||
end
|
||||
require("conform").setup({
|
||||
formatters_by_ft = {
|
||||
-- Simple formatters
|
||||
lua = { "stylua" },
|
||||
nix = { "alejandra", stop_after_first = true },
|
||||
rust = { "rustfmt", lsp_format = "fallback" },
|
||||
sh = { "shellharden", "shfmt" },
|
||||
xml = { "xmllint", "xmltidy" },
|
||||
xhtml = { "xmllint", "xmltidy" },
|
||||
markdown = { "mdfmt" },
|
||||
|
||||
html = { "prettierd", "prettier", stop_after_first = true },
|
||||
css = { "prettierd", "prettier", stop_after_first = true },
|
||||
scss = { "prettierd", "prettier", stop_after_first = true },
|
||||
less = { "prettierd", "prettier", stop_after_first = true },
|
||||
yaml = { "prettierd", "prettier", stop_after_first = true },
|
||||
|
||||
gdscript = { "gdformat" },
|
||||
-- Golang's formatters used by priority
|
||||
go = function(bufnr)
|
||||
local f = {}
|
||||
|
||||
if require("conform").get_formatter_info("gofumpt", bufnr).available then
|
||||
table.insert(f, "gofumpt")
|
||||
else
|
||||
table.insert(f, "gofmt")
|
||||
end
|
||||
|
||||
if require("conform").get_formatter_info("golines", bufnr).available then
|
||||
table.insert(f, "golines")
|
||||
elseif require("conform").get_formatter_info("goimports", bufnr).available then
|
||||
table.insert(f, "goimports")
|
||||
end
|
||||
|
||||
return f
|
||||
end,
|
||||
templ = { "templ" },
|
||||
|
||||
-- JavaScript's ecosystem
|
||||
javascript = js_fmt,
|
||||
javascriptreact = js_fmt,
|
||||
typescript = js_fmt,
|
||||
typescriptreact = js_fmt,
|
||||
json = function(bufnr)
|
||||
local fmts = js_fmt(bufnr)
|
||||
if fmts then
|
||||
return fmts
|
||||
end
|
||||
return { "jq" }
|
||||
end,
|
||||
|
||||
-- Fallback for any filetype
|
||||
["*"] = { "codespell" },
|
||||
["_"] = { "trim_whitespace" },
|
||||
},
|
||||
format_on_save = {
|
||||
timeout_ms = 500,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
formatters = {
|
||||
mdfmt = {
|
||||
command = "mdfmt",
|
||||
},
|
||||
xmltidy = {
|
||||
inherit = false,
|
||||
-- Uses HTML Tidy
|
||||
command = "tidy",
|
||||
args = { "-xml", "-indent", "yes", "2", "-wrap", "100", "-" },
|
||||
},
|
||||
--[[ nixcmdfmt = {
|
||||
inherit = false,
|
||||
stdin = false,
|
||||
cwd = require("conform.util").root_file({ "flake.nix" }),
|
||||
require_cwd = true,
|
||||
command = "nix",
|
||||
args = { "fmt", "$FILENAME" },
|
||||
}, ]]
|
||||
},
|
||||
})
|
||||
require("dot.formatting")
|
||||
end,
|
||||
event = { "InsertLeave", "TextChanged" },
|
||||
on_require = "conform",
|
||||
},
|
||||
{
|
||||
"guess-indent.nvim",
|
||||
after = function()
|
||||
require("guess-indent").setup()
|
||||
end,
|
||||
cmd = "GuessIndent",
|
||||
event = "BufEnter",
|
||||
},
|
||||
|
||||
-- Autocomplete
|
||||
{
|
||||
@@ -205,7 +111,7 @@ lze.load({
|
||||
},
|
||||
{ "telescope-zf-native.nvim", dep_of = "telescope.nvim" },
|
||||
|
||||
-- File quick switching
|
||||
-- Quick file switching
|
||||
{
|
||||
"harpoon2",
|
||||
after = function()
|
||||
@@ -250,16 +156,6 @@ lze.load({
|
||||
lazy = not (#(vim.fs.root(0, ".git") or 0) > 0),
|
||||
},
|
||||
|
||||
-- Formatting
|
||||
{
|
||||
"guess-indent.nvim",
|
||||
after = function()
|
||||
require("guess-indent").setup()
|
||||
end,
|
||||
cmd = "GuessIndent",
|
||||
event = "BufEnter",
|
||||
},
|
||||
|
||||
-- Secrets hiding
|
||||
{
|
||||
"cloak.nvim",
|
||||
@@ -274,7 +170,7 @@ lze.load({
|
||||
ft = { "sh" },
|
||||
},
|
||||
|
||||
-- Treesitter
|
||||
-- Treesitter (Syntax Highlighting)
|
||||
{
|
||||
"nvim-treesitter",
|
||||
dep_of = "indent-blankline.nvim",
|
||||
@@ -301,7 +197,7 @@ lze.load({
|
||||
event = "BufEnter",
|
||||
},
|
||||
|
||||
-- Git signs
|
||||
-- Git
|
||||
{
|
||||
"gitsigns.nvim",
|
||||
after = function()
|
||||
@@ -329,4 +225,24 @@ lze.load({
|
||||
},
|
||||
lazy = not (#vim.fs.root(0, ".git") > 0),
|
||||
},
|
||||
|
||||
-- Todo comments
|
||||
{
|
||||
"todo-comments.nvim",
|
||||
after = function()
|
||||
require("todo-comments").setup()
|
||||
end,
|
||||
},
|
||||
|
||||
-- Integrations
|
||||
{
|
||||
"aw-watcher.nvim",
|
||||
after = function()
|
||||
require("aw_watcher").setup({})
|
||||
end,
|
||||
},
|
||||
{
|
||||
"godot.nvim",
|
||||
cmd = { "GodotDebug", "GodotBreakAtCursor", "GodotStep", "GodotQuit", "GodotContinue" },
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user