Skip to content

fix chat: skip fragment-only markdown links to avoid false 'File not found' warnings#313804

Open
AmSach wants to merge 5 commits intomicrosoft:mainfrom
AmSach:fragment-fix-v2
Open

fix chat: skip fragment-only markdown links to avoid false 'File not found' warnings#313804
AmSach wants to merge 5 commits intomicrosoft:mainfrom
AmSach:fragment-fix-v2

Conversation

@AmSach
Copy link
Copy Markdown

@AmSach AmSach commented May 1, 2026

Supersedes #312677 with proper fix.

Fixes vscode#312673

Properly records markdownLinkRanges for fragment-only links while not treating them as file references. Adds comprehensive test cases covering:

  • Fragment-only anchor links like Details produce no validation errors
  • Fragment-only #tool: and #file: links are handled correctly
  • Mixed link types with both valid file links and fragment-only links

Aman Sachan and others added 3 commits April 29, 2026 16:13
…found' warnings (fixes vscode#312673)

In chatagent/agent markdown files, [text](#anchor) links are intra-document
anchors (GitHub-style heading anchors), not file references.
The validator was treating '#anchor' as a relative file path,
causing false-positive 'File not found' warnings.
Skip links where the path before the fragment is empty.
Reviewed by: aeschli

Add tests to cover:
- Fragment-only anchor links like [Details](#details) produce no validation errors
- Mixed link types: valid file links work while fragment-only links are ignored
…only links

Addresses Copilot review comment on PR microsoft#312677:
For fragment-only links like [x](#tool:foo), the markdownLinkRanges
was not being updated, so the #file:#tool: matcher below would still
see #tool:foo and treat it as a tool reference. Now we always push
to markdownLinkRanges for every markdown link, only skipping the
fileReferences push for fragment-only links.

Also adds a test case for fragment-only links containing #tool:.

Signed-off-by: Aman Sachan <amansachan92905@gmail.com>
Copilot AI review requested due to automatic review settings May 1, 2026 21:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the prompt validator for chatagent/prompt files so that fragment-only Markdown links (e.g. [Details](#details)) are treated as intra-document anchors rather than file references, avoiding false “File not found” warnings in the Problems panel.

Changes:

  • Update prompt body parsing to record Markdown link ranges and skip fragment-only Markdown links when collecting file references.
  • Add tests to ensure fragment-only links (including #tool: / #file: fragments) produce no diagnostics, while mixed link scenarios still validate real file links.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/chat/common/promptSyntax/promptFileParser.ts Adjusts Markdown link parsing to record link ranges and avoid treating fragment-only links as file references.
src/vs/workbench/contrib/chat/test/browser/promptSyntax/languageProviders/promptValidator.test.ts Adds regression tests for fragment-only anchors and mixed link types to prevent false “file not found” markers.

Comment on lines 490 to +493
markdownLinkRanges.push(new Range(i + 1, match.index + 1, i + 1, match.index + match[0].length + 1));
if (beforeFragment.length > 0) {
fileReferences.push({ content: linkTarget, range, isMarkdownLink: true });
}
const beforeFragment = fragmentIndex >= 0 ? linkTarget.substring(0, fragmentIndex) : linkTarget;
markdownLinkRanges.push(new Range(i + 1, match.index + 1, i + 1, match.index + match[0].length + 1));
if (beforeFragment.length > 0) {
fileReferences.push({ content: linkTarget, range, isMarkdownLink: true });
AmSach added 2 commits May 1, 2026 22:22
Address Copilot review comment on PR microsoft#313804:
For markdown links like [ref](./file.md#section), fileReferences
was storing the full linkTarget including the fragment (#section).
This causes resolveFilePath() to fail since URI.joinPath() treats
#... as part of the path, not as a URI fragment. Now we store
beforeFragment (path without fragment) for validation/resolve purposes.

Signed-off-by: Aman Sachan <amansachan92905@gmail.com>
…ectingOrTouching

Address Copilot review comment on PR microsoft#313804:
The markdownLinkRanges include the full markdown link text including closing parenthesis.
When a #file: or #tool: reference immediately follows a markdown link (no whitespace),
Range.areIntersectingOrTouching would consider them 'touching' and skip validation.
Using Range.areIntersecting requires actual overlap, so adjacent references are
still properly validated.

Signed-off-by: Aman Sachan <amansachan92905@gmail.com>
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.

chatagent language mode reports false-positive "File not found" warnings for in-page Markdown anchor links

3 participants