You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/GOTEMPLATE_PARSER.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@
4
4
5
5
## Overview
6
6
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.
@@ -26,10 +26,10 @@ Adds full structural analysis support for **Go HTML templates** (`.html`, `.tmpl
26
26
27
27
For each `.html` / `.tmpl` / `.gohtml` file containing `{{` syntax:
28
28
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)
31
31
-**`{{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)
33
33
-**`{{if ...}}` / `{{else if ...}}`** → correct stack handling (no extra `{{ end }}` consumed)
34
34
-**`.Variables`** → all dot-variables extracted from inside any `{{ ... }}` action, including pipelines like `{{ .Body | truncate 200 }}` and lowercase vars like `.user`, `.items`
35
35
-**Custom functions** → non-keyword identifiers followed by arguments
@@ -38,25 +38,25 @@ For each `.html` / `.tmpl` / `.gohtml` file containing `{{` syntax:
38
38
39
39
```
40
40
html/analyzer.go
41
-
└─ single WalkDir (GoTemplate detection)
41
+
├─ WalkDir (GoTemplate detection)
42
+
│ └─ gotemplate/analyzer.go (analyzeFile)
43
+
│ └─ gotemplate/adapter.go (ConvertToSymbols)
42
44
└─ ca.AnalyzePaths (HTML DOM analysis)
43
-
└─ gotemplate/analyzer.go ← analyzeFile()
44
-
└─ gotemplate/adapter.go ← ConvertToSymbols()
45
45
```
46
46
47
47
## Review Fixes Applied (PR #47)
48
48
49
49
| # | Issue | Fix |
50
50
|---|-------|-----|
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|
52
52
| 2 |`WalkDir` errors silently ignored | Logged via `logger.Instance.Debug`|
53
53
| 3 |`fmt.Fprintf(os.Stderr)` in library code | Replaced with project logger |
54
54
| 4 |`*ast.Ident` template deps missed | Added Ident case in `extractCallsFromAST`|
55
55
| 5 | V2 registry: loose version check |`== "v2"` exact match |
0 commit comments