Skip to content

feat(core): improve @file autocomplete to prioritize filenames#21064

Merged
jacob314 merged 5 commits intomainfrom
sehoon/file_search
Mar 4, 2026
Merged

feat(core): improve @file autocomplete to prioritize filenames#21064
jacob314 merged 5 commits intomainfrom
sehoon/file_search

Conversation

@sehoon38
Copy link
Contributor

@sehoon38 sehoon38 commented Mar 4, 2026

Summary

Improves the behavior of the @ file autocomplete feature to prioritize actual filenames and folder names over matching parent directory structures, providing a more intuitive search experience.

Details

Updated the AsyncFzf configuration in RecursiveFileSearch to evaluate matches right-to-left (forward: false) and introduced a sophisticated multi-stage tiebreaker sequence to refine result ranking:

  1. byBasenamePrefix: Prioritizes matches that start at the beginning of the actual filename or folder name. For example, a search for hooks will now correctly rank the folder /src/hooks/ higher than a file deep inside it like /src/hooks/index.ts.
  2. byMatchPosFromEnd: Scores matches based on their distance from the end of the file path, favoring matches that are closer to the extension/filename.
  3. byLengthAsc: Prefers shorter, cleaner paths to break final ties.

These changes ensure that searching for a string like hooks consistently ranks hooks.ts or a hooks/ directory at the top, rather than files where the term only appears as part of a parent directory name.

Related Issues

Fixes #21063

How to Validate

  1. Run the test suite: npm test -w @google/gemini-cli-core
  2. Run the CLI test suite: npm test -w @google/gemini-cli -- src/ui/hooks/useAtCompletion.test.ts
  3. Start the CLI and verify search ranking for queries like @hooks correctly prioritizes the filename/folder name over the path.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@sehoon38 sehoon38 requested a review from a team as a code owner March 4, 2026 05:50
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the user experience of the @file autocomplete feature by refining its prioritization logic. By adjusting the fuzzy search algorithm to consider filenames and their position within the path more heavily, users will now receive more intuitive and relevant file suggestions, making navigation and file selection more efficient.

Highlights

  • Autocomplete Prioritization: The @file autocomplete feature now prioritizes actual filenames over matching directory structures, enhancing the relevance of search results.
  • Fuzzy Search Configuration: The AsyncFzf configuration was updated to evaluate matches right-to-left (forward: false) and incorporate new tiebreakers for improved sorting.
  • New Tiebreaker Logic: A new tiebreaker, byMatchPosFromEnd, was introduced to score matches based on their distance from the end of the file path, ensuring filenames are ranked higher.
Changelog
  • packages/core/src/utils/filesearch/fileSearch.test.ts
    • Added a new test case to validate the improved file prioritization logic, specifically for scenarios where filenames should be ranked higher than directory paths.
  • packages/core/src/utils/filesearch/fileSearch.ts
    • Introduced two new comparison functions, byLengthAsc and byMatchPosFromEnd, to be used as tiebreakers in the fuzzy search algorithm.
    • Modified the AsyncFzf configuration within RecursiveFileSearch to enable right-to-left matching (forward: false) and apply the newly defined tiebreakers for result sorting.
Activity
  • Added/updated tests to cover the new prioritization logic.
  • Validated the changes on MacOS.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 improves file search autocomplete by changing the fuzzy search logic to prioritize matches closer to the end of a path. The changes in fileSearch.ts introduce new tiebreakers for fzf and set it to search from right-to-left. While this correctly prioritizes filenames over files in deeper directories (e.g., hooks.ts over .../hooks/index.ts), I've found a case where it can prioritize a directory over a file (e.g., hooks/ over hooks.ts). My review includes suggestions to add another tiebreaker to fix this and update the test assertions accordingly to fully align with the goal of prioritizing filenames.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Size Change: +1.16 kB (0%)

Total Size: 25.9 MB

Filename Size Change
./bundle/gemini.js 25.5 MB +1.16 kB (0%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Mar 4, 2026
@jacob314 jacob314 enabled auto-merge March 4, 2026 17:13
@jacob314 jacob314 added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit bc89b05 Mar 4, 2026
28 checks passed
@jacob314 jacob314 deleted the sehoon/file_search branch March 4, 2026 17:35
neeraj-par pushed a commit to neeraj-par/gemini-cli that referenced this pull request Mar 4, 2026
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve @ file search autocomplete to prioritize filenames

3 participants