mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-22 00:49:01 +02:00
add: auto switch to conform if use default config language
This commit is contained in:
parent
22202bc11b
commit
fbd69d94ec
7 changed files with 295 additions and 258 deletions
|
@ -1,132 +1,139 @@
|
|||
return {
|
||||
"stevearc/conform.nvim",
|
||||
enabled = pcode.disable_null_ls or false,
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
opts = function(_, opts)
|
||||
local mason_reg = require("mason-registry")
|
||||
local M = {}
|
||||
local disable = pcode.disable_null_ls or false
|
||||
if require("user.utils.cfgstatus").cheack() then
|
||||
disable = true
|
||||
end
|
||||
if disable then
|
||||
M = {
|
||||
"stevearc/conform.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
opts = function(_, opts)
|
||||
local mason_reg = require("mason-registry")
|
||||
|
||||
opts.formatters = opts.formatters or {}
|
||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||
opts.formatters = opts.formatters or {}
|
||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||
|
||||
-- add diff langue vs filetype
|
||||
local keymap = {
|
||||
["c++"] = "cpp",
|
||||
["c#"] = "cs",
|
||||
["jsx"] = "javascriptreact",
|
||||
}
|
||||
-- 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 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 new mapping filetype
|
||||
local addnew = {
|
||||
["jsonc"] = "prettier",
|
||||
["json"] = "prettier",
|
||||
["typescriptreact"] = "prettier",
|
||||
}
|
||||
|
||||
-- add ignore filetype
|
||||
local ignore = {
|
||||
["php"] = "tlint",
|
||||
}
|
||||
-- add ignore filetype
|
||||
local ignore = {
|
||||
["php"] = "tlint",
|
||||
}
|
||||
|
||||
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/"
|
||||
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
|
||||
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
|
||||
-- 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, "prettier") then
|
||||
-- table.insert(listtest, ftl)
|
||||
-- end
|
||||
-- if substring(pkg.spec.name, "prettier") 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)
|
||||
-- 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
|
||||
|
||||
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
|
||||
-- print(table.concat(listtest, ","))
|
||||
end
|
||||
-- print(table.concat(listtest, ","))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local onsave = pcode.format_on_save or false
|
||||
if onsave then
|
||||
return {
|
||||
format_on_save = {
|
||||
local onsave = pcode.format_on_save or false
|
||||
if onsave then
|
||||
return {
|
||||
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 {
|
||||
formatters = opts.formatters,
|
||||
formatters_by_ft = opts.formatters_by_ft,
|
||||
}
|
||||
end
|
||||
end,
|
||||
config = function(_, opts)
|
||||
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,
|
||||
},
|
||||
formatters = opts.formatters,
|
||||
formatters_by_ft = opts.formatters_by_ft,
|
||||
}
|
||||
else
|
||||
return {
|
||||
formatters = opts.formatters,
|
||||
formatters_by_ft = opts.formatters_by_ft,
|
||||
}
|
||||
end
|
||||
end,
|
||||
config = function(_, opts)
|
||||
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, { desc = "Format file or range (in visual mode)" })
|
||||
end,
|
||||
}
|
||||
end
|
||||
return M
|
||||
|
|
|
@ -20,6 +20,7 @@ if pcode.active_javascript_config.active then
|
|||
"stevearc/conform.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = function(_, opts)
|
||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||
local package = "prettier"
|
||||
require("user.utils.masoncfg").try_install(package)
|
||||
opts.formatters_by_ft.javascript = { package }
|
||||
|
|
|
@ -1,25 +1,28 @@
|
|||
return {
|
||||
{
|
||||
"nvimtools/none-ls.nvim",
|
||||
lazy = true,
|
||||
enabled = not (pcode.disable_null_ls or false),
|
||||
dependencies = {
|
||||
{
|
||||
"jayp0521/mason-null-ls.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {
|
||||
ensure_installed = pcode.null_ls_ensure_installed or {},
|
||||
automatic_setup = true,
|
||||
handlers = {},
|
||||
local M = {}
|
||||
if not (pcode.disable_null_ls or false) then
|
||||
M = {
|
||||
{
|
||||
"nvimtools/none-ls.nvim",
|
||||
lazy = true,
|
||||
dependencies = {
|
||||
{
|
||||
"jayp0521/mason-null-ls.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {
|
||||
ensure_installed = pcode.null_ls_ensure_installed or {},
|
||||
automatic_setup = true,
|
||||
handlers = {},
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("mason-null-ls").setup(opts)
|
||||
end,
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("mason-null-ls").setup(opts)
|
||||
end,
|
||||
"nvimtools/none-ls-extras.nvim",
|
||||
},
|
||||
"nvimtools/none-ls-extras.nvim",
|
||||
event = "InsertEnter",
|
||||
opts = {},
|
||||
config = true,
|
||||
},
|
||||
event = "InsertEnter",
|
||||
opts = {},
|
||||
config = true,
|
||||
},
|
||||
}
|
||||
}
|
||||
end
|
||||
return M
|
||||
|
|
|
@ -1,126 +1,133 @@
|
|||
return {
|
||||
"mfussenegger/nvim-lint",
|
||||
enabled = pcode.disable_null_ls or false,
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
opts = function(_, opts)
|
||||
local mason_reg = require("mason-registry")
|
||||
local M = {}
|
||||
local disable = pcode.disable_null_ls or false
|
||||
if require("user.utils.cfgstatus").cheack() then
|
||||
disable = true
|
||||
end
|
||||
if disable then
|
||||
M = {
|
||||
"mfussenegger/nvim-lint",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
opts = function(_, opts)
|
||||
local mason_reg = require("mason-registry")
|
||||
|
||||
opts.linters_by_ft = opts.linters_by_ft or {}
|
||||
opts.linters_by_ft = opts.linters_by_ft or {}
|
||||
|
||||
-- add diff langue vs filetype
|
||||
local keymap = {
|
||||
["c++"] = "cpp",
|
||||
["c#"] = "cs",
|
||||
}
|
||||
-- add diff langue vs filetype
|
||||
local keymap = {
|
||||
["c++"] = "cpp",
|
||||
["c#"] = "cs",
|
||||
}
|
||||
|
||||
-- add dif nvim-lint vs mason
|
||||
local name_map = {
|
||||
["actionlint"] = "actionlint",
|
||||
["ansible_lint"] = "ansible_lint",
|
||||
["buf"] = "buf_lint",
|
||||
["buildifier"] = "buildifier",
|
||||
["cfn-lint"] = "cfn_lint",
|
||||
["checkstyle"] = "checkstyle",
|
||||
["clj-kondo"] = "clj_kondo",
|
||||
["cmakelint"] = "cmakelint",
|
||||
["codespell"] = "codespell",
|
||||
["cpplint"] = "cpplint",
|
||||
["cspell"] = "cspell",
|
||||
["curlylint"] = "curlylint",
|
||||
["djlint"] = "djlint",
|
||||
["erb-lint"] = "erb_lint",
|
||||
["eslint_d"] = "eslint_d",
|
||||
["flake8"] = "flake8",
|
||||
["gdtoolkit"] = "gdlint",
|
||||
["golangci-lint"] = "golangcilint",
|
||||
["hadolint"] = "hadolint",
|
||||
["jsonlint"] = "jsonlint",
|
||||
["ktlint"] = "ktlint",
|
||||
["luacheck"] = "luacheck",
|
||||
["markdownlint"] = "markdownlint",
|
||||
["mypy"] = "mypy",
|
||||
["phpcs"] = "phpcs",
|
||||
["phpmd"] = "phpmd",
|
||||
["phpstan"] = "phpstan",
|
||||
["proselint"] = "proselint",
|
||||
["pydocstyle"] = "pydocstyle",
|
||||
["pylint"] = "pylint",
|
||||
["revive"] = "revive",
|
||||
["rstcheck"] = "rstcheck",
|
||||
["rubocop"] = "rubocop",
|
||||
["ruff"] = "ruff",
|
||||
["selene"] = "selene",
|
||||
["shellcheck"] = "shellcheck",
|
||||
["sqlfluff"] = "sqlfluff",
|
||||
["standardrb"] = "standardrb",
|
||||
["stylelint"] = "stylelint",
|
||||
["solhint"] = "solhint",
|
||||
["tflint"] = "tflint",
|
||||
["tfsec"] = "tfsec",
|
||||
["trivy"] = "trivy",
|
||||
["vale"] = "vale",
|
||||
["vint"] = "vint",
|
||||
["vulture"] = "vulture",
|
||||
["yamllint"] = "yamllint",
|
||||
}
|
||||
-- add dif nvim-lint vs mason
|
||||
local name_map = {
|
||||
["actionlint"] = "actionlint",
|
||||
["ansible_lint"] = "ansible_lint",
|
||||
["buf"] = "buf_lint",
|
||||
["buildifier"] = "buildifier",
|
||||
["cfn-lint"] = "cfn_lint",
|
||||
["checkstyle"] = "checkstyle",
|
||||
["clj-kondo"] = "clj_kondo",
|
||||
["cmakelint"] = "cmakelint",
|
||||
["codespell"] = "codespell",
|
||||
["cpplint"] = "cpplint",
|
||||
["cspell"] = "cspell",
|
||||
["curlylint"] = "curlylint",
|
||||
["djlint"] = "djlint",
|
||||
["erb-lint"] = "erb_lint",
|
||||
["eslint_d"] = "eslint_d",
|
||||
["flake8"] = "flake8",
|
||||
["gdtoolkit"] = "gdlint",
|
||||
["golangci-lint"] = "golangcilint",
|
||||
["hadolint"] = "hadolint",
|
||||
["jsonlint"] = "jsonlint",
|
||||
["ktlint"] = "ktlint",
|
||||
["luacheck"] = "luacheck",
|
||||
["markdownlint"] = "markdownlint",
|
||||
["mypy"] = "mypy",
|
||||
["phpcs"] = "phpcs",
|
||||
["phpmd"] = "phpmd",
|
||||
["phpstan"] = "phpstan",
|
||||
["proselint"] = "proselint",
|
||||
["pydocstyle"] = "pydocstyle",
|
||||
["pylint"] = "pylint",
|
||||
["revive"] = "revive",
|
||||
["rstcheck"] = "rstcheck",
|
||||
["rubocop"] = "rubocop",
|
||||
["ruff"] = "ruff",
|
||||
["selene"] = "selene",
|
||||
["shellcheck"] = "shellcheck",
|
||||
["sqlfluff"] = "sqlfluff",
|
||||
["standardrb"] = "standardrb",
|
||||
["stylelint"] = "stylelint",
|
||||
["solhint"] = "solhint",
|
||||
["tflint"] = "tflint",
|
||||
["tfsec"] = "tfsec",
|
||||
["trivy"] = "trivy",
|
||||
["vale"] = "vale",
|
||||
["vint"] = "vint",
|
||||
["vulture"] = "vulture",
|
||||
["yamllint"] = "yamllint",
|
||||
}
|
||||
|
||||
-- add new mapping filetype
|
||||
local addnew = {
|
||||
["typescriptreact"] = "eslint_d",
|
||||
["javascriptreact"] = "eslint_d",
|
||||
["javascript.jsx"] = "eslint_d",
|
||||
["typescript.tsx"] = "eslint_d",
|
||||
["vue"] = "eslint_d",
|
||||
["sevelte"] = "eslint_d",
|
||||
["astro"] = "eslint_d",
|
||||
}
|
||||
-- add new mapping filetype
|
||||
local addnew = {
|
||||
["typescriptreact"] = "eslint_d",
|
||||
["javascriptreact"] = "eslint_d",
|
||||
["javascript.jsx"] = "eslint_d",
|
||||
["typescript.tsx"] = "eslint_d",
|
||||
["vue"] = "eslint_d",
|
||||
["sevelte"] = "eslint_d",
|
||||
["astro"] = "eslint_d",
|
||||
}
|
||||
|
||||
local ignore = {
|
||||
["php"] = "tlint",
|
||||
}
|
||||
local ignore = {
|
||||
["php"] = "tlint",
|
||||
}
|
||||
|
||||
-- local listtest = {}
|
||||
for _, pkg in pairs(mason_reg.get_installed_packages()) do
|
||||
for _, type in pairs(pkg.spec.categories) do
|
||||
-- only act upon a Linter
|
||||
if type == "Linter" then
|
||||
-- finally add the linter to it's compatible filetype(s)
|
||||
for _, ft in pairs(pkg.spec.languages) do
|
||||
local ftl = string.lower(ft)
|
||||
local ready = mason_reg.get_package(pkg.spec.name):is_installed()
|
||||
if ready then
|
||||
if keymap[ftl] ~= nil then
|
||||
ftl = keymap[ftl]
|
||||
end
|
||||
|
||||
-- if substring(pkg.spec.name, "eslint") then
|
||||
-- table.insert(listtest, ftl)
|
||||
-- end
|
||||
|
||||
if name_map[pkg.spec.name] ~= nil then
|
||||
pkg.spec.name = name_map[pkg.spec.name]
|
||||
end
|
||||
|
||||
-- add new mapping language
|
||||
for key, value in pairs(addnew) do
|
||||
if value == pkg.spec.name then
|
||||
opts.linters_by_ft[key] = opts.linters_by_ft[key] or {}
|
||||
table.insert(opts.linters_by_ft[key], pkg.spec.name)
|
||||
-- local listtest = {}
|
||||
for _, pkg in pairs(mason_reg.get_installed_packages()) do
|
||||
for _, type in pairs(pkg.spec.categories) do
|
||||
-- only act upon a Linter
|
||||
if type == "Linter" then
|
||||
-- finally add the linter to it's compatible filetype(s)
|
||||
for _, ft in pairs(pkg.spec.languages) do
|
||||
local ftl = string.lower(ft)
|
||||
local ready = mason_reg.get_package(pkg.spec.name):is_installed()
|
||||
if ready then
|
||||
if keymap[ftl] ~= nil then
|
||||
ftl = keymap[ftl]
|
||||
end
|
||||
end
|
||||
|
||||
if ignore[ftl] ~= pkg.spec.name then
|
||||
opts.linters_by_ft[ftl] = opts.linters_by_ft[ftl] or {}
|
||||
table.insert(opts.linters_by_ft[ftl], pkg.spec.name)
|
||||
-- if substring(pkg.spec.name, "eslint") then
|
||||
-- table.insert(listtest, ftl)
|
||||
-- end
|
||||
|
||||
if name_map[pkg.spec.name] ~= nil then
|
||||
pkg.spec.name = name_map[pkg.spec.name]
|
||||
end
|
||||
|
||||
-- add new mapping language
|
||||
for key, value in pairs(addnew) do
|
||||
if value == pkg.spec.name then
|
||||
opts.linters_by_ft[key] = opts.linters_by_ft[key] or {}
|
||||
table.insert(opts.linters_by_ft[key], pkg.spec.name)
|
||||
end
|
||||
end
|
||||
|
||||
if ignore[ftl] ~= pkg.spec.name then
|
||||
opts.linters_by_ft[ftl] = opts.linters_by_ft[ftl] or {}
|
||||
table.insert(opts.linters_by_ft[ftl], pkg.spec.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(table.concat(listtest, ","))
|
||||
end,
|
||||
config = function(_, opts)
|
||||
require("lint").linters_by_ft = opts.linters_by_ft
|
||||
end,
|
||||
}
|
||||
-- print(table.concat(listtest, ","))
|
||||
end,
|
||||
config = function(_, opts)
|
||||
require("lint").linters_by_ft = opts.linters_by_ft
|
||||
end,
|
||||
}
|
||||
end
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue