diff --git a/packages/ui/src/components/chat/FileAttachment.tsx b/packages/ui/src/components/chat/FileAttachment.tsx index 5949164f..158a78f8 100644 --- a/packages/ui/src/components/chat/FileAttachment.tsx +++ b/packages/ui/src/components/chat/FileAttachment.tsx @@ -471,7 +471,7 @@ export const ActiveEditorFileSuggestion = memo(() => { ? `${selection.startLine}` : `${selection.startLine}-${selection.endLine}` } - const selectionLabel = selection ? `${fileName}:${selectionRange}` : '' + const selectionLabel = selection ? `${relativePath}:${selectionRange}` : '' const isSelectionAttached = !!selectionLabel && attachedFiles.some( (f) => f.source === 'vscode' && f.vscodeSource === 'selection' && f.filename === selectionLabel && f.vscodePath === filePath ) diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 1fd80b94..8fbdec8c 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -297,13 +297,14 @@ export async function activate(context: vscode.ExtensionContext) { } // Get file info for context - const filePath = vscode.workspace.asRelativePath(editor.document.uri); + // false matches the relativePath broadcast for the active editor, so this attachment dedupes against the pin-selection suggestion. + const filePath = vscode.workspace.asRelativePath(editor.document.uri, false); // Get line numbers (1-based for display) const startLine = selection.start.line + 1; const endLine = selection.end.line + 1; const lineRange = startLine === endLine ? `${startLine}` : `${startLine}-${endLine}`; - const filename = `${editor.document.fileName.split(/[\\/]/).pop() || filePath}:${lineRange}`; + const filename = `${filePath}:${lineRange}`; const contextSelection = { filePath: editor.document.uri.fsPath, filename,