fix(vscode): keep relative path in selection attachment filename (#1923)

The "Add to Context" command and the active-editor pin-selection suggestion both create selection attachments but used the basename only (e.g. assist.ts:47). OpenCode synthesizes its Read call from that filename, so the directory was lost and the model could read or edit the wrong file when names collide.

Use the workspace-relative path (asRelativePath(uri, false)) in both paths so the filename carries the directory and the two paths produce identical filenames, restoring attachment dedup.

Fixes #1914
This commit is contained in:
Ibrahim Khan
2026-07-10 16:39:55 +03:00
committed by GitHub
parent 7ea974d89b
commit de92b8fef4
2 changed files with 4 additions and 3 deletions
@@ -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
)
+3 -2
View File
@@ -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,