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'
|
local session_file = '.session.vim'
|
||||||
|
|
||||||
-- Check if the session file exists in the current directory
|
-- Check if the session file exists in the current directory
|
||||||
if file_exists(session_file) then
|
-- if file_exists(session_file) then
|
||||||
-- Source the session file
|
-- -- Source the session file
|
||||||
vim.cmd('source ' .. session_file)
|
-- vim.cmd('source ' .. session_file)
|
||||||
end
|
-- end
|
||||||
|
|
||||||
-- The line beneath this is called `modeline`. See `:help modeline`
|
-- The line beneath this is called `modeline`. See `:help modeline`
|
||||||
-- vim: ts=2 sts=2 sw=2 et
|
-- vim: ts=2 sts=2 sw=2 et
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,49 @@
|
||||||
|
-- lua/plugins/conform.lua
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
config = function()
|
config = function()
|
||||||
require("conform").setup({
|
-- Resolve templ binary (Mason first, else PATH)
|
||||||
formatters_by_ft = {
|
local mason_templ = vim.fn.stdpath("data") .. "/mason/bin/templ"
|
||||||
-- Disable formatters for .templ files
|
local templ_cmd = (vim.fn.executable(mason_templ) == 1) and mason_templ
|
||||||
templ = {},
|
or ((vim.fn.executable("templ") == 1) and "templ" or nil)
|
||||||
|
|
||||||
-- Add your other filetype configs here as needed
|
if not templ_cmd then
|
||||||
-- e.g., go = { "gofmt" },
|
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,
|
end,
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ return {
|
||||||
analyses = { unusedparams = true },
|
analyses = { unusedparams = true },
|
||||||
directoryFilters = { '-node_modules' },
|
directoryFilters = { '-node_modules' },
|
||||||
templ = {
|
templ = {
|
||||||
format = true,
|
format = false, -- DISABLED for debugging
|
||||||
lint = true,
|
lint = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -94,11 +94,11 @@ return {
|
||||||
},
|
},
|
||||||
eslint = {},
|
eslint = {},
|
||||||
html = { filetypes = { 'html', 'twig', 'hbs' } },
|
html = { filetypes = { 'html', 'twig', 'hbs' } },
|
||||||
templ = {
|
-- templ = { -- DISABLED for debugging
|
||||||
cmd = { vim.fn.stdpath("data") .. "/mason/bin/templ", "lsp" },
|
-- cmd = { vim.fn.stdpath("data") .. "/mason/bin/templ", "lsp" },
|
||||||
filetypes = { "templ" },
|
-- filetypes = { "templ" },
|
||||||
root_dir = require("lspconfig").util.root_pattern("go.mod", ".git"),
|
-- root_dir = require("lspconfig").util.root_pattern("go.mod", ".git"),
|
||||||
},
|
-- },
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ return {
|
||||||
|
|
||||||
local sources = {
|
local sources = {
|
||||||
diagnostics.checkmake,
|
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.stylua,
|
||||||
formatting.shfmt.with { args = { '-i', '4' } },
|
formatting.shfmt.with { args = { '-i', '4' } },
|
||||||
require('none-ls.formatting.ruff').with { extra_args = { '--extend-select', 'I' } },
|
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
|
-- you can reuse a shared lspconfig on_attach callback here
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
if client.supports_method 'textDocument/formatting' then
|
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_clear_autocmds { group = augroup, buffer = bufnr }
|
||||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
group = augroup,
|
group = augroup,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue