Skip to content

Commit 6ea47ff

Browse files
committed
fix: watch mode only detects Go code changes if text also changes
Closes #960
1 parent 8565703 commit 6ea47ff

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.828
1+
0.3.828

cmd/templ/generatecmd/cmd.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,18 @@ func (cmd Generate) Run(ctx context.Context) (err error) {
226226
if err != nil {
227227
errs <- err
228228
}
229-
if r.GoUpdated || r.TextUpdated {
230-
postGeneration <- &GenerationEvent{
231-
Event: event,
232-
Updated: r.Updated,
233-
GoUpdated: r.GoUpdated,
234-
TextUpdated: r.TextUpdated,
235-
}
229+
if !(r.GoUpdated || r.TextUpdated) {
230+
cmd.Log.Debug("File not updated", slog.String("file", event.Name))
231+
return
232+
}
233+
e := &GenerationEvent{
234+
Event: event,
235+
Updated: r.Updated,
236+
GoUpdated: r.GoUpdated,
237+
TextUpdated: r.TextUpdated,
236238
}
239+
cmd.Log.Debug("File updated", slog.String("file", event.Name))
240+
postGeneration <- e
237241
}(event)
238242
}
239243
// Wait for all events to be processed before closing.

cmd/templ/generatecmd/eventhandler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,16 @@ func (h *FSEventHandler) generate(ctx context.Context, fileName string) (result
282282
if err = os.WriteFile(txtFileName, []byte(joined), 0o644); err != nil {
283283
return result, nil, fmt.Errorf("failed to write string literal file %q: %w", txtFileName, err)
284284
}
285+
}
285286

286-
// Check whether the change would require a recompilation to take effect.
287-
h.fileNameToOutputMutex.Lock()
288-
defer h.fileNameToOutputMutex.Unlock()
289-
previous := h.fileNameToOutput[fileName]
290-
if generator.HasChanged(previous, generatorOutput) {
291-
result.GoUpdated = true
292-
}
293-
h.fileNameToOutput[fileName] = generatorOutput
287+
// Check whether the change would require a recompilation to take effect.
288+
h.fileNameToOutputMutex.Lock()
289+
defer h.fileNameToOutputMutex.Unlock()
290+
previous := h.fileNameToOutput[fileName]
291+
if generator.HasChanged(previous, generatorOutput) {
292+
result.GoUpdated = true
294293
}
294+
h.fileNameToOutput[fileName] = generatorOutput
295295
}
296296

297297
parsedDiagnostics, err := parser.Diagnose(t)

0 commit comments

Comments
 (0)