Skip to content

Fix stale markdown "file does not exist" after linked file is created#325680

Open
cipheraxat wants to merge 2 commits into
microsoft:mainfrom
cipheraxat:fix/324700-markdown-link-stale-not-found
Open

Fix stale markdown "file does not exist" after linked file is created#325680
cipheraxat wants to merge 2 commits into
microsoft:mainfrom
cipheraxat:fix/324700-markdown-link-stale-not-found

Conversation

@cipheraxat

Copy link
Copy Markdown
Contributor

Summary

  • Markdown link validation caches missing targets and clears that cache when file watchers report creates.
  • Watching with RelativePattern(fileUri, '*') never matched create/change/delete events for that file (empty relative path), so “File does not exist at path” stayed stale after the file was created until restart.
  • Watch dirname + basename instead so creates invalidate the cache.

Fixes #324700

Test plan

  • Enable markdown link validation (markdown.validate.enabled / file link validation)
  • In a .md file, add a link to a path that does not exist (e.g. [x](./missing.md))
  • Confirm diagnostic: file does not exist
  • Create missing.md on disk (Explorer or terminal)
  • Confirm the diagnostic clears without restarting VS Code
  • Ctrl+Click the link and confirm the new file opens
  • Delete the linked file again and confirm the diagnostic returns

Markdown link validation caches missing targets and relies on file watchers
to clear that cache. Watching with RelativePattern(fileUri, '*') never matched
create events for the file itself, so diagnostics stayed stale until restart.
Watch dirname + basename instead so creates invalidate the cache.
Copilot AI review requested due to automatic review settings July 13, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes stale Markdown link validation after a missing target file is created.

Changes:

  • Watches the target’s parent directory using its basename.
  • Documents why the previous pattern missed events.

Comment thread extensions/markdown-language-features/src/client/fileWatchingManager.ts Outdated
Watch the parent directory with '*' and filter events to the target URI so
filenames like [draft].md are handled literally. VS Code globs do not support
backslash escapes, so escaping the basename is not reliable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown file links will be interpreted incorrrectly.

3 participants