templ.js

Status

Accepted - February 2026

Context

The templ.js VS Code extension must provide comprehensive IDE support (diagnostics, completion, hover) while delegating base format linting to VS Code’s native language servers.

Requirements

  1. Full IDE Support: Syntax highlighting, diagnostics, completion, hover, go-to-definition, formatting
  2. Embedded Language Handling: Treat templates as “base format + templ DSL overlay”
  3. Incremental Parsing: Only reparse edited sections for performance
  4. Single Language Stack: Pure TypeScript (no Python LSP servers)

Decision

Adopt Volar framework for VS Code language server implementation.

What is Volar?

Volar is a framework for building language servers for embedded languages (languages with multiple syntax regions). Originally built for Vue SFC files, it provides:

Architecture

```bash ascii-flow VS Code ↓ Volar Language Server ├→ Temple Parser (Chevrotain) │ ├→ Virtual Code: Base Format (Markdown/JSON/HTML) │ └→ Virtual Code: Temple DSL ├→ VS Code JSON Server (for JSON templates) ├→ VS Code Markdown Server (for Markdown templates) └→ Temple Semantic Analysis (query validation)


### Example: `example.md.tmpl`

**Source:**

```markdown
# User Report

{% for user in users %}

- {{ user.name }} ({{ user.email }})
  {% endfor %}

Virtual Code Mapping:

Consequences

Positive

Negative

Neutral

Performance Targets

References