From: Bjørn Erik Pedersen Date: Sat, 14 Feb 2026 11:05:21 +0000 (+0100) Subject: tpl/internal: Replace deprecated parser.ParseDir and doc.New X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4a641d1594bd893e4baf147c562342bf050e87d2;p=brevno-suite%2Fhugo tpl/internal: Replace deprecated parser.ParseDir and doc.New 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 --- diff --git a/tpl/internal/templatefuncsRegistry.go b/tpl/internal/templatefuncsRegistry.go index 425938b07..991433a56 100644 --- a/tpl/internal/templatefuncsRegistry.go +++ b/tpl/internal/templatefuncsRegistry.go @@ -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 +}