fix chat: skip fragment-only markdown links to avoid false 'File not found' warnings#313804
Open
AmSach wants to merge 5 commits intomicrosoft:mainfrom
Open
fix chat: skip fragment-only markdown links to avoid false 'File not found' warnings#313804AmSach wants to merge 5 commits intomicrosoft:mainfrom
AmSach wants to merge 5 commits intomicrosoft:mainfrom
Conversation
…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>
Contributor
There was a problem hiding this comment.
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 }); |
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>
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.
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: