You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before you begin
I've installed the latest version of the templ CLI (go install github.com/a-h/templ/cmd/templ@latest), and have upgraded my project to use the latest version of the templ runtime (go get -u github.com/a-h/templ@latest).
Describe the bug
LSP auto-completion doesn't trigger properly when initially writing control structures (if statements, for loops) in Templ components. Completions only appear after you've already written the control structure, then modify an existing variable.
To Reproduce
Create a simple templ component with a variable
Try to write an if statement or for loop using that variable
Notice that LSP completions don't appear during initial typing
After completing the control structure, delete part of a variable name and start typing again
Now LSP completions will appear correctly
This happens in both VS Code and Neovim with nvim-cmp.
Expected behavior
LSP completions should appear during the initial writing of control structures, just like they do when modifying existing code.
Screenshots
I have a screen recording demonstrating this issue that I can provide if needed.
Desktop (please complete the following information):
OS: macOS 15.0
templ CLI version: v0.3.833
Go version: go1.24.0 darwin/arm64
gopls version: v0.18.1
Additional context
This issue affects both the latest release and the most recent commit of templ. The problem is consistent across different editors (VS Code and Neovim).
Screen.Recording.2025-03-21.at.7.44.30.PM.mov
The text was updated successfully, but these errors were encountered:
The issue is probably that since that commit, when you type for , then it won't pick up that it's a for loop until you enter {\n. As a result, no autocomplete...
Options are:
Revert the commit and go back to a situation where if you happen to start a line with for, then you're in Go code.
Update the templ language to force use @for, @if etc. to avoid the problem (and also normalise the @component() syntax with it).
Give the parser the ability to parse a new node called "ForExpressionIncomplete" which isn't valid, but triggers autocompletion.
It's likely that there's only an autocomplete LSP test for string expressions, hence not detecting it, and that a lot of people use snippets tools that auto-insert a {\n.
Before you begin
I've installed the latest version of the templ CLI (
go install github.com/a-h/templ/cmd/templ@latest
), and have upgraded my project to use the latest version of the templ runtime (go get -u github.com/a-h/templ@latest
).Describe the bug
LSP auto-completion doesn't trigger properly when initially writing control structures (if statements, for loops) in Templ components. Completions only appear after you've already written the control structure, then modify an existing variable.
To Reproduce
This happens in both VS Code and Neovim with nvim-cmp.
Expected behavior
LSP completions should appear during the initial writing of control structures, just like they do when modifying existing code.
Screenshots
I have a screen recording demonstrating this issue that I can provide if needed.
Desktop (please complete the following information):
gopls
version: v0.18.1Additional context
This issue affects both the latest release and the most recent commit of templ. The problem is consistent across different editors (VS Code and Neovim).
Screen.Recording.2025-03-21.at.7.44.30.PM.mov
The text was updated successfully, but these errors were encountered: