-
Notifications
You must be signed in to change notification settings - Fork 37.3k
Add support for custom file link rendering metadata #286839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for custom file link rendering metadata in the chat widget. The feature allows markdown links to specify custom display names for file references through JSON metadata in the link text.
Key changes:
- Added support for parsing JSON metadata from link text to enable custom file name rendering
- Updated
InlineAnchorWidgetconstructor to accept optional metadata parameter - Modified file widget rendering logic to support both empty link text (existing behavior) and JSON metadata format
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| chatInlineAnchorWidget.ts | Adds InlineAnchorWidgetMetadata type, implements JSON metadata parsing in renderFileWidgets(), updates InlineAnchorWidget constructor to accept metadata parameter, and uses metadata.fileName for custom display names |
| chatMarkdownDecorationsRenderer.ts | Updates InlineAnchorWidget instantiation to pass undefined as the third parameter (metadata), maintaining backward compatibility |
Comments suppressed due to low confidence (2)
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.ts:66
- The comment on line 66 states "Also support metadata format: {"vscodeLinkType": "file", ...}" but doesn't clarify that the fileName field is optional. The comment should be more explicit about the expected metadata structure, such as: '{"vscodeLinkType": "file", "fileName": "optional-display-name"}'. This will help developers understand the complete API and avoid confusion about whether fileName is required.
// Also support metadata format: [{"vscodeLinkType": "file", ...}](uri)
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.ts:77
- The metadata validation lacks a type guard to ensure the parsed JSON is an object. While the condition checks
metadata && metadata.vscodeLinkType === 'file', if JSON.parse returns a primitive value (string, number, boolean) or an array, accessingmetadata.vscodeLinkTypewon't throw an error but will return undefined, and the condition will silently fail. Add an explicit check that the parsed value is a plain object:metadata && typeof metadata === 'object' && !Array.isArray(metadata)before accessing its properties.
metadata = JSON.parse(linkText);
if (metadata && metadata.vscodeLinkType === 'file' && typeof metadata.fileName === 'string') {
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.ts
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.ts
Outdated
Show resolved
Hide resolved
…chatInlineAnchorWidget.ts Co-authored-by: Copilot <[email protected]>
Sample usage: microsoft/vscode-copilot-chat#2756
