Skip to main content

Module file_watcher

Module file_watcher 

Source
Expand description

File-watcher subscription compilation + matching (4.4.l).

Servers dynamically register workspace/didChangeWatchedFiles via client/registerCapability (the matrix entry for that method in docs/dev/notes/lsp-features.md). Each registration carries a DidChangeWatchedFilesRegistrationOptions containing a list of FileSystemWatcher { glob_pattern, kind }.

This module is the pure piece of the file-watcher pipeline: it walks the dynamic registry, compiles each registration’s patterns into a globset::GlobSet, and produces a per-server WatcherSubscriptions snapshot. The fs-event source itself (the notify crate driver, debounce timer, fan-out) lives in lattice-ui-tui::app::lsp_watcher; that module imports WatcherSubscriptions and asks “does this absolute path match any registered glob, and if so what FileChangeType do we synthesise?”.

Keeping the pure parts here means:

  1. The matching logic is testable in isolation (no fs integration in unit tests; no notify runtime).
  2. Future renderers (GPU, web) reuse the same compilation path – only the event source changes.
  3. Plugins that want to participate in watched-file dispatch (post-1.0 WIT bridge) see one shape, not a tui-only one.

§Glob semantics

LSP 3.17 GlobPattern is either:

  • a plain string (workspace-relative globs like **/*.rs), or
  • a RelativePattern { base_uri, pattern } where base_uri anchors the pattern to a specific workspace folder or URI.

We normalise both shapes to (base, pattern) – the pure string case anchors to the server’s workspace root supplied at compile time; relative patterns honour their declared base. WatchKind defaults to Create|Change|Delete (= 7) when omitted, per spec.

§Path conventions

Glob matching runs against the path relative to the subscription’s base. Absolute paths are normalised by stripping the base prefix before matching; paths outside the base never match a relative-anchored pattern. This matches VSCode’s behaviour, which is what most servers exercise their globs against.

Structs§

WatcherSubscriptions
Snapshot of every active file-watcher registration for one server. Built by compile_for_server from the dynamic registry; consumed by the host’s notify-driven dispatcher.

Functions§

compile_for_server
Compile the dynamic-registration entries on caps for the given server_id into a WatcherSubscriptions snapshot. workspace_root is the absolute path the server was attached to; plain-string globs (no RelativePattern base) anchor here.
compile_with_workspace_root
Build a WatcherSubscriptions whose plain-string globs all anchor to workspace_root. The bare compile_for_server captures the path verbatim because some callers (tests, future per-folder workspace roots) want a custom anchor. Public entry-point most call sites use.