replace none-ls with conform

This commit is contained in:
Ray Elliott 2026-01-12 18:57:13 +00:00
parent d3d2932e08
commit 16004b6117
3 changed files with 109 additions and 1 deletions

View File

@ -4,6 +4,7 @@
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
"cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" },
"cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" },
"conform.nvim": { "branch": "master", "commit": "238f542a118984a88124fc915d5b981680418707" },
"copilot-cmp": { "branch": "master", "commit": "15fc12af3d0109fa76b60b5cffa1373697e261d1" },
"copilot.lua": { "branch": "master", "commit": "5ace9ecd0db9a7a6c14064e4ce4ede5b800325f3" },
"gitsigns.nvim": { "branch": "main", "commit": "42d6aed4e94e0f0bbced16bbdcc42f57673bd75e" },
@ -12,7 +13,6 @@
"mason-lspconfig.nvim": { "branch": "main", "commit": "fe661093f4b05136437b531e7f959af2a2ae66c8" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "517ef5994ef9d6b738322664d5fdd948f0fdeb46" },
"mason.nvim": { "branch": "main", "commit": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65" },
"none-ls.nvim": { "branch": "main", "commit": "1fcf9cbf9acf893455c6cee792537aa709de62cb" },
"nvim-autopairs": { "branch": "master", "commit": "c2a0dd0d931d0fb07665e1fedb1ea688da3b80b4" },
"nvim-cmp": { "branch": "main", "commit": "85bbfad83f804f11688d1ab9486b459e699292d6" },
"nvim-lint": { "branch": "master", "commit": "ca6ea12daf0a4d92dc24c5c9ae22a1f0418ade37" },

108
lua/plugins/conform.lua Normal file
View File

@ -0,0 +1,108 @@
-- conform.nvim: Modern formatting without LSP overhead
-- Replaces none-ls for all formatting tasks
return {
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
config = function()
local conform = require("conform")
-- Helper: Find project-local executable, fallback to global
-- Searches node_modules/.bin/, vendor/bin/, and Mason bin first
local function find_executable(names)
local cwd = vim.fn.getcwd()
local mason_bin = vim.fn.stdpath("data") .. "/mason/bin/"
local search_paths = {
cwd .. "/node_modules/.bin/",
cwd .. "/vendor/bin/",
mason_bin,
}
for _, name in ipairs(names) do
for _, path in ipairs(search_paths) do
local full_path = path .. name
if vim.fn.executable(full_path) == 1 then
return full_path
end
end
if vim.fn.executable(name) == 1 then
return name
end
end
return nil
end
conform.setup({
formatters_by_ft = {
-- JavaScript, TypeScript, CSS, SCSS, JSON, HTML, Markdown
javascript = { "prettier" },
javascriptreact = { "prettier" },
typescript = { "prettier" },
typescriptreact = { "prettier" },
css = { "prettier" },
scss = { "prettier" },
html = { "prettier" },
json = { "prettier" },
jsonc = { "prettier" },
markdown = { "prettier" },
-- PHP
php = { "phpcbf" },
-- Lua
lua = { "stylua" },
},
-- Custom formatter definitions with executable resolution
formatters = {
prettier = {
command = find_executable({ "prettier" }) or "prettier",
},
phpcbf = {
-- Extend built-in phpcbf to add WordPress standard
prepend_args = { "--standard=WordPress" },
},
stylua = {
command = find_executable({ "stylua" }) or "stylua",
},
},
-- Format on save
format_on_save = function(bufnr)
-- Check global flag
if vim.g.format_on_save == false then
return nil
end
return {
timeout_ms = 500,
lsp_fallback = false, -- Don't use LSP formatting
}
end,
})
-- Format-on-save is enabled by default
vim.g.format_on_save = true
-- Keymaps
-- Toggle format-on-save
vim.keymap.set("n", "<leader>lt", function()
vim.g.format_on_save = not vim.g.format_on_save
local status = vim.g.format_on_save and "enabled" or "disabled"
vim.notify("Format on save " .. status, vim.log.levels.INFO)
end, { desc = "Formatting: Toggle format on save", silent = true, noremap = true })
-- Manual format (buffer)
vim.keymap.set("n", "<leader>lf", function()
conform.format({ async = false, lsp_fallback = false })
end, { desc = "Formatting: Format buffer", silent = true, noremap = true })
-- Manual format (visual range)
vim.keymap.set("v", "<leader>lf", function()
conform.format({ async = false, lsp_fallback = false })
end, { desc = "Formatting: Format selection", silent = true, noremap = true })
end,
}