Ignore dot files on @-completion. (#978)
This commit is contained in:
parent
af247a6cbd
commit
a9e56ee460
|
@ -241,7 +241,7 @@ describe('useCompletion git-aware filtering integration', () => {
|
||||||
|
|
||||||
expect(mockFileDiscoveryService.glob).toHaveBeenCalledWith('**/s*', {
|
expect(mockFileDiscoveryService.glob).toHaveBeenCalledWith('**/s*', {
|
||||||
cwd: testCwd,
|
cwd: testCwd,
|
||||||
dot: true,
|
dot: false,
|
||||||
});
|
});
|
||||||
expect(fs.readdir).not.toHaveBeenCalled(); // Ensure glob is used instead of readdir
|
expect(fs.readdir).not.toHaveBeenCalled(); // Ensure glob is used instead of readdir
|
||||||
expect(result.current.suggestions).toEqual([
|
expect(result.current.suggestions).toEqual([
|
||||||
|
@ -249,4 +249,32 @@ describe('useCompletion git-aware filtering integration', () => {
|
||||||
{ label: 'src/index.ts', value: 'src/index.ts' },
|
{ label: 'src/index.ts', value: 'src/index.ts' },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include dotfiles in glob search when input starts with a dot', async () => {
|
||||||
|
const globResults = [
|
||||||
|
`${testCwd}/.env`,
|
||||||
|
`${testCwd}/.gitignore`,
|
||||||
|
`${testCwd}/src/index.ts`,
|
||||||
|
];
|
||||||
|
mockFileDiscoveryService.glob.mockResolvedValue(globResults);
|
||||||
|
|
||||||
|
const { result } = renderHook(() =>
|
||||||
|
useCompletion('@.', testCwd, true, slashCommands, mockConfig),
|
||||||
|
);
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockFileDiscoveryService.glob).toHaveBeenCalledWith('**/.*', {
|
||||||
|
cwd: testCwd,
|
||||||
|
dot: true,
|
||||||
|
});
|
||||||
|
expect(fs.readdir).not.toHaveBeenCalled();
|
||||||
|
expect(result.current.suggestions).toEqual([
|
||||||
|
{ label: '.env', value: '.env' },
|
||||||
|
{ label: '.gitignore', value: '.gitignore' },
|
||||||
|
{ label: 'src/index.ts', value: 'src/index.ts' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -210,6 +210,11 @@ export function useCompletion(
|
||||||
path.join(startDir, entry.name),
|
path.join(startDir, entry.name),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Conditionally ignore dotfiles
|
||||||
|
if (!searchPrefix.startsWith('.') && entry.name.startsWith('.')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this entry should be ignored by git-aware filtering
|
// Check if this entry should be ignored by git-aware filtering
|
||||||
if (
|
if (
|
||||||
fileDiscovery &&
|
fileDiscovery &&
|
||||||
|
@ -260,7 +265,7 @@ export function useCompletion(
|
||||||
const globPattern = `**/${searchPrefix}*`;
|
const globPattern = `**/${searchPrefix}*`;
|
||||||
const files = await fileDiscoveryService.glob(globPattern, {
|
const files = await fileDiscoveryService.glob(globPattern, {
|
||||||
cwd,
|
cwd,
|
||||||
dot: true,
|
dot: searchPrefix.startsWith('.'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const suggestions: Suggestion[] = files
|
const suggestions: Suggestion[] = files
|
||||||
|
@ -309,6 +314,10 @@ export function useCompletion(
|
||||||
// Filter entries using git-aware filtering
|
// Filter entries using git-aware filtering
|
||||||
const filteredEntries = [];
|
const filteredEntries = [];
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
|
// Conditionally ignore dotfiles
|
||||||
|
if (!prefix.startsWith('.') && entry.name.startsWith('.')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!entry.name.toLowerCase().startsWith(lowerPrefix)) continue;
|
if (!entry.name.toLowerCase().startsWith(lowerPrefix)) continue;
|
||||||
|
|
||||||
const relativePath = path.relative(
|
const relativePath = path.relative(
|
||||||
|
|
Loading…
Reference in New Issue