Make useCompletion.test.ts windows compatible (#4766)

This commit is contained in:
Tommaso Sciortino
2025-07-25 10:32:59 -07:00
committed by GitHub
parent f379aa833f
commit 3c16429fc4
3 changed files with 1045 additions and 1953 deletions

View File

@@ -427,13 +427,10 @@ export function useCompletion(
});
const suggestions: Suggestion[] = files
.map((file: string) => {
const relativePath = path.relative(cwd, file);
return {
label: relativePath,
value: escapePath(relativePath),
};
})
.map((file: string) => ({
label: file,
value: escapePath(file),
}))
.filter((s) => {
if (fileDiscoveryService) {
return !fileDiscoveryService.shouldIgnoreFile(
@@ -475,7 +472,7 @@ export function useCompletion(
fetchedSuggestions = await findFilesRecursively(
cwd,
prefix,
fileDiscoveryService,
null,
filterOptions,
);
}
@@ -518,6 +515,13 @@ export function useCompletion(
});
}
// Like glob, we always return forwardslashes, even in windows.
fetchedSuggestions = fetchedSuggestions.map((suggestion) => ({
...suggestion,
label: suggestion.label.replace(/\\/g, '/'),
value: suggestion.value.replace(/\\/g, '/'),
}));
// Sort by depth, then directories first, then alphabetically
fetchedSuggestions.sort((a, b) => {
const depthA = (a.label.match(/\//g) || []).length;