A Zed editor extension for Go templates (text/template and html/template), powered by go-template-lsp.
- Diagnostics: Real-time syntax error detection and semantic analysis (undefined variables, missing fields, unknown functions)
- Hover: Type information and documentation on hover over template variables and functions
- Go to Definition: Navigate to template definitions (
{{define "name"}}) - Formatting: Re-indent based on HTML and template nesting, with optional attribute wrapping
- Folding Ranges: Collapse template blocks (
{{if}}...{{end}},{{range}}...{{end}}) and comments - Semantic Tokens: Enhanced syntax highlighting for keywords, variables, functions, strings, numbers, and operators
- Document Highlight: Highlight matching template keywords (e.g. click
{{if}}to highlight its{{else}}and{{end}}) - Document Links: Clickable links in template documents
- Custom Function Discovery: Automatically scans Go source files for
template.FuncMapdefinitions so custom functions are recognized
| Extension | Type |
|---|---|
.gotmpl, .go.tmpl, .gtpl, .tpl, .tmpl |
Go text templates |
.gohtml, .go.html |
Go HTML templates |
.html |
HTML (with template detection) |
.htmx2.gohtml |
Go HTML templates with HTMX 2.x |
.htmx4.gohtml |
Go HTML templates with HTMX 4.x |
The extension includes variants for HTMX projects:
- Go HTML Template (HTMX 2): For HTMX 2.x projects (stable)
- Go HTML Template (HTMX 4): For HTMX 4.x projects (alpha, expected stable early-mid 2026)
To enable HTMX support, either:
- Use the file extension: Name your files with
.htmx2.gohtmlor.htmx4.gohtml - Select manually: Use Zed's language picker (click the language name in the status bar) to choose the HTMX variant
- Configure in settings: Add to your Zed
settings.json:
{
"file_types": {
"Go HTMX 2": ["gohtml"]
}
}The Zed language IDs for HTMX variants are Go HTMX 2 and Go HTMX 4.
- Open Zed
- Go to Extensions (Cmd+Shift+X)
- Search for "Go Template LSP"
- Click Install
The extension automatically downloads the appropriate LSP binary for your platform.
As a Dev Extension (for local development):
- Clone this repository
- In Zed, open the command palette (Cmd+Shift+P)
- Run "zed: install dev extension"
- Select this directory
See Zed's extension development docs for more details.
Configuration:
After installing the extension, you can customize file associations in your Zed settings.json (Cmd+, → "Open Settings"):
{
"languages": {
"Go HTML Template": {
"language_servers": ["go-template-lsp"]
},
"Go Text Template": {
"language_servers": ["go-template-lsp"]
}
}
}To add additional file extensions, use file_types:
{
"file_types": {
"Go HTML Template": ["tmpl", "html"]
}
}The LSP formatter re-indents Go template files based on HTML tag and template action nesting. It uses the standard tabSize and insertSpaces settings from Zed.
To enable attribute wrapping, add initialization options to your Zed settings.json:
{
"lsp": {
"go-template-lsp": {
"initialization_options": {
"printWidth": 120,
"attrWrapMode": "overflow"
}
}
}
}| Setting | Type | Default | Description |
|---|---|---|---|
printWidth |
int |
0 (disabled) |
Maximum line width before wrapping attributes. Set to 0 to disable. |
attrWrapMode |
string |
"overflow" |
"overflow": only wrap attributes that push past printWidth. "all": wrap every attribute onto its own line. |
overflow mode keeps attributes on the first line as long as they fit, then wraps the rest:
<button type="button"
class="map-zoom-btn"
title="Expand">all mode puts every attribute on its own line:
<button
type="button"
class="map-zoom-btn"
title="Expand">Continuation lines are indented one level deeper than the tag. Multi-line tags already in the source are joined back into a single line before re-wrapping.
cargo build --target wasm32-wasip1toba/go-template-lsp — The Go template LSP server that powers this extension.
yayolande/gota — Template parsing and semantic analysis, by yayolande.
yayolande/go-template-lsp — LSP server architecture, by yayolande.
hjr265/zed-gotmpl — Tree-sitter query patterns for syntax highlighting, adapted from this project by Mahmud Ridwan.
MIT License - see LICENSE for details.
