Skip to content

🧹 Refactor walk_for_completions to use SearchContext#3128

Open
Hmbown wants to merge 1 commit into
mainfrom
fix-too-many-arguments-18290017424165256247
Open

🧹 Refactor walk_for_completions to use SearchContext#3128
Hmbown wants to merge 1 commit into
mainfrom
fix-too-many-arguments-18290017424165256247

Conversation

@Hmbown

@Hmbown Hmbown commented Jun 12, 2026

Copy link
Copy Markdown
Owner

🎯 What: The code health issue addressed was "High Complexity: Too Many Arguments in walk_for_completions". This was resolved by creating a SearchContext struct that groups the 5 related search state parameters and passing it by mutable reference instead.
💡 Why: How this improves maintainability: The functions walk_for_completions, walk_always_discoverable_dirs, and add_local_reference_completions each took 8 arguments. Grouping 5 of these related search-state arguments into a single struct greatly reduces signature complexity and allows for the removal of the #[allow(clippy::too_many_arguments)] pragma.
Verification: I successfully confirmed that the changes did not break the functionality by ensuring that the codebase compiled warning-free with cargo check and cargo clippy, formatted correctly using cargo fmt, and passed all the tests related to working_set and codewhale-tui.
Result: The signatures are now simpler, easier to read, and clippy exceptions have been cleanly removed, leaving the project in a slightly healthier state.


PR created automatically by Jules for task 18290017424165256247 started by @Hmbown

- Fixes high complexity by replacing 5 related arguments with a `SearchContext` struct in `walk_for_completions`, `walk_always_discoverable_dirs`, and `add_local_reference_completions`.
- Removes `#[allow(clippy::too_many_arguments)]` from these functions.
- Simplifies method signatures and improves code maintainability.

Co-authored-by: Hmbown <101357273+Hmbown@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a SearchContext struct to encapsulate search-related parameters, simplifying the signatures of several walk and completion functions and allowing the removal of #[allow(clippy::too_many_arguments)] attributes. The review feedback suggests further improving this design by implementing helper methods on SearchContext (specifically is_at_limit and add_match) to centralize limit checking and match categorization, which would reduce code duplication across the traversal functions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +38 to +44
struct SearchContext<'a> {
needle: &'a str,
limit: usize,
prefix_hits: &'a mut Vec<String>,
substring_hits: &'a mut Vec<String>,
seen: &'a mut HashSet<PathBuf>,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and reduce code duplication, we can encapsulate the search matching and limit checking logic directly within SearchContext. This keeps the walk functions cleaner and more focused on traversal.

struct SearchContext<'a> {
    needle: &'a str,
    limit: usize,
    prefix_hits: &'a mut Vec<String>,
    substring_hits: &'a mut Vec<String>,
    seen: &'a mut HashSet<PathBuf>,
}

impl<'a> SearchContext<'a> {
    fn is_at_limit(&self) -> bool {
        self.prefix_hits.len() + self.substring_hits.len() >= self.limit
    }

    fn add_match(&mut self, candidate: String) {
        let lower = candidate.to_lowercase();
        if self.needle.is_empty() || lower.starts_with(self.needle) {
            self.prefix_hits.push(candidate);
        } else if lower.contains(self.needle) {
            self.substring_hits.push(candidate);
        }
    }
}

}
for entry in builder.build().flatten() {
if prefix_hits.len() + substring_hits.len() >= limit {
if ctx.prefix_hits.len() + ctx.substring_hits.len() >= ctx.limit {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the new is_at_limit helper method on SearchContext to simplify the limit check.

Suggested change
if ctx.prefix_hits.len() + ctx.substring_hits.len() >= ctx.limit {
if ctx.is_at_limit() {

Comment on lines +438 to 442
if ctx.needle.is_empty() || lower.starts_with(ctx.needle) {
ctx.prefix_hits.push(candidate);
} else if lower.contains(ctx.needle) {
ctx.substring_hits.push(candidate);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the new add_match helper method on SearchContext to encapsulate the matching logic. Note that you should also remove the now-unused let lower = candidate.to_lowercase(); on the preceding line (line 437) to avoid compiler warnings.

            ctx.add_match(candidate);


for entry in builder.build().flatten() {
if prefix_hits.len() + substring_hits.len() >= limit {
if ctx.prefix_hits.len() + ctx.substring_hits.len() >= ctx.limit {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the new is_at_limit helper method on SearchContext to simplify the limit check.

Suggested change
if ctx.prefix_hits.len() + ctx.substring_hits.len() >= ctx.limit {
if ctx.is_at_limit() {

Comment on lines +480 to 484
if ctx.needle.is_empty() || lower.starts_with(ctx.needle) {
ctx.prefix_hits.push(candidate);
} else if lower.contains(ctx.needle) {
ctx.substring_hits.push(candidate);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the new add_match helper method on SearchContext to encapsulate the matching logic. Note that you should also remove the now-unused let lower = candidate.to_lowercase(); on the preceding line (line 479) to avoid compiler warnings.

        ctx.add_match(candidate);


for path in local_reference_paths(root, LOCAL_REFERENCE_SCAN_LIMIT, max_depth) {
if prefix_hits.len() + substring_hits.len() >= limit {
if ctx.prefix_hits.len() + ctx.substring_hits.len() >= ctx.limit {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the new is_at_limit helper method on SearchContext to simplify the limit check.

Suggested change
if ctx.prefix_hits.len() + ctx.substring_hits.len() >= ctx.limit {
if ctx.is_at_limit() {

Comment on lines +516 to 520
if ctx.needle.is_empty() || lower.starts_with(ctx.needle) {
ctx.prefix_hits.push(rel_str);
} else if lower.contains(ctx.needle) {
ctx.substring_hits.push(rel_str);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the new add_match helper method on SearchContext to encapsulate the matching logic. Note that you should also remove the now-unused let lower = rel_str.to_lowercase(); on the preceding line (line 515) to avoid compiler warnings.

        ctx.add_match(rel_str);

@Hmbown Hmbown added this to the v0.8.64 milestone Jun 13, 2026
pull Bot pushed a commit to dolfly/DeepSeek-TUI that referenced this pull request Jun 14, 2026
Introduce a small SearchContext for workspace completion walks so the related search state moves together and the helper signatures no longer need too-many-arguments allowances.

Also keeps the nearby hotbar test clippy-clean under the all-targets TUI gate.

Modified harvest from PR Hmbown#3128 by @Hmbown.

Co-authored-by: Hmbown <101357273+Hmbown@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant