Skip to content

LSP completion not working in Templ control structures #1102

@axadrn

Description

@axadrn

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

  1. Create a simple templ component with a variable
  2. Try to write an if statement or for loop using that variable
  3. Notice that LSP completions don't appear during initial typing
  4. After completing the control structure, delete part of a variable name and start typing again
  5. 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

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