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" },
|
||||
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
|
||||
"alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" },
|
||||
"auto-conform.nvim": { "branch": "main", "commit": "d0fd09f9ef296963c2ce710361e0af50d3765ace" },
|
||||
"bigfile.nvim": { "branch": "main", "commit": "33eb067e3d7029ac77e081cfe7c45361887a311a" },
|
||||
"bufferline.nvim": { "branch": "main", "commit": "81820cac7c85e51e4cf179f8a66d13dbf7b032d9" },
|
||||
"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
|
||||
end
|
||||
if disable then
|
||||
M = {
|
||||
"stevearc/conform.nvim",
|
||||
event = { "BufReadPre", "BufNewFile", "VeryLazy" },
|
||||
opts = function(_, opts)
|
||||
local mason_reg = require("mason-registry")
|
||||
|
||||
opts.formatters = opts.formatters or {}
|
||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||
opts.ensure_installed = opts.ensure_installed or {}
|
||||
vim.list_extend(opts.ensure_installed, pcode.null_ls_ensure_installed or {})
|
||||
|
||||
-- add diff langue vs filetype
|
||||
local keymap = {
|
||||
["c++"] = "cpp",
|
||||
["c#"] = "cs",
|
||||
["jsx"] = "javascriptreact",
|
||||
}
|
||||
|
||||
-- add diff conform vs mason
|
||||
local name_map = {
|
||||
["cmakelang"] = "cmake_format",
|
||||
["deno"] = "deno_fmt",
|
||||
["elm-format"] = "elm_format",
|
||||
["gdtoolkit"] = "gdformat",
|
||||
["nixpkgs-fmt"] = "nixpkgs_fmt",
|
||||
["opa"] = "opa_fmt",
|
||||
["php-cs-fixer"] = "php_cs_fixer",
|
||||
["ruff"] = "ruff_format",
|
||||
["sql-formatter"] = "sql_formatter",
|
||||
["xmlformatter"] = "xmlformat",
|
||||
}
|
||||
|
||||
-- add new mapping filetype
|
||||
local addnew = {
|
||||
["jsonc"] = "prettier",
|
||||
["json"] = "prettier",
|
||||
["typescriptreact"] = "prettier",
|
||||
}
|
||||
|
||||
-- add ignore filetype
|
||||
local ignore = {
|
||||
["php"] = "tlint",
|
||||
["lua"] = "ast-grep",
|
||||
["kotlin"] = "ktlint",
|
||||
}
|
||||
|
||||
for _, pkg in pairs(mason_reg.get_installed_packages()) do
|
||||
for _, type in pairs(pkg.spec.categories) do
|
||||
-- only act upon a formatter
|
||||
if type == "Formatter" then
|
||||
-- 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
|
||||
-- the key of the entry to this table
|
||||
-- is the name of the bare executable
|
||||
-- the actual value may not be the absolute path
|
||||
-- in some cases
|
||||
local bin = next(pkg.spec.bin)
|
||||
-- this should be replaced by a function
|
||||
-- that quieries the configured mason install path
|
||||
local prefix = vim.fn.stdpath("data") .. "/mason/bin/"
|
||||
|
||||
opts.formatters[pkg.spec.name] = {
|
||||
command = prefix .. bin,
|
||||
args = { "$FILENAME" },
|
||||
stdin = true,
|
||||
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
|
||||
|
||||
-- add new mapping language
|
||||
for key, value in pairs(addnew) do
|
||||
if value == pkg.spec.name then
|
||||
opts.formatters_by_ft[key] = opts.formatters_by_ft[key] or {}
|
||||
table.insert(opts.formatters_by_ft[key], pkg.spec.name)
|
||||
end
|
||||
end
|
||||
|
||||
if ignore[ftl] ~= pkg.spec.name then
|
||||
opts.formatters_by_ft[ftl] = opts.formatters_by_ft[ftl] or {}
|
||||
table.insert(opts.formatters_by_ft[ftl], pkg.spec.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(table.concat(listtest, ","))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local onsave = pcode.format_on_save or false
|
||||
if onsave then
|
||||
return {
|
||||
ensure_installed = opts.ensure_installed,
|
||||
format_on_save = {
|
||||
lsp_fallback = true,
|
||||
timeout_ms = pcode.format_timeout_ms or 5000,
|
||||
},
|
||||
formatters = opts.formatters,
|
||||
formatters_by_ft = opts.formatters_by_ft,
|
||||
}
|
||||
else
|
||||
return {
|
||||
ensure_installed = opts.ensure_installed,
|
||||
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,
|
||||
}
|
||||
-- M = {
|
||||
-- "stevearc/conform.nvim",
|
||||
-- event = { "BufReadPre", "BufNewFile", "VeryLazy" },
|
||||
-- opts = function(_, opts)
|
||||
-- local mason_reg = require("mason-registry")
|
||||
--
|
||||
-- opts.formatters = opts.formatters or {}
|
||||
-- opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||
-- opts.ensure_installed = opts.ensure_installed or {}
|
||||
-- vim.list_extend(opts.ensure_installed, pcode.null_ls_ensure_installed or {})
|
||||
--
|
||||
-- -- add diff langue vs filetype
|
||||
-- local keymap = {
|
||||
-- ["c++"] = "cpp",
|
||||
-- ["c#"] = "cs",
|
||||
-- ["jsx"] = "javascriptreact",
|
||||
-- }
|
||||
--
|
||||
-- -- add diff conform vs mason
|
||||
-- local name_map = {
|
||||
-- ["cmakelang"] = "cmake_format",
|
||||
-- ["deno"] = "deno_fmt",
|
||||
-- ["elm-format"] = "elm_format",
|
||||
-- ["gdtoolkit"] = "gdformat",
|
||||
-- ["nixpkgs-fmt"] = "nixpkgs_fmt",
|
||||
-- ["opa"] = "opa_fmt",
|
||||
-- ["php-cs-fixer"] = "php_cs_fixer",
|
||||
-- ["ruff"] = "ruff_format",
|
||||
-- ["sql-formatter"] = "sql_formatter",
|
||||
-- ["xmlformatter"] = "xmlformat",
|
||||
-- }
|
||||
--
|
||||
-- -- add new mapping filetype
|
||||
-- local addnew = {
|
||||
-- ["jsonc"] = "prettier",
|
||||
-- ["json"] = "prettier",
|
||||
-- ["typescriptreact"] = "prettier",
|
||||
-- }
|
||||
--
|
||||
-- -- add ignore filetype
|
||||
-- local ignore = {
|
||||
-- ["php"] = "tlint",
|
||||
-- ["lua"] = "ast-grep",
|
||||
-- ["kotlin"] = "ktlint",
|
||||
-- }
|
||||
--
|
||||
-- for _, pkg in pairs(mason_reg.get_installed_packages()) do
|
||||
-- for _, type in pairs(pkg.spec.categories) do
|
||||
-- -- only act upon a formatter
|
||||
-- if type == "Formatter" then
|
||||
-- -- 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
|
||||
-- -- the key of the entry to this table
|
||||
-- -- is the name of the bare executable
|
||||
-- -- the actual value may not be the absolute path
|
||||
-- -- in some cases
|
||||
-- local bin = next(pkg.spec.bin)
|
||||
-- -- this should be replaced by a function
|
||||
-- -- that quieries the configured mason install path
|
||||
-- local prefix = vim.fn.stdpath("data") .. "/mason/bin/"
|
||||
--
|
||||
-- opts.formatters[pkg.spec.name] = {
|
||||
-- command = prefix .. bin,
|
||||
-- args = { "$FILENAME" },
|
||||
-- stdin = true,
|
||||
-- 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
|
||||
--
|
||||
-- -- add new mapping language
|
||||
-- for key, value in pairs(addnew) do
|
||||
-- if value == pkg.spec.name then
|
||||
-- opts.formatters_by_ft[key] = opts.formatters_by_ft[key] or {}
|
||||
-- table.insert(opts.formatters_by_ft[key], pkg.spec.name)
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- if ignore[ftl] ~= pkg.spec.name then
|
||||
-- opts.formatters_by_ft[ftl] = opts.formatters_by_ft[ftl] or {}
|
||||
-- table.insert(opts.formatters_by_ft[ftl], pkg.spec.name)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- -- print(table.concat(listtest, ","))
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- local onsave = pcode.format_on_save or false
|
||||
-- if onsave then
|
||||
-- return {
|
||||
-- ensure_installed = opts.ensure_installed,
|
||||
-- format_on_save = {
|
||||
-- lsp_fallback = true,
|
||||
-- timeout_ms = pcode.format_timeout_ms or 5000,
|
||||
-- },
|
||||
-- formatters = opts.formatters,
|
||||
-- formatters_by_ft = opts.formatters_by_ft,
|
||||
-- }
|
||||
-- else
|
||||
-- return {
|
||||
-- ensure_installed = opts.ensure_installed,
|
||||
-- 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
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue