fix issue with templ files
This commit is contained in:
parent
ff42b77215
commit
d3455ad8ee
5 changed files with 69 additions and 22 deletions
|
|
@ -1,21 +1,49 @@
|
|||
-- lua/plugins/conform.lua
|
||||
return {
|
||||
{
|
||||
"stevearc/conform.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
config = function()
|
||||
require("conform").setup({
|
||||
formatters_by_ft = {
|
||||
-- Disable formatters for .templ files
|
||||
templ = {},
|
||||
-- Resolve templ binary (Mason first, else PATH)
|
||||
local mason_templ = vim.fn.stdpath("data") .. "/mason/bin/templ"
|
||||
local templ_cmd = (vim.fn.executable(mason_templ) == 1) and mason_templ
|
||||
or ((vim.fn.executable("templ") == 1) and "templ" or nil)
|
||||
|
||||
-- Add your other filetype configs here as needed
|
||||
-- e.g., go = { "gofmt" },
|
||||
if not templ_cmd then
|
||||
vim.notify("[conform.nvim] Could not find `templ` binary. Install via Mason or PATH.", vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
require("conform").setup({
|
||||
formatters = {
|
||||
templ_fmt = {
|
||||
command = templ_cmd or "templ",
|
||||
-- Read source from stdin, tell templ the filename for correct rules,
|
||||
-- and write formatted result to stdout (no in-place writes).
|
||||
args = { "fmt", "-stdin-filepath", "$FILENAME", "-stdout" },
|
||||
stdin = true,
|
||||
},
|
||||
},
|
||||
format_on_save = {
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
formatters_by_ft = {
|
||||
templ = { "templ_fmt" }, -- ✅ only templ fmt for .templ
|
||||
javascript = { "prettier" },
|
||||
typescript = { "prettier" },
|
||||
jsx = { "prettier" },
|
||||
tsx = { "prettier" },
|
||||
json = { "prettier" },
|
||||
yaml = { "prettier" },
|
||||
markdown = { "prettier" },
|
||||
html = { "prettier" },
|
||||
css = { "prettier" },
|
||||
lua = { "stylua" },
|
||||
go = { "gofmt" },
|
||||
},
|
||||
format_on_save = function(bufnr)
|
||||
if vim.bo[bufnr].filetype == "templ" then
|
||||
return { timeout_ms = 2000, lsp_fallback = false } -- no LSP/Prettier fallback
|
||||
end
|
||||
return { timeout_ms = 1000, lsp_fallback = true }
|
||||
end,
|
||||
})
|
||||
end,
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue