diff --git a/.version b/.version
index 5158f20d0..a27b075aa 100644
--- a/.version
+++ b/.version
@@ -1 +1 @@
-0.2.808
\ No newline at end of file
+0.2.810
\ No newline at end of file
diff --git a/benchmarks/templ/template_templ.go b/benchmarks/templ/template_templ.go
index eb129170d..6fb43e211 100644
--- a/benchmarks/templ/template_templ.go
+++ b/benchmarks/templ/template_templ.go
@@ -28,7 +28,7 @@ func Render(p Person) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, ">
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/cmd/templ/generatecmd/cmd.go b/cmd/templ/generatecmd/cmd.go
index 3f1707481..77afe19b9 100644
--- a/cmd/templ/generatecmd/cmd.go
+++ b/cmd/templ/generatecmd/cmd.go
@@ -7,6 +7,7 @@ import (
"log/slog"
"net/http"
"net/url"
+ "os"
"path"
"path/filepath"
"regexp"
@@ -54,6 +55,7 @@ type Generate struct {
type GenerationEvent struct {
Event fsnotify.Event
+ Updated bool
GoUpdated bool
TextUpdated bool
}
@@ -114,7 +116,7 @@ func (cmd Generate) Run(ctx context.Context) (err error) {
// If we're processing a single file, don't bother setting up the channels/multithreaing.
if cmd.Args.FileName != "" {
- _, _, err = fseh.HandleEvent(ctx, fsnotify.Event{
+ _, err = fseh.HandleEvent(ctx, fsnotify.Event{
Name: cmd.Args.FileName,
Op: fsnotify.Create,
})
@@ -219,15 +221,16 @@ func (cmd Generate) Run(ctx context.Context) (err error) {
cmd.Log.Debug("Processing file", slog.String("file", event.Name))
defer eventsWG.Done()
defer func() { <-sem }()
- goUpdated, textUpdated, err := fseh.HandleEvent(ctx, event)
+ r, err := fseh.HandleEvent(ctx, event)
if err != nil {
errs <- err
}
- if goUpdated || textUpdated {
+ if r.GoUpdated || r.TextUpdated {
postGeneration <- &GenerationEvent{
Event: event,
- GoUpdated: goUpdated,
- TextUpdated: textUpdated,
+ Updated: r.Updated,
+ GoUpdated: r.GoUpdated,
+ TextUpdated: r.TextUpdated,
}
}
}(event)
@@ -273,6 +276,9 @@ func (cmd Generate) Run(ctx context.Context) (err error) {
postGenerationEventsWG.Add(1)
if cmd.Args.Command != "" && goUpdated {
cmd.Log.Debug("Executing command", slog.String("command", cmd.Args.Command))
+ if cmd.Args.Watch {
+ os.Setenv("TEMPL_DEV_MODE", "true")
+ }
if _, err := run.Run(ctx, cmd.Args.Path, cmd.Args.Command); err != nil {
cmd.Log.Error("Error executing command", slog.Any("error", err))
}
diff --git a/cmd/templ/generatecmd/eventhandler.go b/cmd/templ/generatecmd/eventhandler.go
index 841670a09..82224eb43 100644
--- a/cmd/templ/generatecmd/eventhandler.go
+++ b/cmd/templ/generatecmd/eventhandler.go
@@ -57,18 +57,17 @@ func NewFSEventHandler(
fileNameToLastModTimeMutex: &sync.Mutex{},
fileNameToError: make(map[string]struct{}),
fileNameToErrorMutex: &sync.Mutex{},
+ fileNameToOutput: make(map[string]generator.GeneratorOutput),
+ fileNameToOutputMutex: &sync.Mutex{},
+ devMode: devMode,
hashes: make(map[string][sha256.Size]byte),
hashesMutex: &sync.Mutex{},
genOpts: genOpts,
genSourceMapVis: genSourceMapVis,
- DevMode: devMode,
keepOrphanedFiles: keepOrphanedFiles,
writer: fileWriter,
lazy: lazy,
}
- if devMode {
- fseh.genOpts = append(fseh.genOpts, generator.WithExtractStrings())
- }
return fseh
}
@@ -80,71 +79,84 @@ type FSEventHandler struct {
fileNameToLastModTimeMutex *sync.Mutex
fileNameToError map[string]struct{}
fileNameToErrorMutex *sync.Mutex
+ fileNameToOutput map[string]generator.GeneratorOutput
+ fileNameToOutputMutex *sync.Mutex
+ devMode bool
hashes map[string][sha256.Size]byte
hashesMutex *sync.Mutex
genOpts []generator.GenerateOpt
genSourceMapVis bool
- DevMode bool
Errors []error
keepOrphanedFiles bool
writer func(string, []byte) error
lazy bool
}
-func (h *FSEventHandler) HandleEvent(ctx context.Context, event fsnotify.Event) (goUpdated, textUpdated bool, err error) {
+type GenerateResult struct {
+ // Updated indicates that the file was updated.
+ Updated bool
+ // GoUpdated indicates that Go expressions were updated.
+ GoUpdated bool
+ // TextUpdated indicates that text literals were updated.
+ TextUpdated bool
+}
+
+func (h *FSEventHandler) HandleEvent(ctx context.Context, event fsnotify.Event) (result GenerateResult, err error) {
// Handle _templ.go files.
if !event.Has(fsnotify.Remove) && strings.HasSuffix(event.Name, "_templ.go") {
_, err = os.Stat(strings.TrimSuffix(event.Name, "_templ.go") + ".templ")
if !os.IsNotExist(err) {
- return false, false, err
+ return GenerateResult{}, err
}
// File is orphaned.
if h.keepOrphanedFiles {
- return false, false, nil
+ return GenerateResult{}, nil
}
h.Log.Debug("Deleting orphaned Go file", slog.String("file", event.Name))
if err = os.Remove(event.Name); err != nil {
h.Log.Warn("Failed to remove orphaned file", slog.Any("error", err))
}
- return true, false, nil
+ return GenerateResult{Updated: true, GoUpdated: true, TextUpdated: false}, nil
}
// Handle _templ.txt files.
if !event.Has(fsnotify.Remove) && strings.HasSuffix(event.Name, "_templ.txt") {
- if h.DevMode {
- // Don't delete the file if we're in dev mode, but mark that text was updated.
- return false, true, nil
+ if h.devMode {
+ // Don't delete the file in dev mode, ignore changes to it, since the .templ file
+ // must have been updated in order to trigger a change in the _templ.txt file.
+ return GenerateResult{Updated: false, GoUpdated: false, TextUpdated: false}, nil
}
h.Log.Debug("Deleting watch mode file", slog.String("file", event.Name))
if err = os.Remove(event.Name); err != nil {
h.Log.Warn("Failed to remove watch mode text file", slog.Any("error", err))
- return false, false, nil
+ return GenerateResult{}, nil
}
- return false, false, nil
+ return GenerateResult{}, nil
}
// Handle .templ files.
if !strings.HasSuffix(event.Name, ".templ") {
- return false, false, nil
+ return GenerateResult{}, nil
}
// If the file hasn't been updated since the last time we processed it, ignore it.
lastModTime, updatedModTime := h.UpsertLastModTime(event.Name)
if !updatedModTime {
h.Log.Debug("Skipping file because it wasn't updated", slog.String("file", event.Name))
- return false, false, nil
+ return GenerateResult{}, nil
}
// If the go file is newer than the templ file, skip generation, because it's up-to-date.
if h.lazy && goFileIsUpToDate(event.Name, lastModTime) {
h.Log.Debug("Skipping file because the Go file is up-to-date", slog.String("file", event.Name))
- return false, false, nil
+ return GenerateResult{}, nil
}
// Start a processor.
start := time.Now()
- goUpdated, textUpdated, diag, err := h.generate(ctx, event.Name)
+ var diag []parser.Diagnostic
+ result, diag, err = h.generate(ctx, event.Name)
if err != nil {
h.SetError(event.Name, true)
- return goUpdated, textUpdated, fmt.Errorf("failed to generate code for %q: %w", event.Name, err)
+ return result, fmt.Errorf("failed to generate code for %q: %w", event.Name, err)
}
if len(diag) > 0 {
for _, d := range diag {
@@ -153,14 +165,14 @@ func (h *FSEventHandler) HandleEvent(ctx context.Context, event fsnotify.Event)
slog.String("to", fmt.Sprintf("%d:%d", d.Range.To.Line, d.Range.To.Col)),
)
}
- return
+ return result, nil
}
if errorCleared, errorCount := h.SetError(event.Name, false); errorCleared {
h.Log.Info("Error cleared", slog.String("file", event.Name), slog.Int("errors", errorCount))
}
h.Log.Debug("Generated code", slog.String("file", event.Name), slog.Duration("in", time.Since(start)))
- return goUpdated, textUpdated, nil
+ return result, nil
}
func goFileIsUpToDate(templFileName string, templFileLastMod time.Time) (upToDate bool) {
@@ -212,68 +224,78 @@ func (h *FSEventHandler) UpsertHash(fileName string, hash [sha256.Size]byte) (up
// generate Go code for a single template.
// If a basePath is provided, the filename included in error messages is relative to it.
-func (h *FSEventHandler) generate(ctx context.Context, fileName string) (goUpdated, textUpdated bool, diagnostics []parser.Diagnostic, err error) {
+func (h *FSEventHandler) generate(ctx context.Context, fileName string) (result GenerateResult, diagnostics []parser.Diagnostic, err error) {
t, err := parser.Parse(fileName)
if err != nil {
- return false, false, nil, fmt.Errorf("%s parsing error: %w", fileName, err)
+ return GenerateResult{}, nil, fmt.Errorf("%s parsing error: %w", fileName, err)
}
targetFileName := strings.TrimSuffix(fileName, ".templ") + "_templ.go"
// Only use relative filenames to the basepath for filenames in runtime error messages.
absFilePath, err := filepath.Abs(fileName)
if err != nil {
- return false, false, nil, fmt.Errorf("failed to get absolute path for %q: %w", fileName, err)
+ return GenerateResult{}, nil, fmt.Errorf("failed to get absolute path for %q: %w", fileName, err)
}
relFilePath, err := filepath.Rel(h.dir, absFilePath)
if err != nil {
- return false, false, nil, fmt.Errorf("failed to get relative path for %q: %w", fileName, err)
+ return GenerateResult{}, nil, fmt.Errorf("failed to get relative path for %q: %w", fileName, err)
}
// Convert Windows file paths to Unix-style for consistency.
relFilePath = filepath.ToSlash(relFilePath)
var b bytes.Buffer
- sourceMap, literals, err := generator.Generate(t, &b, append(h.genOpts, generator.WithFileName(relFilePath))...)
+ generatorOutput, err := generator.Generate(t, &b, append(h.genOpts, generator.WithFileName(relFilePath))...)
if err != nil {
- return false, false, nil, fmt.Errorf("%s generation error: %w", fileName, err)
+ return GenerateResult{}, nil, fmt.Errorf("%s generation error: %w", fileName, err)
}
formattedGoCode, err := format.Source(b.Bytes())
if err != nil {
- err = remapErrorList(err, sourceMap, fileName)
- return false, false, nil, fmt.Errorf("% source formatting error %w", fileName, err)
+ err = remapErrorList(err, generatorOutput.SourceMap, fileName)
+ return GenerateResult{}, nil, fmt.Errorf("%s source formatting error %w", fileName, err)
}
// Hash output, and write out the file if the goCodeHash has changed.
goCodeHash := sha256.Sum256(formattedGoCode)
if h.UpsertHash(targetFileName, goCodeHash) {
- goUpdated = true
+ result.Updated = true
if err = h.writer(targetFileName, formattedGoCode); err != nil {
- return false, false, nil, fmt.Errorf("failed to write target file %q: %w", targetFileName, err)
+ return result, nil, fmt.Errorf("failed to write target file %q: %w", targetFileName, err)
}
}
// Add the txt file if it has changed.
- if len(literals) > 0 {
+ if h.devMode {
txtFileName := strings.TrimSuffix(fileName, ".templ") + "_templ.txt"
- txtHash := sha256.Sum256([]byte(literals))
+ joined := strings.Join(generatorOutput.Literals, "\n")
+ txtHash := sha256.Sum256([]byte(joined))
if h.UpsertHash(txtFileName, txtHash) {
- textUpdated = true
- if err = os.WriteFile(txtFileName, []byte(literals), 0o644); err != nil {
- return false, false, nil, fmt.Errorf("failed to write string literal file %q: %w", txtFileName, err)
+ result.TextUpdated = true
+ if err = os.WriteFile(txtFileName, []byte(joined), 0o644); err != nil {
+ return result, nil, fmt.Errorf("failed to write string literal file %q: %w", txtFileName, err)
+ }
+
+ // Check whether the change would require a recompilation to take effect.
+ h.fileNameToOutputMutex.Lock()
+ defer h.fileNameToOutputMutex.Unlock()
+ previous := h.fileNameToOutput[fileName]
+ if generator.HasChanged(previous, generatorOutput) {
+ result.GoUpdated = true
}
+ h.fileNameToOutput[fileName] = generatorOutput
}
}
parsedDiagnostics, err := parser.Diagnose(t)
if err != nil {
- return goUpdated, textUpdated, nil, fmt.Errorf("%s diagnostics error: %w", fileName, err)
+ return result, nil, fmt.Errorf("%s diagnostics error: %w", fileName, err)
}
if h.genSourceMapVis {
- err = generateSourceMapVisualisation(ctx, fileName, targetFileName, sourceMap)
+ err = generateSourceMapVisualisation(ctx, fileName, targetFileName, generatorOutput.SourceMap)
}
- return goUpdated, textUpdated, parsedDiagnostics, err
+ return result, parsedDiagnostics, err
}
// Takes an error from the formatter and attempts to convert the positions reported in the target file to their positions
diff --git a/cmd/templ/generatecmd/run/run_unix.go b/cmd/templ/generatecmd/run/run_unix.go
index 68f8d6724..f2f4bfbce 100644
--- a/cmd/templ/generatecmd/run/run_unix.go
+++ b/cmd/templ/generatecmd/run/run_unix.go
@@ -52,7 +52,7 @@ func ignoreExited(err error) error {
return err
}
-func Run(ctx context.Context, workingDir, input string) (cmd *exec.Cmd, err error) {
+func Run(ctx context.Context, workingDir string, input string) (cmd *exec.Cmd, err error) {
m.Lock()
defer m.Unlock()
cmd, ok := running[input]
diff --git a/cmd/templ/generatecmd/run/run_windows.go b/cmd/templ/generatecmd/run/run_windows.go
index f96a06c70..0a79032b1 100644
--- a/cmd/templ/generatecmd/run/run_windows.go
+++ b/cmd/templ/generatecmd/run/run_windows.go
@@ -37,7 +37,7 @@ func Stop(cmd *exec.Cmd) (err error) {
return kill.Run()
}
-func Run(ctx context.Context, workingDir, input string) (cmd *exec.Cmd, err error) {
+func Run(ctx context.Context, workingDir string, input string) (cmd *exec.Cmd, err error) {
m.Lock()
defer m.Unlock()
cmd, ok := running[input]
diff --git a/cmd/templ/generatecmd/test-eventhandler/eventhandler_test.go b/cmd/templ/generatecmd/test-eventhandler/eventhandler_test.go
index 5e3e2d335..8c1319921 100644
--- a/cmd/templ/generatecmd/test-eventhandler/eventhandler_test.go
+++ b/cmd/templ/generatecmd/test-eventhandler/eventhandler_test.go
@@ -63,7 +63,7 @@ func TestErrorLocationMapping(t *testing.T) {
}
event := fsnotify.Event{Name: file.Name(), Op: fsnotify.Write}
- _, _, err = fseh.HandleEvent(context.Background(), event)
+ _, err = fseh.HandleEvent(context.Background(), event)
if err == nil {
t.Errorf("%s: no error was thrown", test.name)
break
diff --git a/cmd/templ/generatecmd/testwatch/generate_test.go b/cmd/templ/generatecmd/testwatch/generate_test.go
index b97437767..70f4bd550 100644
--- a/cmd/templ/generatecmd/testwatch/generate_test.go
+++ b/cmd/templ/generatecmd/testwatch/generate_test.go
@@ -394,12 +394,12 @@ func Setup(gzipEncoding bool) (args TestArgs, teardown func(t *testing.T), err e
if err = waitForURL(args.AppURL); err != nil {
cancel()
wg.Wait()
- return args, teardown, fmt.Errorf("failed to start app server: %v", err)
+ return args, teardown, fmt.Errorf("failed to start app server, command error %v: %w", cmdErr, err)
}
if err = waitForURL(args.ProxyURL); err != nil {
cancel()
wg.Wait()
- return args, teardown, fmt.Errorf("failed to start proxy server: %v", err)
+ return args, teardown, fmt.Errorf("failed to start proxy server, command error %v: %w", cmdErr, err)
}
// Wait for exit.
diff --git a/cmd/templ/generatecmd/testwatch/testdata/main.go b/cmd/templ/generatecmd/testwatch/testdata/main.go
index 8b4d150bf..8ffd85d71 100644
--- a/cmd/templ/generatecmd/testwatch/testdata/main.go
+++ b/cmd/templ/generatecmd/testwatch/testdata/main.go
@@ -5,6 +5,7 @@ import (
"compress/gzip"
"flag"
"fmt"
+ "log/slog"
"net/http"
"os"
"strconv"
@@ -63,7 +64,14 @@ func main() {
count++
c := Page(count)
- templ.Handler(c).ServeHTTP(w, r)
+ h := templ.Handler(c)
+ h.ErrorHandler = func(r *http.Request, err error) http.Handler {
+ slog.Error("failed to render template", slog.Any("error", err))
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ })
+ }
+ h.ServeHTTP(w, r)
})
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", *flagPort), nil)
if err != nil {
diff --git a/cmd/templ/generatecmd/testwatch/testdata/templates_templ.go b/cmd/templ/generatecmd/testwatch/testdata/templates_templ.go
index 938618f6f..508897f35 100644
--- a/cmd/templ/generatecmd/testwatch/testdata/templates_templ.go
+++ b/cmd/templ/generatecmd/testwatch/testdata/templates_templ.go
@@ -30,7 +30,7 @@ func Page(count int) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("templ test pageCount
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
templ test pageCount
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -43,7 +43,7 @@ func Page(count int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Original
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
Original
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/cmd/templ/imports/process.go b/cmd/templ/imports/process.go
index d3ccbe770..7ceb57863 100644
--- a/cmd/templ/imports/process.go
+++ b/cmd/templ/imports/process.go
@@ -79,7 +79,7 @@ func Process(t parser.TemplateFile) (parser.TemplateFile, error) {
var updatedImports []*ast.ImportSpec
var eg errgroup.Group
eg.Go(func() (err error) {
- if _, _, err := generator.Generate(t, gw); err != nil {
+ if _, err := generator.Generate(t, gw); err != nil {
return fmt.Errorf("failed to generate go code: %w", err)
}
updatedImports, err = updateImports(fileName, gw.String())
diff --git a/cmd/templ/lspcmd/httpdebug/list_templ.go b/cmd/templ/lspcmd/httpdebug/list_templ.go
index 49b64413c..5ee3ede5f 100644
--- a/cmd/templ/lspcmd/httpdebug/list_templ.go
+++ b/cmd/templ/lspcmd/httpdebug/list_templ.go
@@ -28,12 +28,12 @@ func list(uris []string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("File | | | | |
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "File | | | | |
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, uri := range uris {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " |
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -46,7 +46,7 @@ func list(uris []string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | | Mapping | Mapping | Source Map | Source Map | Templ | Templ | Go |
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\">Go")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go
index 6599e17ce..d7a1d36bf 100644
--- a/cmd/templ/lspcmd/proxy/server.go
+++ b/cmd/templ/lspcmd/proxy/server.go
@@ -111,16 +111,19 @@ func (p *Server) convertGoRangeToTemplRange(templURI lsp.DocumentURI, input lsp.
return
}
// Map from the source position to target Go position.
- start, ok := sourceMap.SourcePositionFromTarget(input.Start.Line, input.Start.Character)
- if ok {
+ start, startPositionMapped := sourceMap.SourcePositionFromTarget(input.Start.Line, input.Start.Character)
+ if startPositionMapped {
output.Start.Line = start.Line
output.Start.Character = start.Col
}
- end, ok := sourceMap.SourcePositionFromTarget(input.End.Line, input.End.Character)
- if ok {
+ end, endPositionMapped := sourceMap.SourcePositionFromTarget(input.End.Line, input.End.Character)
+ if endPositionMapped {
output.End.Line = end.Line
output.End.Character = end.Col
}
+ if !startPositionMapped || !endPositionMapped {
+ p.Log.Warn("go->templ: range not found in sourcemap", zap.Any("range", input))
+ }
return
}
@@ -265,12 +268,12 @@ func (p *Server) Initialize(ctx context.Context, params *lsp.InitializeParams) (
return nil
}
w := new(strings.Builder)
- sm, _, err := generator.Generate(template, w)
+ generatorOutput, err := generator.Generate(template, w)
if err != nil {
return fmt.Errorf("generate failure: %w", err)
}
p.Log.Info("setting source map cache contents", zap.String("uri", string(uri)))
- p.SourceMapCache.Set(string(uri), sm)
+ p.SourceMapCache.Set(string(uri), generatorOutput.SourceMap)
// Set the Go contents.
p.GoSource[string(uri)] = w.String()
@@ -667,14 +670,14 @@ func (p *Server) DidChange(ctx context.Context, params *lsp.DidChangeTextDocumen
//
// This change would increase the surface area of gopls that we use, so may surface a number of issues
// if enabled.
- sm, _, err := generator.Generate(template, w)
+ generatorOutput, err := generator.Generate(template, w)
if err != nil {
p.Log.Error("generate failure", zap.Error(err))
return
}
// Cache the sourcemap.
p.Log.Info("setting cache", zap.String("uri", string(params.TextDocument.URI)))
- p.SourceMapCache.Set(string(params.TextDocument.URI), sm)
+ p.SourceMapCache.Set(string(params.TextDocument.URI), generatorOutput.SourceMap)
p.GoSource[string(params.TextDocument.URI)] = w.String()
// Change the path.
params.TextDocument.URI = goURI
@@ -740,12 +743,12 @@ func (p *Server) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocumentPar
// Generate the output code and cache the source map and Go contents to use during completion
// requests.
w := new(strings.Builder)
- sm, _, err := generator.Generate(template, w)
+ generatorOutput, err := generator.Generate(template, w)
if err != nil {
return
}
p.Log.Info("setting source map cache contents", zap.String("uri", string(params.TextDocument.URI)))
- p.SourceMapCache.Set(string(params.TextDocument.URI), sm)
+ p.SourceMapCache.Set(string(params.TextDocument.URI), generatorOutput.SourceMap)
// Set the Go contents.
params.TextDocument.Text = w.String()
p.GoSource[string(params.TextDocument.URI)] = params.TextDocument.Text
@@ -837,16 +840,6 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP
return nil, err
}
- // recursively convert the ranges of the symbols and their children
- var convertRange func(s *lsp.DocumentSymbol)
- convertRange = func(s *lsp.DocumentSymbol) {
- s.Range = p.convertGoRangeToTemplRange(templURI, s.Range)
- s.SelectionRange = p.convertGoRangeToTemplRange(templURI, s.SelectionRange)
- for i := 0; i < len(s.Children); i++ {
- convertRange(&s.Children[i])
- }
- }
-
for _, s := range symbols {
if m, ok := s.(map[string]interface{}); ok {
s, err = mapToSymbol(m)
@@ -856,7 +849,7 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP
}
switch s := s.(type) {
case lsp.DocumentSymbol:
- convertRange(&s)
+ p.convertSymbolRange(templURI, &s)
result = append(result, s)
case lsp.SymbolInformation:
s.Location.URI = templURI
@@ -868,6 +861,54 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP
return result, err
}
+func (p *Server) convertSymbolRange(templURI lsp.DocumentURI, s *lsp.DocumentSymbol) {
+ sourceMap, ok := p.SourceMapCache.Get(string(templURI))
+ if !ok {
+ p.Log.Warn("go->templ: sourcemap not found in cache")
+ return
+ }
+ src, ok := sourceMap.SymbolSourceRangeFromTarget(s.Range.Start.Line, s.Range.Start.Character)
+ if !ok {
+ p.Log.Warn("go->templ: symbol range not found", zap.Any("symbol", s), zap.Any("choices", sourceMap.TargetSymbolRangeToSource))
+ return
+ }
+ s.Range = lsp.Range{
+ Start: lsp.Position{
+ Line: uint32(src.From.Line),
+ Character: uint32(src.From.Col),
+ },
+ End: lsp.Position{
+ Line: uint32(src.To.Line),
+ Character: uint32(src.To.Col),
+ },
+ }
+ // Within the symbol, we can select sub-sections.
+ // These are Go expressions, in the standard source map.
+ s.SelectionRange = p.convertGoRangeToTemplRange(templURI, s.SelectionRange)
+ for i := 0; i < len(s.Children); i++ {
+ p.convertSymbolRange(templURI, &s.Children[i])
+ if !isRangeWithin(s.Range, s.Children[i].Range) {
+ p.Log.Error("child symbol range not within parent range", zap.Any("symbol", s.Children[i]), zap.Int("index", i))
+ }
+ }
+ if !isRangeWithin(s.Range, s.SelectionRange) {
+ p.Log.Error("selection range not within range", zap.Any("symbol", s))
+ }
+}
+
+func isRangeWithin(parent, child lsp.Range) bool {
+ if child.Start.Line < parent.Start.Line || child.End.Line > parent.End.Line {
+ return false
+ }
+ if child.Start.Line == parent.Start.Line && child.Start.Character < parent.Start.Character {
+ return false
+ }
+ if child.End.Line == parent.End.Line && child.End.Character > parent.End.Character {
+ return false
+ }
+ return true
+}
+
func (p *Server) ExecuteCommand(ctx context.Context, params *lsp.ExecuteCommandParams) (result interface{}, err error) {
p.Log.Info("client -> server: ExecuteCommand")
defer p.Log.Info("client -> server: ExecuteCommand end")
diff --git a/cmd/templ/testproject/testdata/remotechild_templ.go b/cmd/templ/testproject/testdata/remotechild_templ.go
index 2544e0425..26448c999 100644
--- a/cmd/templ/testproject/testdata/remotechild_templ.go
+++ b/cmd/templ/testproject/testdata/remotechild_templ.go
@@ -28,7 +28,7 @@ func Remote() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("This is remote content
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "This is remote content
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/cmd/templ/testproject/testdata/templates_templ.go b/cmd/templ/testproject/testdata/templates_templ.go
index 2bffb2427..176ba6055 100644
--- a/cmd/templ/testproject/testdata/templates_templ.go
+++ b/cmd/templ/testproject/testdata/templates_templ.go
@@ -30,7 +30,7 @@ func Page(count int) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("templ test pageCount
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
templ test pageCount
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -43,7 +43,7 @@ func Page(count int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Original
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
Original
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/cmd/templ/visualize/sourcemapvisualisation_templ.go b/cmd/templ/visualize/sourcemapvisualisation_templ.go
index 1793a8be8..35b25ebfd 100644
--- a/cmd/templ/visualize/sourcemapvisualisation_templ.go
+++ b/cmd/templ/visualize/sourcemapvisualisation_templ.go
@@ -60,7 +60,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -73,7 +73,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("- Source Map Visualisation")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "- Source Map Visualisation")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -86,7 +86,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -95,7 +95,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -117,7 +117,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -138,7 +138,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -147,7 +147,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -168,7 +168,7 @@ func combine(templFileName string, left, right templ.Component) templ.Component
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -240,7 +240,7 @@ func mappedCharacter(s string, sourceID, targetID string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -284,7 +284,7 @@ func mappedCharacter(s string, sourceID, targetID string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/examples/blog/posts_templ.go b/examples/blog/posts_templ.go
index 29c560b64..b93352d57 100644
--- a/examples/blog/posts_templ.go
+++ b/examples/blog/posts_templ.go
@@ -33,7 +33,7 @@ func headerTemplate(name string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -46,7 +46,7 @@ func headerTemplate(name string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -75,7 +75,7 @@ func footerTemplate() templ.Component {
templ_7745c5c3_Var3 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -117,7 +117,7 @@ func navTemplate() templ.Component {
templ_7745c5c3_Var5 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -146,7 +146,7 @@ func layout(name string) templ.Component {
templ_7745c5c3_Var6 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -159,7 +159,7 @@ func layout(name string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -171,7 +171,7 @@ func layout(name string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -179,7 +179,7 @@ func layout(name string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -187,7 +187,7 @@ func layout(name string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -216,12 +216,12 @@ func postsTemplate(posts []Post) templ.Component {
templ_7745c5c3_Var8 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, p := range posts {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -234,7 +234,7 @@ func postsTemplate(posts []Post) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -247,12 +247,12 @@ func postsTemplate(posts []Post) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -293,7 +293,7 @@ func home() templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Welcome to my website.
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "Welcome to my website.
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/examples/counter-basic/components_templ.go b/examples/counter-basic/components_templ.go
index 38234dcb1..2a961d7f4 100644
--- a/examples/counter-basic/components_templ.go
+++ b/examples/counter-basic/components_templ.go
@@ -30,7 +30,7 @@ func counts(global, user int) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Global: ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
Global: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -43,7 +43,7 @@ func counts(global, user int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
User: ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
User: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -56,7 +56,7 @@ func counts(global, user int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -85,7 +85,7 @@ func form() templ.Component {
templ_7745c5c3_Var4 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -114,7 +114,7 @@ func page(global, user int) templ.Component {
templ_7745c5c3_Var5 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Counts")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "
Counts")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -126,7 +126,7 @@ func page(global, user int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/examples/counter/components/components_templ.go b/examples/counter/components/components_templ.go
index e2f134159..e1c3d6c65 100644
--- a/examples/counter/components/components_templ.go
+++ b/examples/counter/components/components_templ.go
@@ -44,7 +44,7 @@ func counts(global, session int) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "Session
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -143,7 +143,7 @@ func Page(global, session int) templ.Component {
templ_7745c5c3_Var8 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Counts")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
Counts")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -151,7 +151,7 @@ func Page(global, session int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/examples/counter/go.mod b/examples/counter/go.mod
index a143c45e5..a371da342 100644
--- a/examples/counter/go.mod
+++ b/examples/counter/go.mod
@@ -44,9 +44,10 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/yuin/goldmark v1.7.4 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
- golang.org/x/mod v0.18.0 // indirect
- golang.org/x/sys v0.21.0 // indirect
- golang.org/x/tools v0.22.0 // indirect
+ golang.org/x/mod v0.20.0 // indirect
+ golang.org/x/sync v0.8.0 // indirect
+ golang.org/x/sys v0.23.0 // indirect
+ golang.org/x/tools v0.24.0 // indirect
)
replace github.com/a-h/templ => ../../
diff --git a/examples/counter/go.sum b/examples/counter/go.sum
index feac4512b..3e574d8f4 100644
--- a/examples/counter/go.sum
+++ b/examples/counter/go.sum
@@ -84,23 +84,23 @@ golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXy
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
-golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
-golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
+golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
-golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
+golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
-golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
+golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
-golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
-golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
+golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
+golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
diff --git a/examples/counter/lambda/main.go b/examples/counter/lambda/main.go
index 861f5a37b..91cdc16d3 100644
--- a/examples/counter/lambda/main.go
+++ b/examples/counter/lambda/main.go
@@ -13,7 +13,7 @@ import (
func main() {
// Create handlers.
- log := slog.New(slog.NewJSONHandler(os.Stderr))
+ log := slog.New(slog.NewJSONHandler(os.Stderr, nil))
s, err := db.NewCountStore(os.Getenv("TABLE_NAME"), os.Getenv("AWS_REGION"))
if err != nil {
log.Error("failed to create store", slog.Any("error", err))
diff --git a/examples/external-libraries/components_templ.go b/examples/external-libraries/components_templ.go
index c2d9108f1..a5597cd66 100644
--- a/examples/external-libraries/components_templ.go
+++ b/examples/external-libraries/components_templ.go
@@ -40,7 +40,7 @@ func page(data []TimeValue) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Graphs")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Graphs")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -48,7 +48,7 @@ func page(data []TimeValue) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\">