Skip to content

fix: File watcher should watch directories recursively - #21771

Merged
Veykril merged 1 commit into
rust-lang:masterfrom
Wilfred:watch_dirs_recursively
Mar 10, 2026
Merged

Veykril merged 1 commit into
rust-lang:masterfrom
Wilfred:watch_dirs_recursively

Conversation

@Wilfred

@Wilfred Wilfred commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Currently rust-analyzer only watches the directory itself, and doesn't consider children recursively.

This is a problem when the directory itself is deleted and recreated (e.g. if you're creating all of mycrate/src/ with a code generating script). The obvious solution is to configure rust-analyzer to watch the parent directory (assuming rust-project.json), but that requires recursive watching.

This problem probably also occurs when switching between git commits.

Instead, watch directories recursively so we can use the file watcher with parent directories.

See also discussion on #19907.

I've tested on some decent sized projects (several hundred transitive dependencies) and performance seemed fine.

Currently rust-analyzer only watches the directory itself, and doesn't
consider children recursively.

This is a problem when the directory itself is deleted and
recreated (e.g. if you're creating all of `mycrate/src/` with a code
generating script). The obvious solution is to configure rust-analyzer
to watch the parent directory (assuming rust-project.json), but that
requires recursive watching.

This problem probably also occurs when switching between git commits.

Instead, watch directories recursively so we can use the file watcher
with parent directories.

See also discussion on rust-lang#19907.

I've tested on some decent sized projects (several hundred transitive
dependencies) and performance seemed fine.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 6, 2026

@Veykril Veykril left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see how this goes

View changes since this review

@Veykril
Veykril added this pull request to the merge queue Mar 10, 2026
Merged via the queue into rust-lang:master with commit 3e832f3 Mar 10, 2026
17 of 18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2026
@Wilfred
Wilfred deleted the watch_dirs_recursively branch March 12, 2026 14:24
scovich added a commit to scovich/rust-analyzer that referenced this pull request Sep 16, 2026
vfs-notify registered one recursive `watch()` per directory in the workspace
walk. On macOS, notify's fsevent backend rebuilds the entire FSEventStream on
every `watch()` call, so watching N directories cost O(N^2) realpath/getattrlist
syscalls. This translates to minutes of startup in a large workspace.

Fortunately, the per-directory recursive watches became redundant when
rust-lang#21771 switched the watch to `RecursiveMode::Recursive`,
so we can remove most of them. However, symlinked directories are still watched
explicitly because macOS fsevent framework does not follow symlinks on its own.

Result: LSP indexing time for https://github.com/delta-io/delta-kernel-rs on my
macOS laptop dropped from ~11 minutes to ~45 seconds.
solodevstack pushed a commit to solodevstack/rust-analyzer that referenced this pull request Sep 25, 2026
vfs-notify registered one recursive `watch()` per directory in the workspace
walk. On macOS, notify's fsevent backend rebuilds the entire FSEventStream on
every `watch()` call, so watching N directories cost O(N^2) realpath/getattrlist
syscalls. This translates to minutes of startup in a large workspace.

Fortunately, the per-directory recursive watches became redundant when
rust-lang#21771 switched the watch to `RecursiveMode::Recursive`,
so we can remove most of them. However, symlinked directories are still watched
explicitly because macOS fsevent framework does not follow symlinks on its own.

Result: LSP indexing time for https://github.com/delta-io/delta-kernel-rs on my
macOS laptop dropped from ~11 minutes to ~45 seconds.
lnicola pushed a commit to lnicola/rust that referenced this pull request Oct 12, 2026
vfs-notify registered one recursive `watch()` per directory in the workspace
walk. On macOS, notify's fsevent backend rebuilds the entire FSEventStream on
every `watch()` call, so watching N directories cost O(N^2) realpath/getattrlist
syscalls. This translates to minutes of startup in a large workspace.

Fortunately, the per-directory recursive watches became redundant when
rust-lang/rust-analyzer#21771 switched the watch to `RecursiveMode::Recursive`,
so we can remove most of them. However, symlinked directories are still watched
explicitly because macOS fsevent framework does not follow symlinks on its own.

Result: LSP indexing time for https://github.com/delta-io/delta-kernel-rs on my
macOS laptop dropped from ~11 minutes to ~45 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants