fix: regression in completion filtering (#1135)
This commit is contained in:
parent
7f189f4d5f
commit
63fbc8ce18
|
@ -59,6 +59,31 @@ describe('useCompletion git-aware filtering integration', () => {
|
|||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should filter git-ignored entries from @ completions', async () => {
|
||||
const globResults = [`${testCwd}/data`, `${testCwd}/dist`];
|
||||
vi.mocked(glob).mockResolvedValue(globResults);
|
||||
|
||||
// Mock git ignore service to ignore certain files
|
||||
mockFileDiscoveryService.shouldGitIgnoreFile.mockImplementation(
|
||||
(path: string) => path.includes('dist'),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useCompletion('@d', testCwd, true, slashCommands, mockConfig),
|
||||
);
|
||||
|
||||
// Wait for async operations to complete
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 150)); // Account for debounce
|
||||
});
|
||||
|
||||
expect(result.current.suggestions).toHaveLength(1);
|
||||
expect(result.current.suggestions).toEqual(
|
||||
expect.arrayContaining([{ label: 'data', value: 'data' }]),
|
||||
);
|
||||
expect(result.current.showSuggestions).toBe(true);
|
||||
});
|
||||
|
||||
it('should filter git-ignored directories from @ completions', async () => {
|
||||
// Mock fs.readdir to return both regular and git-ignored directories
|
||||
vi.mocked(fs.readdir).mockResolvedValue([
|
||||
|
|
|
@ -306,6 +306,12 @@ export function useCompletion(
|
|||
value: escapePath(relativePath),
|
||||
};
|
||||
})
|
||||
.filter((s) => {
|
||||
if (fileDiscoveryService) {
|
||||
return !fileDiscoveryService.shouldGitIgnoreFile(s.label); // relative path
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.slice(0, maxResults);
|
||||
|
||||
return suggestions;
|
||||
|
|
Loading…
Reference in New Issue