Fix autocomplete popover stability and workspace file suggestion ranking
This commit is contained in:
@@ -234,4 +234,33 @@ describe('searchWorkspaceEntries', () => {
|
||||
})
|
||||
expect(escapedResults.some((entry) => entry.path.includes('escaped-link'))).toBe(false)
|
||||
})
|
||||
|
||||
it('ignores node_modules entries so deep workspace files still resolve under scan limits', async () => {
|
||||
mkdirSync(path.join(workspaceDir, 'packages', 'app', 'src', 'app'), { recursive: true })
|
||||
writeFileSync(path.join(workspaceDir, 'packages', 'app', 'src', 'app', '_layout.tsx'), '')
|
||||
|
||||
for (let index = 0; index < 120; index += 1) {
|
||||
mkdirSync(path.join(workspaceDir, 'node_modules', `pkg-${index}`), { recursive: true })
|
||||
writeFileSync(
|
||||
path.join(workspaceDir, 'node_modules', `pkg-${index}`, 'index.js'),
|
||||
'module.exports = {};\n'
|
||||
)
|
||||
}
|
||||
writeFileSync(path.join(workspaceDir, 'node_modules', '_layout.tsx'), '')
|
||||
|
||||
const results = await searchWorkspaceEntries({
|
||||
cwd: workspaceDir,
|
||||
query: '_layout.tsx',
|
||||
limit: 20,
|
||||
includeFiles: true,
|
||||
includeDirectories: true,
|
||||
maxEntriesScanned: 60,
|
||||
})
|
||||
|
||||
expect(results).toContainEqual({
|
||||
path: 'packages/app/src/app/_layout.tsx',
|
||||
kind: 'file',
|
||||
})
|
||||
expect(results.some((entry) => entry.path.startsWith('node_modules/'))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -73,6 +73,7 @@ const directoryListCache = new Map<string, DirectoryListCacheEntry>()
|
||||
const workspaceEntryListCache = new Map<string, WorkspaceEntryListCacheEntry>()
|
||||
const NO_SEGMENT_INDEX = Number.MAX_SAFE_INTEGER
|
||||
const NO_MATCH_OFFSET = Number.MAX_SAFE_INTEGER
|
||||
const WORKSPACE_IGNORED_DIRECTORY_NAMES = new Set(['node_modules'])
|
||||
|
||||
export async function searchHomeDirectories(
|
||||
options: SearchHomeDirectoriesOptions
|
||||
@@ -750,6 +751,9 @@ async function listWorkspaceChildEntries(input: {
|
||||
if (isHiddenDirectoryName(dirent.name)) {
|
||||
continue
|
||||
}
|
||||
if (isIgnoredWorkspaceDirectoryName(dirent.name)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const candidatePath = path.join(input.directory, dirent.name)
|
||||
const entry = await resolveWorkspaceCandidate({
|
||||
@@ -839,6 +843,10 @@ function isHiddenDirectoryName(name: string): boolean {
|
||||
return name.startsWith('.')
|
||||
}
|
||||
|
||||
function isIgnoredWorkspaceDirectoryName(name: string): boolean {
|
||||
return WORKSPACE_IGNORED_DIRECTORY_NAMES.has(name)
|
||||
}
|
||||
|
||||
function setDirectoryListCache(cacheKey: string, entry: DirectoryListCacheEntry): void {
|
||||
directoryListCache.set(cacheKey, entry)
|
||||
pruneDirectoryListCache()
|
||||
|
||||
Reference in New Issue
Block a user