Skip to content

Commit 63e0bbc

Browse files
committed
add check subcommand and update READMEs
Add a CLI `check` subcommand that runs the same diagnostic pipeline as the LSP server and outputs errors to stdout, enabling CI/CD pipelines, pre-commit hooks, and AI agents to lint Go templates without running an editor. Supports text output (file:line:col: message) and structured JSON output (-json flag). Exit codes: 0 = clean, 1 = errors found, 2 = tool failure. Update both go-template-lsp and gozer READMEs to document all available features including the new check subcommand, formatting with attribute wrapping, document links, and custom function discovery.
1 parent 7d3f45b commit 63e0bbc

3 files changed

Lines changed: 73 additions & 3 deletions

File tree

.beans/.sync.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"synced_at": "2026-02-01T19:29:29.915237Z"
88
}
99
},
10+
"golsp-909x": {
11+
"clickup": {
12+
"task_id": "868hdq2ky",
13+
"synced_at": "2026-02-08T16:33:17.888637Z"
14+
}
15+
},
1016
"golsp-9w5l": {
1117
"clickup": {
1218
"task_id": "868hba6g9",
@@ -61,6 +67,12 @@
6167
"synced_at": "2026-02-02T04:04:50.009521Z"
6268
}
6369
},
70+
"golsp-k9kf": {
71+
"clickup": {
72+
"task_id": "868hdq2kx",
73+
"synced_at": "2026-02-08T16:33:17.589069Z"
74+
}
75+
},
6476
"golsp-lteb": {
6577
"clickup": {
6678
"task_id": "868ham023",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# golsp-ru6k
3+
title: Update READMEs for check subcommand
4+
status: completed
5+
type: task
6+
priority: normal
7+
created_at: 2026-02-08T16:34:02Z
8+
updated_at: 2026-02-08T16:35:15Z
9+
---
10+
11+
Update go-template-lsp README and gozer README to document the new check subcommand and ensure all features are listed.

README.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ A Language Server Protocol (LSP) implementation for Go templates (`text/template
44

55
## Features
66

7-
- **Diagnostics**: Real-time syntax error detection as you type
7+
- **Diagnostics**: Real-time syntax error detection and semantic analysis (undefined variables, missing fields, unknown functions)
88
- **Hover**: Type information and documentation on hover over template variables and functions
99
- **Go to Definition**: Navigate to template definitions (`{{define "name"}}`)
1010
- **Formatting**: Re-indent based on HTML and template nesting, with optional attribute wrapping
1111
- **Folding Ranges**: Collapse template blocks (`{{if}}...{{end}}`, `{{range}}...{{end}}`) and comments
12-
- **Semantic Tokens**: Enhanced syntax highlighting
13-
- **Document Highlight**: Highlight matching template keywords
12+
- **Semantic Tokens**: Enhanced syntax highlighting for keywords, variables, functions, strings, numbers, and operators
13+
- **Document Highlight**: Highlight matching template keywords (e.g. click `{{if}}` to highlight its `{{else}}` and `{{end}}`)
14+
- **Document Links**: Clickable links in template documents
15+
- **Custom Function Discovery**: Automatically scans Go source files for `template.FuncMap` definitions so custom functions are recognized
16+
- **CLI Linting**: `check` subcommand for CI/CD and command-line diagnostics
1417

1518
## Installation
1619

@@ -112,6 +115,50 @@ When an HTML opening tag exceeds a configured line width, the formatter can wrap
112115

113116
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.
114117

118+
## CLI Linting (`check`)
119+
120+
The `check` subcommand runs the same diagnostic pipeline as the LSP server and prints errors to stdout. This is useful for CI/CD pipelines, pre-commit hooks, and AI agents.
121+
122+
```bash
123+
# Check the current directory
124+
go-template-lsp check
125+
126+
# Check a specific directory
127+
go-template-lsp check ./views
128+
129+
# JSON output
130+
go-template-lsp check -json ./views
131+
```
132+
133+
**Text output** (default):
134+
135+
```
136+
views/user.html:8:22: missing matching '{{ end }}' statement
137+
```
138+
139+
**JSON output** (`-json`):
140+
141+
```json
142+
[
143+
{
144+
"file": "views/user.html",
145+
"line": 8,
146+
"column": 22,
147+
"endLine": 8,
148+
"endColumn": 24,
149+
"message": "missing matching '{{ end }}' statement"
150+
}
151+
]
152+
```
153+
154+
**Exit codes:**
155+
156+
| Code | Meaning |
157+
|------|---------|
158+
| `0` | No errors found |
159+
| `1` | Template errors found |
160+
| `2` | Tool failure (e.g. directory not found) |
161+
115162
## Supported File Extensions
116163

117164
| Extension | Type |

0 commit comments

Comments
 (0)