From 5d9318032405ae13cbe0025edbfb4b326697dab8 Mon Sep 17 00:00:00 2001 From: early Date: Sat, 7 Sep 2024 18:05:21 -0600 Subject: [PATCH] File() -> Source(), recursive list file deps --- include/callstack.go | 16 ++++++--- internal/compile/compile.go | 4 +-- internal/compile/component.go | 2 +- internal/compile/template.go | 66 ++++++++++++++++++++++------------- page/page.go | 17 ++++++++- part/part.go | 16 ++++++++- 6 files changed, 86 insertions(+), 35 deletions(-) diff --git a/include/callstack.go b/include/callstack.go index 3e889df..15e4910 100644 --- a/include/callstack.go +++ b/include/callstack.go @@ -35,21 +35,27 @@ func isNotEligible(caller string, ignorePackages []string) bool { // getCallStackButt gets the calling file, ignoring any file in an ignored // package. func getCallStackButt(ignorePackages []string) (string, error) { - skip := 0 - for { - callers := make([]uintptr, 10) + const incr int = 2 + const max int = incr * 10 + for skip := 0; skip < max; skip += incr { + callers := make([]uintptr, incr) count := runtime.Callers(skip, callers) frames := runtime.CallersFrames(callers) - for frame, more := frames.Next(); more; { + + frame, more := frames.Next() + for { // If getCallStackButt gets called from main, use the runtime to // determine what module main is in. if isNotEligible(frame.Function, ignorePackages) { + if !more { + break + } frame, more = frames.Next() } else { return frame.File, nil } } - if count < 10 { + if count < incr { break } } diff --git a/internal/compile/compile.go b/internal/compile/compile.go index f5937bb..2cbcc70 100644 --- a/internal/compile/compile.go +++ b/internal/compile/compile.go @@ -16,7 +16,7 @@ import ( type Source interface { Name() string - File() include.Opener + Source() include.Opener Includes() []Source } @@ -44,7 +44,7 @@ type Result struct { func Compile(root TemplateSource, transform ...func(root *html.Node)) (Result, error) { var result Result - reader, err := root.File().Open() + reader, err := root.Source().Open() if err != nil { return result, err } diff --git a/internal/compile/component.go b/internal/compile/component.go index 0c2aaff..7f77949 100644 --- a/internal/compile/component.go +++ b/internal/compile/component.go @@ -19,7 +19,7 @@ func insertComponentSource(subSource Source, document *html.Node) error { // subSource should be: //