fix(vscode): normalize Windows paths in file mention URL construction

This commit is contained in:
Igor Šćekić
2026-02-18 14:44:59 +01:00
parent 847367b1f0
commit b50a16725e
2 changed files with 7 additions and 4 deletions
@@ -221,9 +221,9 @@ export const PromptInput: Component = () => {
if (textareaRef) textareaRef.style.height = "auto"
}
const fileName = (path: string) => path.split("/").pop() ?? path
const fileName = (path: string) => path.replaceAll("\\", "/").split("/").pop() ?? path
const dirName = (path: string) => {
const parts = path.split("/")
const parts = path.replaceAll("\\", "/").split("/")
if (parts.length <= 1) return ""
const dir = parts.slice(0, -1).join("/")
return dir.length > 30 ? `…/${parts.slice(-3, -1).join("/")}` : dir
@@ -164,10 +164,13 @@ export function useFileMention(vscode: VSCodeContext): FileMention {
const parseFileAttachments = (text: string): FileAttachment[] => {
const paths = mentionedPaths()
const result: FileAttachment[] = []
const dir = workspaceDir.replaceAll("\\", "/")
for (const path of paths) {
if (text.includes(`@${path}`)) {
const abs = path.startsWith("/") ? path : `${workspaceDir}/${path}`
result.push({ mime: "text/plain", url: `file://${abs}` })
const abs = path.startsWith("/") ? path : `${dir}/${path}`
const url = new URL("file://")
url.pathname = abs.startsWith("/") ? abs : `/${abs}`
result.push({ mime: "text/plain", url: url.href })
}
}
return result