Skip to content

Neovim templ formatting #1378

@fdgdgerg

Description

@fdgdgerg

Describe the bug
Templ fmt is inconsistent during usage within neovim and doesn't play nicely with conform.nvim. Especially when formatting <script> tags. The more code that is written the more inconsistent the behaviour. Templ fmt is also exceptionally slow.

I assume its pushing the buffer state back in time further the more code/time is written/passed.

To Reproduce
Write a dummy script tag on online with text in between. And save.
Conform.nvim is necessary to reproduce the bug. And can be reproduced whether or not conform.nvim is enabled or disabled. When conform.nvim is enabled though the behaviour occasionally becomes quite a bit more emphasized, I'm assuming based on distance in time/code from the prior save.

Expected behavior
The two script tags should be formatted and saved.

Actual behavior
2 save ":w" instances are needed to format and save the code.

Screenshots
Image

Logs
If the issue is related to IDE support, run through the LSP troubleshooting section at https://templ.guide/developer-tools/ide-support/#troubleshooting-1 and include logs from templ

templ info output
(✓) os [ goos=darwin goarch=arm64 ]
(✓) go [ location=/opt/homebrew/bin/go version=go version go1.26.2 darwin/arm64 ]
(✓) gopls [ location=/opt/homebrew/bin/gopls version=golang.org/x/tools/gopls v0.21.1 ]
(✓) templ [ location=/Users/joebu/go/bin/templ version=v0.3.1001 ]
(!) prettier [ location= version= message=failed to find prettier: exec: "prettier": executable file not found in $PATH ]
Note: prettier and prettierd are within neovim and installed via mason

Desktop (please complete the following information):
OS: MacOS
templ lsp version: v0.3.1001
Additional context
Full Config Link:
https://github.com/[fdgdgerg/nvim-config-errors](https://github.com/fdgdgerg/nvim-config-errors)

Slowness Video:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions