]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl/internal: Replace deprecated parser.ParseDir and doc.New
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 14 Feb 2026 11:05:21 +0000 (12:05 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 14 Feb 2026 13:49:09 +0000 (14:49 +0100)
Replace parser.ParseDir (deprecated since Go 1.25) with manual
file iteration using parser.ParseFile, and replace doc.New with
doc.NewFromFiles.

Fixes #14513

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
tpl/internal/templatefuncsRegistry.go

index 425938b073c2b0d99d39180799ce149366ded1da..991433a5610df0170c961d190a8285a8fb87d399 100644 (file)
@@ -20,6 +20,7 @@ import (
        "context"
        "encoding/json"
        "fmt"
+       "go/ast"
        "go/doc"
        "go/parser"
        "go/token"
@@ -291,13 +292,16 @@ func getGetTplPackagesGoDoc() map[string]map[string]methodGoDocInfo {
                        namespaceDoc := make(map[string]methodGoDocInfo)
                        packagePath := filepath.Join(basePath, fi.Name())
 
-                       d, err := parser.ParseDir(fset, packagePath, nil, parser.ParseComments)
+                       astFiles, err := parseDir(fset, packagePath)
                        if err != nil {
                                log.Fatal(err)
                        }
 
-                       for _, f := range d {
-                               p := doc.New(f, "./", 0)
+                       if len(astFiles) > 0 {
+                               p, err := doc.NewFromFiles(fset, astFiles, "./")
+                               if err != nil {
+                                       log.Fatal(err)
+                               }
 
                                for _, t := range p.Types {
                                        if t.Name == "Namespace" {
@@ -323,3 +327,22 @@ func getGetTplPackagesGoDoc() map[string]map[string]methodGoDocInfo {
 
        return tplPackagesGoDoc
 }
+
+func parseDir(fset *token.FileSet, dir string) ([]*ast.File, error) {
+       entries, err := os.ReadDir(dir)
+       if err != nil {
+               return nil, err
+       }
+       var files []*ast.File
+       for _, e := range entries {
+               if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") {
+                       continue
+               }
+               f, err := parser.ParseFile(fset, filepath.Join(dir, e.Name()), nil, parser.ParseComments)
+               if err != nil {
+                       return nil, err
+               }
+               files = append(files, f)
+       }
+       return files, nil
+}