Repository navigation
fix: Do not start fallback grep if index is not ready #880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -81,7 +81,8 @@ function M.update_results_sync() | |||||
|
|
||||||
| S.suggestion_items = nil | ||||||
| S.suggestion_source = nil | ||||||
| if #results == 0 and S.query ~= '' then | ||||||
| local suggestions_enabled = (S.config.suggestions or {}).enabled ~= false | ||||||
| if #results == 0 and S.query ~= '' and suggestions_enabled then | ||||||
| if S.mode == 'grep' then | ||||||
| local suggestion_results = | ||||||
| file_picker.search_files_paginated(S.query, S.current_file_cache, S.config.max_threads, nil, 0, page_size) | ||||||
|
|
@@ -90,8 +91,7 @@ function M.update_results_sync() | |||||
| S.suggestion_source = 'files' | ||||||
| end | ||||||
| else | ||||||
| local grep_result = grep.search(S.query, 0, page_size, S.grep_config, 'plain') | ||||||
| local grep_items = grep_result and grep_result.items or {} | ||||||
| local grep_items = M.suggestion_grep(page_size) | ||||||
| if #grep_items > 0 then | ||||||
| S.suggestion_items = grep_items | ||||||
| S.suggestion_source = 'grep' | ||||||
|
|
@@ -113,6 +113,23 @@ function M.update_results_sync() | |||||
| P.render_debounced() | ||||||
| end | ||||||
|
|
||||||
| -- Hint only: hard time budget (a zero-hit query would otherwise scan every file) | ||||||
| -- and skipped unless the bigram index is built, since without it grep is a cold disk scan. | ||||||
| ---@param page_size number | ||||||
| ---@return table[] | ||||||
| function M.suggestion_grep(page_size) | ||||||
| if not file_picker.get_scan_progress().is_index_ready then return {} end | ||||||
| local suggest_config = S.config.suggestions or {} | ||||||
|
|
||||||
| local grep_config = vim.tbl_extend('force', S.grep_config or S.config.grep or {}, { | ||||||
| enforce_time_budget = true, | ||||||
| time_budget_ms = suggest_config.grep_time_budget_ms or 50, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,180p' lua/fff/picker_ui/search_manager.lua
printf '\n--- grep budget consumers ---\n'
rg -n -C 4 'time_budget_ms|suggestion_grep|grep_time_budget_ms' lua crates
printf '\n--- suggestion configuration ---\n'
sed -n '40,125p' lua/fff/conf.lua
sed -n '430,490p' lua/fff/conf.luaRepository: dmtrKovalenko/fff Length of output: 41675 Keep the suggestion grep budget bounded.
Clamp this value to a positive duration, or reject zero during configuration validation. Proposed fix- time_budget_ms = suggest_config.grep_time_budget_ms or 50,
+ time_budget_ms = math.max(1, suggest_config.grep_time_budget_ms or 50),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| }) | ||||||
| local ok, grep_result = pcall(grep.search, S.query, 0, page_size, grep_config, 'plain') | ||||||
| if not ok or not grep_result then return {} end | ||||||
| return grep_result.items or {} | ||||||
| end | ||||||
|
|
||||||
| function M.load_page_at_index(new_page_index, adjust_cursor_fn) | ||||||
| local ok, err, results | ||||||
| local page_size = S.pagination.page_size | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
grep_time_budget_msis configured as0, this value is forwarded directly even though the grep implementation treats zero as “no budget.” A zero-result file query can therefore synchronously scan every indexed file and block the picker UI instead of honoring the promised hard cap.