MCPcopy Create free account
hub / github.com/winfunc/opcode / performSearch

Function performSearch

src/components/FilePicker.tsx:287–326  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

285 };
286
287 const performSearch = async (query: string) => {
288 try {
289 console.log('[FilePicker] Searching for:', query, 'in:', basePath);
290
291 // Create cache key that includes both query and basePath
292 const cacheKey = `${basePath}:${query}`;
293
294 // Check cache first and show immediately
295 if (globalSearchCache.has(cacheKey)) {
296 console.log('[FilePicker] Showing cached search results for:', query);
297 setSearchResults(globalSearchCache.get(cacheKey) || []);
298 setIsShowingCached(true);
299 setError(null);
300 } else {
301 // Only show loading if we don't have cached data
302 setIsLoading(true);
303 }
304
305 // Always fetch fresh results in background
306 const results = await api.searchFiles(basePath, query);
307 console.log('[FilePicker] Fresh search results:', results.length, 'items');
308
309 // Cache the results
310 globalSearchCache.set(cacheKey, results);
311
312 // Update with fresh results
313 setSearchResults(results);
314 setIsShowingCached(false);
315 setError(null);
316 } catch (err) {
317 console.error('[FilePicker] Search failed:', query, err);
318 // Only set error if we don't have cached data to show
319 const cacheKey = `${basePath}:${query}`;
320 if (!globalSearchCache.has(cacheKey)) {
321 setError(err instanceof Error ? err.message : 'Search failed');
322 }
323 } finally {
324 setIsLoading(false);
325 }
326 };
327
328 const navigateToDirectory = (path: string) => {
329 setCurrentPath(path);

Callers 2

FilePickerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected