fix: index only the user-selected file/dir from @ autocomplete (#1388)

Co-authored-by: Letta Code <noreply@letta.com>
This commit is contained in:
Shelley Pham
2026-03-13 16:23:54 -07:00
committed by GitHub
parent 4352507c67
commit 7d3b4a4500
2 changed files with 11 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from "react";
import { addEntriesToCache } from "../helpers/fileIndex";
import { searchFiles } from "../helpers/fileSearch";
import { useAutocompleteNavigation } from "../hooks/useAutocompleteNavigation";
import { AutocompleteBox, AutocompleteItem } from "./Autocomplete";
@@ -66,7 +67,15 @@ export function FileAutocomplete({
const { selectedIndex } = useAutocompleteNavigation({
matches,
maxVisible: 10,
onSelect: onSelect ? (item) => onSelect(item.path) : undefined,
onSelect: onSelect
? (item) => {
// Index only the selected item, not all search results
if (item.type === "file" || item.type === "dir") {
addEntriesToCache([{ path: item.path, type: item.type }]);
}
onSelect(item.path);
}
: undefined,
manageActiveState: false, // We manage active state manually due to async loading
});

View File

@@ -1,12 +1,7 @@
import { readdirSync, statSync } from "node:fs";
import { join, relative, resolve } from "node:path";
import { debugLog } from "../../utils/debug";
import {
addEntriesToCache,
ensureFileIndex,
type FileMatch,
searchFileIndex,
} from "./fileIndex";
import { ensureFileIndex, type FileMatch, searchFileIndex } from "./fileIndex";
import { shouldHardExcludeEntry } from "./fileSearchConfig";
export function debounce<T extends (...args: never[]) => unknown>(
@@ -171,8 +166,6 @@ export async function searchFiles(
}
if (!indexSearchSucceeded || results.length === 0) {
const diskResultsBefore = results.length;
if (effectiveDeep) {
// Deep search: recursively search subdirectories.
// Use a shallower depth limit when searching outside the project directory
@@ -225,13 +218,6 @@ export async function searchFiles(
} catch {}
}
}
// If the index was working but just didn't have these files (created
// externally), add the newly found entries so future searches hit the
// cache instead of falling back to disk again.
if (indexSearchSucceeded && results.length > diskResultsBefore) {
addEntriesToCache(results.slice(diskResultsBefore));
}
}
// Only sort when the disk scan ran — its results come in arbitrary readdir