Improve the performance of filename completion over large repositories. (#938)

This commit is contained in:
DeWitt Clinton
2025-06-12 07:09:38 -07:00
committed by GitHub
parent 9072a4e5ee
commit f2ab6d08c4
6 changed files with 84 additions and 11 deletions

View File

@@ -42,6 +42,7 @@ describe('useCompletion git-aware filtering integration', () => {
shouldIgnoreFile: vi.fn(),
filterFiles: vi.fn(),
getIgnoreInfo: vi.fn(() => ({ gitIgnored: [], customIgnored: [] })),
glob: vi.fn().mockResolvedValue([]),
};
mockConfig = {
@@ -225,4 +226,27 @@ describe('useCompletion git-aware filtering integration', () => {
{ label: 'component.tsx', value: 'component.tsx' },
]);
});
it('should use glob for top-level @ completions when available', async () => {
const globResults = [`${testCwd}/src/index.ts`, `${testCwd}/README.md`];
mockFileDiscoveryService.glob.mockResolvedValue(globResults);
const { result } = renderHook(() =>
useCompletion('@s', testCwd, true, slashCommands, mockConfig),
);
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 150));
});
expect(mockFileDiscoveryService.glob).toHaveBeenCalledWith('**/s*', {
cwd: testCwd,
dot: true,
});
expect(fs.readdir).not.toHaveBeenCalled(); // Ensure glob is used instead of readdir
expect(result.current.suggestions).toEqual([
{ label: 'README.md', value: 'README.md' },
{ label: 'src/index.ts', value: 'src/index.ts' },
]);
});
});