watch

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package watch implements the daemon mode: format every source file as soon as anything finishes writing it.

Three things make this safe, and all three are things hand-rolled watchexec/entr pipelines get wrong:

  • Self-writes are recognised by content, not by timing. See internal/engine/selfwrite.go.
  • A file is only formatted once it has stopped changing. The debounce timer is reset by every new event, and after it fires the file is read twice with a settle gap; if the two reads differ, the write is still in progress and the timer starts again.
  • Even if both of those were defeated, a partially written file does not parse, the formatter exits non-zero, and the engine writes nothing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Debounce is how long a file must be quiet before it is formatted.
	Debounce time.Duration
	// Settle is the gap between the two verification reads.
	Settle time.Duration
	// Workers bounds concurrent formatting.
	Workers int
	// OnResult is called for every file the watcher acts on.
	OnResult func(engine.Result)
	// OnReady is called once the initial tree walk has finished and the
	// watcher is live.
	OnReady func(dirs int)
	// Log receives progress.
	Log engine.Logger
}

Options tune the watcher.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher formats files under a root as they are written.

func New

func New(root string, eng *engine.Engine, ign *scan.Ignorer, proj *detect.Project, opts Options) *Watcher

New builds a Watcher.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run watches until ctx is cancelled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL