Does this issue occur when all extensions are disabled?: Yes/No
- VS Code Version: 1.119.0
- OS Version:
Description
When using the "Add File to Chat" option from the editor tab right-click context menu (MenuId.EditorTitleContext), the action only works if the target tab is the currently active editor. Right-clicking on any non-active tab and selecting "Add File to Chat" does nothing — the file is not attached to the chat input.
Steps to Reproduce
- Open two or more files in the editor.
- Make sure one file is active (focused).
- Right-click on any other (non-active) tab.
- Select "Add File to Chat".
Expected Behavior
The right-clicked file should be attached to the Chat input, regardless of whether the tab is currently active.
Actual Behavior
Nothing happens. The file is not added to the Chat input.
Root Cause (for contributors)
In chatContextActions.ts, the _getResources method calls _getEditorResources with a wrapped array instead of spreading the arguments:
// Bug: passes `args` as a single element, creating nested array
this._getEditorResources(accessor, args)
// Fix: spread args correctly
this._getEditorResources(accessor, ...args)
Because _getEditorResources uses ...args rest parameter internally and passes args directly to resolveCommandsContext(args, ...), the nesting causes resolveCommandsContext to receive [[uri, editorCommandsContext]] instead of [uri, editorCommandsContext]. This results in an empty groupedEditors array and no file being attached.
Why Active Tab Appears to Work
When triggered from inside the editor content area (right-click on editor body, not the tab), args[1] may not satisfy isEditorCommandsContext, causing the code to fall back to editorService.activeEditor — which coincidentally is the active file.
Affected File
chatContextActions.ts
Fix
Change line 95 from:
const contexts = isEditorCommandsContext(args[1]) ? this._getEditorResources(accessor, args) : ...
to:
const contexts = isEditorCommandsContext(args[1]) ? this._getEditorResources(accessor, ...args) : ...
Does this issue occur when all extensions are disabled?: Yes/No
Description
When using the "Add File to Chat" option from the editor tab right-click context menu (
MenuId.EditorTitleContext), the action only works if the target tab is the currently active editor. Right-clicking on any non-active tab and selecting "Add File to Chat" does nothing — the file is not attached to the chat input.Steps to Reproduce
Expected Behavior
The right-clicked file should be attached to the Chat input, regardless of whether the tab is currently active.
Actual Behavior
Nothing happens. The file is not added to the Chat input.
Root Cause (for contributors)
In chatContextActions.ts, the
_getResourcesmethod calls_getEditorResourceswith a wrapped array instead of spreading the arguments:Because
_getEditorResourcesuses...argsrest parameter internally and passesargsdirectly toresolveCommandsContext(args, ...), the nesting causesresolveCommandsContextto receive[[uri, editorCommandsContext]]instead of[uri, editorCommandsContext]. This results in an emptygroupedEditorsarray and no file being attached.Why Active Tab Appears to Work
When triggered from inside the editor content area (right-click on editor body, not the tab),
args[1]may not satisfyisEditorCommandsContext, causing the code to fall back toeditorService.activeEditor— which coincidentally is the active file.Affected File
chatContextActions.ts
Fix
Change line 95 from:
to: