Skip to content

Index notes in folders created, moved or renamed outside VS Code - #1724

Merged
riccardoferretti merged 1 commit into
mainfrom
claude/pensive-davinci-7go95v
Sep 29, 2026
Merged

riccardoferretti merged 1 commit into
mainfrom
claude/pensive-davinci-7go95v

Conversation

@riccardoferretti

Copy link
Copy Markdown
Collaborator

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 (createFileSystemWatcher docs: "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.ts time 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):

Scenario Missed before Missed after
a/b/n.md via vscode.workspace.fs.writeFile 2/10 0/10
mkdir -p a/b && write (outside VS Code) 9/10 0/10
mkdir a && write a/n.md (outside VS Code) 10/10 0/10
Folder moved into the workspace 5/5 0/5
Folder renamed 5/5: new path not indexed, old path never removed 0/5

Change

  • foam-vscode: one extra **/* watcher per workspace folder, listening to creates and deletes. A created folder is expanded, via findFiles with the existing watch glob, into create events for the files it contains. Deletes are forwarded as they are.
  • foam-core: when a deleted URI isn't a resource, the resources under it (as a folder) are removed. IWatcher now 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

  • Every path created in the workspace now costs one 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.
  • A file can be reported both on its own and through its folder's expansion, which means an extra read. The result is the same.

Tests

  • foam.test.ts: deleting a folder removes the notes under it, but not folder.md or folder-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-races should no longer be needed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EX3EnAE7eqkcteJi29pqJr


Generated by Claude Code

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
@riccardoferretti
riccardoferretti merged commit 05d22fd into main Sep 29, 2026
9 checks passed
@riccardoferretti
riccardoferretti deleted the claude/pensive-davinci-7go95v branch September 29, 2026 18:50
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.

2 participants