Skip to content

Commit d3455ad

Browse files
committed
fix issue with templ files
1 parent ff42b77 commit d3455ad

File tree

5 files changed

+69
-22
lines changed

5 files changed

+69
-22
lines changed

.prettierrc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"quoteProps": "as-needed",
8+
"trailingComma": "es5",
9+
"bracketSpacing": true,
10+
"bracketSameLine": false,
11+
"arrowParens": "avoid",
12+
"plugins": ["prettier-plugin-go-template"]
13+
}

init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ end
9898
local session_file = '.session.vim'
9999

100100
-- Check if the session file exists in the current directory
101-
if file_exists(session_file) then
102-
-- Source the session file
103-
vim.cmd('source ' .. session_file)
104-
end
101+
-- if file_exists(session_file) then
102+
-- -- Source the session file
103+
-- vim.cmd('source ' .. session_file)
104+
-- end
105105

106106
-- The line beneath this is called `modeline`. See `:help modeline`
107107
-- vim: ts=2 sts=2 sw=2 et

lua/plugins/conform.lua

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
1+
-- lua/plugins/conform.lua
12
return {
23
{
34
"stevearc/conform.nvim",
5+
event = { "BufReadPre", "BufNewFile" },
46
config = function()
5-
require("conform").setup({
6-
formatters_by_ft = {
7-
-- Disable formatters for .templ files
8-
templ = {},
7+
-- Resolve templ binary (Mason first, else PATH)
8+
local mason_templ = vim.fn.stdpath("data") .. "/mason/bin/templ"
9+
local templ_cmd = (vim.fn.executable(mason_templ) == 1) and mason_templ
10+
or ((vim.fn.executable("templ") == 1) and "templ" or nil)
11+
12+
if not templ_cmd then
13+
vim.notify("[conform.nvim] Could not find `templ` binary. Install via Mason or PATH.", vim.log.levels.WARN)
14+
end
915

10-
-- Add your other filetype configs here as needed
11-
-- e.g., go = { "gofmt" },
16+
require("conform").setup({
17+
formatters = {
18+
templ_fmt = {
19+
command = templ_cmd or "templ",
20+
-- Read source from stdin, tell templ the filename for correct rules,
21+
-- and write formatted result to stdout (no in-place writes).
22+
args = { "fmt", "-stdin-filepath", "$FILENAME", "-stdout" },
23+
stdin = true,
24+
},
1225
},
13-
format_on_save = {
14-
timeout_ms = 500,
15-
lsp_fallback = true,
26+
formatters_by_ft = {
27+
templ = { "templ_fmt" }, -- ✅ only templ fmt for .templ
28+
javascript = { "prettier" },
29+
typescript = { "prettier" },
30+
jsx = { "prettier" },
31+
tsx = { "prettier" },
32+
json = { "prettier" },
33+
yaml = { "prettier" },
34+
markdown = { "prettier" },
35+
html = { "prettier" },
36+
css = { "prettier" },
37+
lua = { "stylua" },
38+
go = { "gofmt" },
1639
},
40+
format_on_save = function(bufnr)
41+
if vim.bo[bufnr].filetype == "templ" then
42+
return { timeout_ms = 2000, lsp_fallback = false } -- no LSP/Prettier fallback
43+
end
44+
return { timeout_ms = 1000, lsp_fallback = true }
45+
end,
1746
})
1847
end,
19-
event = { "BufReadPre", "BufNewFile" },
20-
}
48+
},
2149
}

lua/plugins/lsp.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ return {
7777
analyses = { unusedparams = true },
7878
directoryFilters = { '-node_modules' },
7979
templ = {
80-
format = true,
80+
format = false, -- DISABLED for debugging
8181
lint = true,
8282
},
8383
},
@@ -94,11 +94,11 @@ return {
9494
},
9595
eslint = {},
9696
html = { filetypes = { 'html', 'twig', 'hbs' } },
97-
templ = {
98-
cmd = { vim.fn.stdpath("data") .. "/mason/bin/templ", "lsp" },
99-
filetypes = { "templ" },
100-
root_dir = require("lspconfig").util.root_pattern("go.mod", ".git"),
101-
},
97+
-- templ = { -- DISABLED for debugging
98+
-- cmd = { vim.fn.stdpath("data") .. "/mason/bin/templ", "lsp" },
99+
-- filetypes = { "templ" },
100+
-- root_dir = require("lspconfig").util.root_pattern("go.mod", ".git"),
101+
-- },
102102
lua_ls = {
103103
settings = {
104104
Lua = {

lua/plugins/none-ls.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ return {
2727

2828
local sources = {
2929
diagnostics.checkmake,
30-
formatting.prettier.with { filetypes = { 'html', 'json', 'yaml', 'markdown' } },
30+
formatting.prettier.with { filetypes = { 'html', 'json', 'yaml', 'markdown' } }, -- removed 'templ' for debugging
3131
formatting.stylua,
3232
formatting.shfmt.with { args = { '-i', '4' } },
3333
require('none-ls.formatting.ruff').with { extra_args = { '--extend-select', 'I' } },
@@ -41,6 +41,12 @@ return {
4141
-- you can reuse a shared lspconfig on_attach callback here
4242
on_attach = function(client, bufnr)
4343
if client.supports_method 'textDocument/formatting' then
44+
-- Skip formatting for .templ files during debugging
45+
local filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
46+
if filetype == 'templ' then
47+
return
48+
end
49+
4450
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
4551
vim.api.nvim_create_autocmd('BufWritePre', {
4652
group = augroup,

0 commit comments

Comments
 (0)