fix issue with templ files
This commit is contained in:
parent
ff42b77215
commit
d3455ad8ee
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "es5",
|
||||
"bracketSpacing": true,
|
||||
"bracketSameLine": false,
|
||||
"arrowParens": "avoid",
|
||||
"plugins": ["prettier-plugin-go-template"]
|
||||
}
|
||||
8
init.lua
8
init.lua
|
|
@ -98,10 +98,10 @@ end
|
|||
local session_file = '.session.vim'
|
||||
|
||||
-- Check if the session file exists in the current directory
|
||||
if file_exists(session_file) then
|
||||
-- Source the session file
|
||||
vim.cmd('source ' .. session_file)
|
||||
end
|
||||
-- if file_exists(session_file) then
|
||||
-- -- Source the session file
|
||||
-- vim.cmd('source ' .. session_file)
|
||||
-- end
|
||||
|
||||
-- The line beneath this is called `modeline`. See `:help modeline`
|
||||
-- vim: ts=2 sts=2 sw=2 et
|
||||
|
|
|
|||
|
|
@ -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" },
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ return {
|
|||
analyses = { unusedparams = true },
|
||||
directoryFilters = { '-node_modules' },
|
||||
templ = {
|
||||
format = true,
|
||||
format = false, -- DISABLED for debugging
|
||||
lint = true,
|
||||
},
|
||||
},
|
||||
|
|
@ -94,11 +94,11 @@ return {
|
|||
},
|
||||
eslint = {},
|
||||
html = { filetypes = { 'html', 'twig', 'hbs' } },
|
||||
templ = {
|
||||
cmd = { vim.fn.stdpath("data") .. "/mason/bin/templ", "lsp" },
|
||||
filetypes = { "templ" },
|
||||
root_dir = require("lspconfig").util.root_pattern("go.mod", ".git"),
|
||||
},
|
||||
-- templ = { -- DISABLED for debugging
|
||||
-- cmd = { vim.fn.stdpath("data") .. "/mason/bin/templ", "lsp" },
|
||||
-- filetypes = { "templ" },
|
||||
-- root_dir = require("lspconfig").util.root_pattern("go.mod", ".git"),
|
||||
-- },
|
||||
lua_ls = {
|
||||
settings = {
|
||||
Lua = {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ return {
|
|||
|
||||
local sources = {
|
||||
diagnostics.checkmake,
|
||||
formatting.prettier.with { filetypes = { 'html', 'json', 'yaml', 'markdown' } },
|
||||
formatting.prettier.with { filetypes = { 'html', 'json', 'yaml', 'markdown' } }, -- removed 'templ' for debugging
|
||||
formatting.stylua,
|
||||
formatting.shfmt.with { args = { '-i', '4' } },
|
||||
require('none-ls.formatting.ruff').with { extra_args = { '--extend-select', 'I' } },
|
||||
|
|
@ -41,6 +41,12 @@ return {
|
|||
-- you can reuse a shared lspconfig on_attach callback here
|
||||
on_attach = function(client, bufnr)
|
||||
if client.supports_method 'textDocument/formatting' then
|
||||
-- Skip formatting for .templ files during debugging
|
||||
local filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
|
||||
if filetype == 'templ' then
|
||||
return
|
||||
end
|
||||
|
||||
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
group = augroup,
|
||||
|
|
|
|||
Loading…
Reference in New Issue