mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-21 08:35:48 +02:00
add: auto-conform config plugins
This commit is contained in:
parent
a636b2988d
commit
dd872b6ea5
3 changed files with 219 additions and 140 deletions
|
@ -2,6 +2,7 @@
|
||||||
"Comment.nvim": { "branch": "master", "commit": "e51f2b142d88bb666dcaa77d93a07f4b419aca70" },
|
"Comment.nvim": { "branch": "master", "commit": "e51f2b142d88bb666dcaa77d93a07f4b419aca70" },
|
||||||
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
|
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
|
||||||
"alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" },
|
"alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" },
|
||||||
|
"auto-conform.nvim": { "branch": "main", "commit": "d0fd09f9ef296963c2ce710361e0af50d3765ace" },
|
||||||
"bigfile.nvim": { "branch": "main", "commit": "33eb067e3d7029ac77e081cfe7c45361887a311a" },
|
"bigfile.nvim": { "branch": "main", "commit": "33eb067e3d7029ac77e081cfe7c45361887a311a" },
|
||||||
"bufferline.nvim": { "branch": "main", "commit": "81820cac7c85e51e4cf179f8a66d13dbf7b032d9" },
|
"bufferline.nvim": { "branch": "main", "commit": "81820cac7c85e51e4cf179f8a66d13dbf7b032d9" },
|
||||||
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
|
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
|
||||||
|
|
78
lua/plugins/autoconform.lua
Normal file
78
lua/plugins/autoconform.lua
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
local M = {}
|
||||||
|
local disable = pcode.disable_null_ls or false
|
||||||
|
if require("user.utils.cfgstatus").cheack() then
|
||||||
|
disable = true
|
||||||
|
end
|
||||||
|
if disable then
|
||||||
|
M = {
|
||||||
|
"pojokcodeid/auto-conform.nvim",
|
||||||
|
dependencies = {
|
||||||
|
"williamboman/mason.nvim",
|
||||||
|
"stevearc/conform.nvim",
|
||||||
|
},
|
||||||
|
event = "VeryLazy",
|
||||||
|
config = function()
|
||||||
|
require("auto-conform").setup({
|
||||||
|
-- formatters config conform
|
||||||
|
formatters = {
|
||||||
|
-- yamlfix = {
|
||||||
|
-- -- Change where to find the command
|
||||||
|
-- command = "local/path/yamlfix",
|
||||||
|
-- -- Adds environment args to the yamlfix formatter
|
||||||
|
-- env = {
|
||||||
|
-- YAMLFIX_SEQUENCE_STYLE = "block_style",
|
||||||
|
-- },
|
||||||
|
-- },
|
||||||
|
},
|
||||||
|
-- formatters_by_ft conform
|
||||||
|
formatters_by_ft = {
|
||||||
|
lua = { "stylua" },
|
||||||
|
},
|
||||||
|
-- install mason formatter
|
||||||
|
ensure_installed = {
|
||||||
|
"prettier",
|
||||||
|
},
|
||||||
|
-- mapping masson language vs filetype
|
||||||
|
lang_maps = {
|
||||||
|
-- ["c++"] = "cpp",
|
||||||
|
-- ["c#"] = "cs",
|
||||||
|
-- ["jsx"] = "javascriptreact",
|
||||||
|
},
|
||||||
|
-- mappings conform name vs masonn name if not same
|
||||||
|
name_maps = {
|
||||||
|
-- ["cmakelang"] = "cmake_format",
|
||||||
|
-- ["deno"] = "deno_fmt",
|
||||||
|
-- ["elm-format"] = "elm_format",
|
||||||
|
},
|
||||||
|
-- add new mapping to conform
|
||||||
|
add_new = {
|
||||||
|
-- ["jsonc"] = "prettier",
|
||||||
|
-- ["json"] = "prettier",
|
||||||
|
-- ["typescriptreact"] = "prettier",
|
||||||
|
},
|
||||||
|
-- disable register mason to conform
|
||||||
|
ignore = {
|
||||||
|
-- ["php"] = "tlint",
|
||||||
|
-- ["lua"] = "ast-grep",
|
||||||
|
-- ["kotlin"] = "ktlint",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
-- other conform config
|
||||||
|
local conform = require("conform")
|
||||||
|
conform.setup({
|
||||||
|
format_on_save = {
|
||||||
|
lsp_fallback = true,
|
||||||
|
timeout_ms = pcode.format_timeout_ms or 5000,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
vim.keymap.set({ "n", "v" }, "<leader>lF", function()
|
||||||
|
conform.format({
|
||||||
|
lsp_fallback = true,
|
||||||
|
async = false,
|
||||||
|
timeout_ms = pcode.format_timeout_ms or 5000,
|
||||||
|
})
|
||||||
|
end, { desc = "Format file or range (in visual mode)" })
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return M
|
|
@ -4,145 +4,145 @@ if require("user.utils.cfgstatus").cheack() then
|
||||||
disable = true
|
disable = true
|
||||||
end
|
end
|
||||||
if disable then
|
if disable then
|
||||||
M = {
|
-- M = {
|
||||||
"stevearc/conform.nvim",
|
-- "stevearc/conform.nvim",
|
||||||
event = { "BufReadPre", "BufNewFile", "VeryLazy" },
|
-- event = { "BufReadPre", "BufNewFile", "VeryLazy" },
|
||||||
opts = function(_, opts)
|
-- opts = function(_, opts)
|
||||||
local mason_reg = require("mason-registry")
|
-- local mason_reg = require("mason-registry")
|
||||||
|
--
|
||||||
opts.formatters = opts.formatters or {}
|
-- opts.formatters = opts.formatters or {}
|
||||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
-- opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||||
opts.ensure_installed = opts.ensure_installed or {}
|
-- opts.ensure_installed = opts.ensure_installed or {}
|
||||||
vim.list_extend(opts.ensure_installed, pcode.null_ls_ensure_installed or {})
|
-- vim.list_extend(opts.ensure_installed, pcode.null_ls_ensure_installed or {})
|
||||||
|
--
|
||||||
-- add diff langue vs filetype
|
-- -- add diff langue vs filetype
|
||||||
local keymap = {
|
-- local keymap = {
|
||||||
["c++"] = "cpp",
|
-- ["c++"] = "cpp",
|
||||||
["c#"] = "cs",
|
-- ["c#"] = "cs",
|
||||||
["jsx"] = "javascriptreact",
|
-- ["jsx"] = "javascriptreact",
|
||||||
}
|
-- }
|
||||||
|
--
|
||||||
-- add diff conform vs mason
|
-- -- add diff conform vs mason
|
||||||
local name_map = {
|
-- local name_map = {
|
||||||
["cmakelang"] = "cmake_format",
|
-- ["cmakelang"] = "cmake_format",
|
||||||
["deno"] = "deno_fmt",
|
-- ["deno"] = "deno_fmt",
|
||||||
["elm-format"] = "elm_format",
|
-- ["elm-format"] = "elm_format",
|
||||||
["gdtoolkit"] = "gdformat",
|
-- ["gdtoolkit"] = "gdformat",
|
||||||
["nixpkgs-fmt"] = "nixpkgs_fmt",
|
-- ["nixpkgs-fmt"] = "nixpkgs_fmt",
|
||||||
["opa"] = "opa_fmt",
|
-- ["opa"] = "opa_fmt",
|
||||||
["php-cs-fixer"] = "php_cs_fixer",
|
-- ["php-cs-fixer"] = "php_cs_fixer",
|
||||||
["ruff"] = "ruff_format",
|
-- ["ruff"] = "ruff_format",
|
||||||
["sql-formatter"] = "sql_formatter",
|
-- ["sql-formatter"] = "sql_formatter",
|
||||||
["xmlformatter"] = "xmlformat",
|
-- ["xmlformatter"] = "xmlformat",
|
||||||
}
|
-- }
|
||||||
|
--
|
||||||
-- add new mapping filetype
|
-- -- add new mapping filetype
|
||||||
local addnew = {
|
-- local addnew = {
|
||||||
["jsonc"] = "prettier",
|
-- ["jsonc"] = "prettier",
|
||||||
["json"] = "prettier",
|
-- ["json"] = "prettier",
|
||||||
["typescriptreact"] = "prettier",
|
-- ["typescriptreact"] = "prettier",
|
||||||
}
|
-- }
|
||||||
|
--
|
||||||
-- add ignore filetype
|
-- -- add ignore filetype
|
||||||
local ignore = {
|
-- local ignore = {
|
||||||
["php"] = "tlint",
|
-- ["php"] = "tlint",
|
||||||
["lua"] = "ast-grep",
|
-- ["lua"] = "ast-grep",
|
||||||
["kotlin"] = "ktlint",
|
-- ["kotlin"] = "ktlint",
|
||||||
}
|
-- }
|
||||||
|
--
|
||||||
for _, pkg in pairs(mason_reg.get_installed_packages()) do
|
-- for _, pkg in pairs(mason_reg.get_installed_packages()) do
|
||||||
for _, type in pairs(pkg.spec.categories) do
|
-- for _, type in pairs(pkg.spec.categories) do
|
||||||
-- only act upon a formatter
|
-- -- only act upon a formatter
|
||||||
if type == "Formatter" then
|
-- if type == "Formatter" then
|
||||||
-- if formatter doesn't have a builtin config, create our own from a generic template
|
-- -- if formatter doesn't have a builtin config, create our own from a generic template
|
||||||
if not require("conform").get_formatter_config(pkg.spec.name) then
|
-- if not require("conform").get_formatter_config(pkg.spec.name) then
|
||||||
-- the key of the entry to this table
|
-- -- the key of the entry to this table
|
||||||
-- is the name of the bare executable
|
-- -- is the name of the bare executable
|
||||||
-- the actual value may not be the absolute path
|
-- -- the actual value may not be the absolute path
|
||||||
-- in some cases
|
-- -- in some cases
|
||||||
local bin = next(pkg.spec.bin)
|
-- local bin = next(pkg.spec.bin)
|
||||||
-- this should be replaced by a function
|
-- -- this should be replaced by a function
|
||||||
-- that quieries the configured mason install path
|
-- -- that quieries the configured mason install path
|
||||||
local prefix = vim.fn.stdpath("data") .. "/mason/bin/"
|
-- local prefix = vim.fn.stdpath("data") .. "/mason/bin/"
|
||||||
|
--
|
||||||
opts.formatters[pkg.spec.name] = {
|
-- opts.formatters[pkg.spec.name] = {
|
||||||
command = prefix .. bin,
|
-- command = prefix .. bin,
|
||||||
args = { "$FILENAME" },
|
-- args = { "$FILENAME" },
|
||||||
stdin = true,
|
-- stdin = true,
|
||||||
require_cwd = false,
|
-- require_cwd = false,
|
||||||
}
|
-- }
|
||||||
end
|
|
||||||
|
|
||||||
-- local listtest = {}
|
|
||||||
-- finally add the formatter to it's compatible filetype(s)
|
|
||||||
for _, ft in pairs(pkg.spec.languages) do
|
|
||||||
local ftl = string.lower(ft)
|
|
||||||
-- register only ready installed package
|
|
||||||
local ready = mason_reg.get_package(pkg.spec.name):is_installed()
|
|
||||||
if ready then
|
|
||||||
if keymap[ftl] ~= nil then
|
|
||||||
ftl = keymap[ftl]
|
|
||||||
end
|
|
||||||
if name_map[pkg.spec.name] ~= nil then
|
|
||||||
pkg.spec.name = name_map[pkg.spec.name]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- if substring(pkg.spec.name, "ktfmt") then
|
|
||||||
-- table.insert(listtest, ftl)
|
|
||||||
-- end
|
-- end
|
||||||
|
--
|
||||||
-- add new mapping language
|
-- -- local listtest = {}
|
||||||
for key, value in pairs(addnew) do
|
-- -- finally add the formatter to it's compatible filetype(s)
|
||||||
if value == pkg.spec.name then
|
-- for _, ft in pairs(pkg.spec.languages) do
|
||||||
opts.formatters_by_ft[key] = opts.formatters_by_ft[key] or {}
|
-- local ftl = string.lower(ft)
|
||||||
table.insert(opts.formatters_by_ft[key], pkg.spec.name)
|
-- -- register only ready installed package
|
||||||
end
|
-- local ready = mason_reg.get_package(pkg.spec.name):is_installed()
|
||||||
end
|
-- if ready then
|
||||||
|
-- if keymap[ftl] ~= nil then
|
||||||
if ignore[ftl] ~= pkg.spec.name then
|
-- ftl = keymap[ftl]
|
||||||
opts.formatters_by_ft[ftl] = opts.formatters_by_ft[ftl] or {}
|
-- end
|
||||||
table.insert(opts.formatters_by_ft[ftl], pkg.spec.name)
|
-- if name_map[pkg.spec.name] ~= nil then
|
||||||
end
|
-- pkg.spec.name = name_map[pkg.spec.name]
|
||||||
end
|
-- end
|
||||||
end
|
--
|
||||||
-- print(table.concat(listtest, ","))
|
-- -- if substring(pkg.spec.name, "ktfmt") then
|
||||||
end
|
-- -- table.insert(listtest, ftl)
|
||||||
end
|
-- -- end
|
||||||
end
|
--
|
||||||
|
-- -- add new mapping language
|
||||||
local onsave = pcode.format_on_save or false
|
-- for key, value in pairs(addnew) do
|
||||||
if onsave then
|
-- if value == pkg.spec.name then
|
||||||
return {
|
-- opts.formatters_by_ft[key] = opts.formatters_by_ft[key] or {}
|
||||||
ensure_installed = opts.ensure_installed,
|
-- table.insert(opts.formatters_by_ft[key], pkg.spec.name)
|
||||||
format_on_save = {
|
-- end
|
||||||
lsp_fallback = true,
|
-- end
|
||||||
timeout_ms = pcode.format_timeout_ms or 5000,
|
--
|
||||||
},
|
-- if ignore[ftl] ~= pkg.spec.name then
|
||||||
formatters = opts.formatters,
|
-- opts.formatters_by_ft[ftl] = opts.formatters_by_ft[ftl] or {}
|
||||||
formatters_by_ft = opts.formatters_by_ft,
|
-- table.insert(opts.formatters_by_ft[ftl], pkg.spec.name)
|
||||||
}
|
-- end
|
||||||
else
|
-- end
|
||||||
return {
|
-- end
|
||||||
ensure_installed = opts.ensure_installed,
|
-- -- print(table.concat(listtest, ","))
|
||||||
formatters = opts.formatters,
|
-- end
|
||||||
formatters_by_ft = opts.formatters_by_ft,
|
-- end
|
||||||
}
|
-- end
|
||||||
end
|
--
|
||||||
end,
|
-- local onsave = pcode.format_on_save or false
|
||||||
config = function(_, opts)
|
-- if onsave then
|
||||||
for _, value in pairs(opts.ensure_installed) do
|
-- return {
|
||||||
require("user.utils.masoncfg").try_install(value)
|
-- ensure_installed = opts.ensure_installed,
|
||||||
end
|
-- format_on_save = {
|
||||||
local conform = require("conform")
|
-- lsp_fallback = true,
|
||||||
conform.setup(opts)
|
-- timeout_ms = pcode.format_timeout_ms or 5000,
|
||||||
vim.keymap.set({ "n", "v" }, "<leader>lF", function()
|
-- },
|
||||||
conform.format({
|
-- formatters = opts.formatters,
|
||||||
lsp_fallback = true,
|
-- formatters_by_ft = opts.formatters_by_ft,
|
||||||
async = false,
|
-- }
|
||||||
timeout_ms = pcode.format_timeout_ms or 5000,
|
-- else
|
||||||
})
|
-- return {
|
||||||
end, { desc = "Format file or range (in visual mode)" })
|
-- ensure_installed = opts.ensure_installed,
|
||||||
end,
|
-- formatters = opts.formatters,
|
||||||
}
|
-- formatters_by_ft = opts.formatters_by_ft,
|
||||||
|
-- }
|
||||||
|
-- end
|
||||||
|
-- end,
|
||||||
|
-- config = function(_, opts)
|
||||||
|
-- for _, value in pairs(opts.ensure_installed) do
|
||||||
|
-- require("user.utils.masoncfg").try_install(value)
|
||||||
|
-- end
|
||||||
|
-- local conform = require("conform")
|
||||||
|
-- conform.setup(opts)
|
||||||
|
-- vim.keymap.set({ "n", "v" }, "<leader>lF", function()
|
||||||
|
-- conform.format({
|
||||||
|
-- lsp_fallback = true,
|
||||||
|
-- async = false,
|
||||||
|
-- timeout_ms = pcode.format_timeout_ms or 5000,
|
||||||
|
-- })
|
||||||
|
-- end, { desc = "Format file or range (in visual mode)" })
|
||||||
|
-- end,
|
||||||
|
-- }
|
||||||
end
|
end
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue