Skip to content

Commit c1d954f

Browse files
committed
docs: resolve PR review feedback on go-template parsing
1 parent e956715 commit c1d954f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/GOTEMPLATE_PARSER.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
55
## Overview
66

7-
Adds full structural analysis support for **Go HTML templates** (`.html`, `.tmpl`, `.gohtml`) to the RagCode indexer. The new parser extracts template definitions, includes, block relationships, control-flow blocks, variables, and custom functions — and emits them as typed symbols with `RelDependency` edges for cross-file linking.
7+
Adds full structural analysis support for **Go HTML templates** (`.html`, `.tmpl`, `.gohtml`) to the RagCode indexer. The new parser extracts template definitions, includes, block relationships, control-flow blocks, variables, and custom functions — tracking them either as emitted `parser.Symbol` entries, relational edges like `RelInheritance`, or structured `metadata` attached to parent symbols.
88

99
## New Files
1010

1111
| File | Purpose |
1212
|------|---------|
1313
| `pkg/parser/html/gotemplate/analyzer.go` | Line-by-line scanner: extracts defines, blocks, templates, range/with/if/else-if, variables, custom funcs |
14-
| `pkg/parser/html/gotemplate/adapter.go` | Converts `GoTemplate` structs → `pkgParser.Symbol` + `RelDependency` relations |
14+
| `pkg/parser/html/gotemplate/adapter.go` | Converts `GoTemplate` structs → `parser.Symbol` + `RelDependency` relations |
1515
| `pkg/parser/html/gotemplate/analyzer_test.go` | Unit tests covering layout, page, partial, multi-file, else-if, block relations |
1616

1717
## Modified Files
@@ -26,10 +26,10 @@ Adds full structural analysis support for **Go HTML templates** (`.html`, `.tmpl
2626

2727
For each `.html` / `.tmpl` / `.gohtml` file containing `{{` syntax:
2828

29-
- **`{{define "name"}}`** → symbol of kind `template`, with start/end lines
30-
- **`{{block "name" .}}`**symbol of kind `block`, parent relation to enclosing define
29+
- **`{{define "name"}}`**`parser.Type` symbol with `metadata.template_type = go_template_define` and start/end lines (plus a separate file-level `go_template` symbol)
30+
- **`{{block "name" .}}`**represented via `RelInheritance` relations + `blocks` metadata on the file-level template symbol (no standalone `block` symbol)
3131
- **`{{template "name" .}}`**`RelDependency` edge from current template to included one
32-
- **`{{range .Items}}`** / **`{{with .Obj}}`**recorded in template metadata
32+
- **`{{range .Items}}`** → recorded in template metadata; **`{{with .Obj}}`**only its source ranges are tracked (no dedicated symbol metadata yet)
3333
- **`{{if ...}}` / `{{else if ...}}`** → correct stack handling (no extra `{{ end }}` consumed)
3434
- **`.Variables`** → all dot-variables extracted from inside any `{{ ... }}` action, including pipelines like `{{ .Body | truncate 200 }}` and lowercase vars like `.user`, `.items`
3535
- **Custom functions** → non-keyword identifiers followed by arguments
@@ -38,25 +38,25 @@ For each `.html` / `.tmpl` / `.gohtml` file containing `{{` syntax:
3838

3939
```
4040
html/analyzer.go
41-
└─ single WalkDir (GoTemplate detection)
41+
├─ WalkDir (GoTemplate detection)
42+
│ └─ gotemplate/analyzer.go (analyzeFile)
43+
│ └─ gotemplate/adapter.go (ConvertToSymbols)
4244
└─ ca.AnalyzePaths (HTML DOM analysis)
43-
└─ gotemplate/analyzer.go ← analyzeFile()
44-
└─ gotemplate/adapter.go ← ConvertToSymbols()
4545
```
4646

4747
## Review Fixes Applied (PR #47)
4848

4949
| # | Issue | Fix |
5050
|---|-------|-----|
51-
| 1 | Double I/O in directory walk | Single `WalkDir` for GoTemplate; DOM via `AnalyzePaths` |
51+
| 1 | Double I/O in directory walk | Reduced for GoTemplate; DOM analysis still performs separate walk |
5252
| 2 | `WalkDir` errors silently ignored | Logged via `logger.Instance.Debug` |
5353
| 3 | `fmt.Fprintf(os.Stderr)` in library code | Replaced with project logger |
5454
| 4 | `*ast.Ident` template deps missed | Added Ident case in `extractCallsFromAST` |
5555
| 5 | V2 registry: loose version check | `== "v2"` exact match |
5656
| 6 | Variables in pipelines missed | `reAction` + `reActionVar` pattern replacing narrow `reVariable` |
5757
| 7 | `reActionVar` missed lowercase vars | Regex broadened to `[A-Za-z_]` |
5858
| 8 | `htmlPaths` collected but unused | Variable removed entirely |
59-
| 9 | `scanner.Err()` unchecked after scan | Not yet addressed (future work) |
59+
| 9 | scanner.Err() unchecked after scan | Fixed: added check in analyzeFile |
6060

6161
## Tests
6262

0 commit comments

Comments
 (0)