Skip to content

Commit

Permalink
fix: watch mode only detects Go code changes if text also changes
Browse files Browse the repository at this point in the history
Closes #960
  • Loading branch information
a-h committed Jan 22, 2025
1 parent 8565703 commit 6ea47ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.828
0.3.828
18 changes: 11 additions & 7 deletions cmd/templ/generatecmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,18 @@ func (cmd Generate) Run(ctx context.Context) (err error) {
if err != nil {
errs <- err
}
if r.GoUpdated || r.TextUpdated {
postGeneration <- &GenerationEvent{
Event: event,
Updated: r.Updated,
GoUpdated: r.GoUpdated,
TextUpdated: r.TextUpdated,
}
if !(r.GoUpdated || r.TextUpdated) {
cmd.Log.Debug("File not updated", slog.String("file", event.Name))
return
}
e := &GenerationEvent{
Event: event,
Updated: r.Updated,
GoUpdated: r.GoUpdated,
TextUpdated: r.TextUpdated,
}
cmd.Log.Debug("File updated", slog.String("file", event.Name))
postGeneration <- e
}(event)
}
// Wait for all events to be processed before closing.
Expand Down
16 changes: 8 additions & 8 deletions cmd/templ/generatecmd/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,16 @@ func (h *FSEventHandler) generate(ctx context.Context, fileName string) (result
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
// 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)
Expand Down

0 comments on commit 6ea47ff

Please sign in to comment.