Skip to content

Commit 1f25b51

Browse files
ulugbeknaCopilot
andcommitted
nes: fix: normalize Windows workspace path casing
Compare local Windows file and notebook paths case-insensitively when stripping the workspace root. URI serialization lowercases the document drive letter while the workspace URI can retain uppercase casing, which leaked an absolute path into NES predictions. Fixes #325491 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c3a3ef53-5b3f-4816-a695-a90acc9caa11
1 parent 2cb0cc1 commit 1f25b51

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

extensions/copilot/src/extension/xtab/common/promptCraftingUtils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55

66
import { DocumentId } from '../../../platform/inlineEdits/common/dataTypes/documentId';
77
import { Schemas } from '../../../util/vs/base/common/network';
8+
import { isWindows } from '../../../util/vs/base/common/platform';
9+
import { startsWithIgnoreCase } from '../../../util/vs/base/common/strings';
810

911
export function toUniquePath(documentId: DocumentId, workspaceRootPath: string | undefined): string {
1012
const filePath = documentId.path;
11-
// remove prefix from path if defined
1213
const workspaceRootPathWithSlash = workspaceRootPath === undefined ? undefined : (workspaceRootPath.endsWith('/') ? workspaceRootPath : workspaceRootPath + '/');
14+
const documentScheme = documentId.toUri().scheme;
15+
const ignorePathCase = isWindows && (documentScheme === Schemas.file || documentScheme === Schemas.vscodeNotebookCell);
16+
const isWorkspaceRelative = workspaceRootPathWithSlash !== undefined
17+
&& (ignorePathCase ? startsWithIgnoreCase(filePath, workspaceRootPathWithSlash) : filePath.startsWith(workspaceRootPathWithSlash));
1318

14-
const updatedFilePath = workspaceRootPathWithSlash !== undefined && filePath.startsWith(workspaceRootPathWithSlash)
19+
const updatedFilePath = isWorkspaceRelative
1520
? filePath.substring(workspaceRootPathWithSlash.length)
1621
: filePath;
1722

18-
return documentId.toUri().scheme === Schemas.vscodeNotebookCell ? `${updatedFilePath}#${documentId.fragment}` : updatedFilePath;
23+
return documentScheme === Schemas.vscodeNotebookCell ? `${updatedFilePath}#${documentId.fragment}` : updatedFilePath;
1924
}
2025

2126
export function countTokensForLines(page: string[], computeTokens: (s: string) => number): number {
2227
return page.reduce((sum, line) => sum + computeTokens(line) + 1 /* \n */, 0);
2328
}
24-

0 commit comments

Comments
 (0)