Index notes in folders created, moved or renamed outside VS Code - #1724
Merged
Merged
Conversation
VS Code reports a folder created, deleted, moved or renamed as one event for the folder, and on Linux often doesn't report the files written into a new folder before it is watched. Foam's watcher only matched note and attachment extensions, so it dropped the folder event and never saw those notes; a renamed folder also left its old notes in the index. Watch folders too: a created folder is expanded into the files it contains, and a deleted folder removes the resources under it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EX3EnAE7eqkcteJi29pqJr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Foam's file watcher only matches note/attachment extensions, so folder events are filtered out. VS Code reports a folder created, deleted, moved or renamed as a single event for the folder (
createFileSystemWatcherdocs: "if you need to know about all deleted files, you have to watch with**and deal with all file events yourself"), and on Linux files written into a brand-new folder are often not reported at all, because the folder isn't watched yet when they're written.This is what made
refactor.spec.tstime out on ubuntu in CI (run).Reproduced in a real VS Code 1.110 test host on Linux, 10 runs per scenario (5 for move/rename):
a/b/n.mdviavscode.workspace.fs.writeFilemkdir -p a/b && write(outside VS Code)mkdir a && write a/n.md(outside VS Code)Change
**/*watcher per workspace folder, listening to creates and deletes. A created folder is expanded, viafindFileswith the existing watch glob, into create events for the files it contains. Deletes are forwarded as they are.IWatchernow documents that a delete may be for a folder.The CLI's chokidar watcher already reports each file in a new folder, so it needs no change.
Trade-offs
stat, and every non-note delete costs one pass over the index. Note deletes arrive from both watchers, so the second is a no-op pass.Tests
foam.test.ts: deleting a folder removes the notes under it, but notfolder.mdorfolder-sibling/.watcher.spec.ts(real VS Code host only): a folder moved into the workspace is indexed; after a rename, the new path is indexed and the old one is removed. Both failed every time before the fix.Not verified on macOS/Windows. With this in, the rewrite-missed-files workaround on
fix/refactor-spec-rename-racesshould no longer be needed.🤖 Generated with Claude Code
https://claude.ai/code/session_01EX3EnAE7eqkcteJi29pqJr
Generated by Claude Code