Skip to content

🧹 Refactor search context arguments in working_set.rs#3118

Closed
Hmbown wants to merge 1 commit into
mainfrom
fix-working-set-args-3644023353456815746
Closed

🧹 Refactor search context arguments in working_set.rs#3118
Hmbown wants to merge 1 commit into
mainfrom
fix-working-set-args-3644023353456815746

Conversation

@Hmbown

@Hmbown Hmbown commented Jun 12, 2026

Copy link
Copy Markdown
Owner

🎯 What: Grouped related search parameters (prefix_hits, substring_hits, seen, and limit) into a new SearchContext struct in crates/tui/src/working_set.rs. Applied this refactoring to walk_always_discoverable_dirs, walk_for_completions, and add_local_reference_completions.

💡 Why: This reduces the number of arguments passed to these helper functions, making the code much easier to read and maintain. It also allows the removal of the #[allow(clippy::too_many_arguments)] attribute.

Verification: Verified by running cargo clippy -p codewhale-tui (no warnings) and cargo test -p codewhale-tui (all related tests passed).

Result: Improved maintainability and reduced clippy suppressions without altering functionality.


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

This commit addresses a code health issue where `walk_always_discoverable_dirs`, `walk_for_completions`, and `add_local_reference_completions` had too many arguments and required `#[allow(clippy::too_many_arguments)]`.

A new struct `SearchContext<'a>` is introduced to encapsulate the frequently passed search state (`prefix_hits`, `substring_hits`, `seen`, and `limit`). This simplifies function signatures, improves readability, and resolves the clippy warnings.

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 in crates/tui/src/working_set.rs to group search-related parameters, simplifying function signatures and allowing the removal of several #[allow(clippy::too_many_arguments)] attributes. The reviewer suggests further encapsulating the limit checking and hit-adding logic as helper methods on the new SearchContext struct to reduce code duplication and improve maintainability across the walk 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 +387 to +392
struct SearchContext<'a> {
prefix_hits: &'a mut Vec<String>,
substring_hits: &'a mut Vec<String>,
seen: &'a mut HashSet<PathBuf>,
limit: usize,
}

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

Since we are introducing a SearchContext struct to group these search parameters, we can encapsulate the limit checking and hit-adding logic as helper methods on the struct. This reduces code duplication across the different walk functions and improves maintainability.

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

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

    fn add_hit(&mut self, candidate: String, needle: &str) {
        let lower = candidate.to_lowercase();
        if needle.is_empty() || lower.starts_with(needle) {
            self.prefix_hits.push(candidate);
        } else if lower.contains(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 encapsulated is_limit_reached 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_limit_reached() {

Comment on lines 455 to 460
let lower = candidate.to_lowercase();
if needle.is_empty() || lower.starts_with(needle) {
prefix_hits.push(candidate);
ctx.prefix_hits.push(candidate);
} else if lower.contains(needle) {
substring_hits.push(candidate);
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 encapsulated add_hit helper method on SearchContext to simplify adding prefix or substring hits.

Suggested change
let lower = candidate.to_lowercase();
if needle.is_empty() || lower.starts_with(needle) {
prefix_hits.push(candidate);
ctx.prefix_hits.push(candidate);
} else if lower.contains(needle) {
substring_hits.push(candidate);
ctx.substring_hits.push(candidate);
}
ctx.add_hit(candidate, needle);


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 encapsulated is_limit_reached 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_limit_reached() {

Comment on lines 498 to 503
let lower = candidate.to_lowercase();
if needle.is_empty() || lower.starts_with(needle) {
prefix_hits.push(candidate);
ctx.prefix_hits.push(candidate);
} else if lower.contains(needle) {
substring_hits.push(candidate);
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 encapsulated add_hit helper method on SearchContext to simplify adding prefix or substring hits.

Suggested change
let lower = candidate.to_lowercase();
if needle.is_empty() || lower.starts_with(needle) {
prefix_hits.push(candidate);
ctx.prefix_hits.push(candidate);
} else if lower.contains(needle) {
substring_hits.push(candidate);
ctx.substring_hits.push(candidate);
}
ctx.add_hit(candidate, needle);


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 encapsulated is_limit_reached 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_limit_reached() {

Comment on lines 541 to 546
let lower = rel_str.to_lowercase();
if needle.is_empty() || lower.starts_with(needle) {
prefix_hits.push(rel_str);
ctx.prefix_hits.push(rel_str);
} else if lower.contains(needle) {
substring_hits.push(rel_str);
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 encapsulated add_hit helper method on SearchContext to simplify adding prefix or substring hits.

Suggested change
let lower = rel_str.to_lowercase();
if needle.is_empty() || lower.starts_with(needle) {
prefix_hits.push(rel_str);
ctx.prefix_hits.push(rel_str);
} else if lower.contains(needle) {
substring_hits.push(rel_str);
ctx.substring_hits.push(rel_str);
}
ctx.add_hit(rel_str, needle);

@Hmbown Hmbown added this to the v0.8.64 milestone Jun 13, 2026
@Hmbown

Hmbown commented Jun 15, 2026

Copy link
Copy Markdown
Owner Author

Closing as part of cleaning up stale auto-generated PRs from the v0.8.64/v0.8.65 milestones. If any of this work is still wanted it can be reopened or re-landed.

@Hmbown Hmbown closed this Jun 15, 2026
@google-labs-jules

Copy link
Copy Markdown
Contributor

Closing as part of cleaning up stale auto-generated PRs from the v0.8.64/v0.8.65 milestones. If any of this work is still wanted it can be reopened or re-landed.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

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