Skip to content

fix(ui): Custom commands file path autocompletion#6916

Closed
dracic wants to merge 18 commits intogoogle-gemini:mainfrom
dracic:feature/customcomands-path-autocomplete
Closed

fix(ui): Custom commands file path autocompletion#6916
dracic wants to merge 18 commits intogoogle-gemini:mainfrom
dracic:feature/customcomands-path-autocomplete

Conversation

@dracic
Copy link
Copy Markdown
Contributor

@dracic dracic commented Aug 23, 2025

TLDR

Enables file path autocompletion for custom commands by implementing dual-mode completion that allows @ file suggestions to work with /custom-command @path/to/file syntax. Also fixes post-rebase 35% width constraint issue affecting file path suggestion display.

Key Changes:

  • Dual-mode completion: Custom commands (.toml files) now support both slash command completion and @ file path completion
  • Width constraint fix: File path completions use full width instead of being constrained to 35% like slash commands
  • Performance optimizations: O(1) command lookups with memoized Map, regex-based parsing
  • Comprehensive testing: 23 tests including edge cases

Dive Deeper

This PR addresses a fundamental UX limitation where custom commands couldn't use file path autocompletion. The implementation introduces a dual-mode completion strategy:

Architecture Overview

  1. Command Detection: Uses CommandKind.FILE enum to differentiate custom commands from built-in commands
  2. Mode Selection Logic:
    • Built-in commands: Early return with SLASH mode (preserves existing behavior)
    • Custom commands: Allow fall-through to @ detection for file path completion
  3. UI Improvement: Replaces brittle string parsing with explicit CompletionMode propagation

Technical Implementation

  • File: useCommandCompletion.tsx - Core dual-mode logic using isCustomCommand helper
  • File: SuggestionsDisplay.tsx - Width constraint fix using explicit completion mode
  • File: InputPrompt.tsx - Pass completion mode to UI components

Performance Enhancements

  • O(1) Lookups: Memoized Map<string, SlashCommand> replaces O(n) array searches
  • Robust Parsing: Regex-based command extraction handles edge cases gracefully
  • Logic Optimization: Single command type determination eliminates redundant calls
  • UI Polish: Ellipsis truncation prevents long file path overflow

Reviewer Test Plan

Manual Testing Scenarios

1. Basic Dual-Mode Functionality

# Custom command file path completion (NEW)
/my-custom @src/  # Should show file suggestions with full width

# Built-in command behavior (PRESERVED) 
/memory @src/     # Should NOT show file suggestions

# Custom command name completion (PRESERVED)
/my-cus           # Should show command name suggestions and adjust to longest command

2. Edge Cases

# Extra whitespace
/my-custom   @some/path   # Should work correctly

# Empty @ query  
/my-custom @              # Should trigger file completion

# Command substring conflicts
/log vs /logs             # Should differentiate correctly

# No-op command
/                         # Should show slash completion

3. Visual Validation

  • File path suggestions should use full width (not 35% constraint)
  • Slash command suggestions should use minimum 15 chars, maximum 35% of terminal width, but adapts to fit the longest visible command
  • Long file paths should truncate with ellipsis (no overflow)

Automated Testing

cd packages/cli
npm run typecheck  # Type safety
npm run lint       # Code standards
npm test -- useCommandCompletion  # 23 tests including edge cases
npm test -- SuggestionsDisplay InputPrompt  # UI component tests

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Test Results:

  • ✅ 112/112 completion-related tests PASSED
  • ✅ TypeScript compilation clean
  • ✅ ESLint passes
  • ✅ Zero regressions in existing functionality

Linked issues / bugs

Resolves #6685

Additional Context:

@dracic dracic requested a review from a team as a code owner August 23, 2025 10:54
Copy link
Copy Markdown
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.

Summary of Changes

Hello @dracic, 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 enhances the user interface by introducing dual-mode autocompletion for custom commands, allowing them to support both command name suggestions and file path suggestions. It also addresses a critical UI display bug that previously limited file path suggestion width. The changes include performance optimizations for command lookups and robust parsing, all backed by extensive new test cases to ensure stability and prevent regressions.

Highlights

  • Dual-Mode Autocompletion for Custom Commands: Custom commands now support both traditional slash command completion and new @ file path completion, allowing users to easily select files within custom command contexts.
  • Improved UI Display for File Paths: Resolved a UI issue where file path suggestions were constrained to 35% width, ensuring they now utilize the full available width for better readability.
  • Performance Optimizations: Implemented a memoized Map for O(1) command lookups and utilized regex-based parsing for command extraction, significantly enhancing performance and responsiveness.
  • Comprehensive Test Coverage: Added 23 new tests, including a focus on paranoid edge cases, to ensure the stability and correctness of the new dual-mode completion system.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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
Copy Markdown
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 is an excellent pull request that thoughtfully implements file path autocompletion for custom commands. The introduction of a dual-mode completion system is a clever solution. I'm particularly impressed by the performance optimizations, such as the memoized map for O(1) command lookups, and the addition of a comprehensive suite of tests covering many edge cases. The code is clean, the logic is sound, and the UI improvements for handling long file paths are a great touch. Overall, this is a high-quality contribution that significantly improves the user experience.

@dracic dracic changed the title fix(ui): Custom comands file path autocompletion fix(ui): Custom commands file path autocompletion Aug 23, 2025
@dracic dracic force-pushed the feature/customcomands-path-autocomplete branch from 8e58111 to 362a2f3 Compare August 26, 2025 05:53
@dracic
Copy link
Copy Markdown
Contributor Author

dracic commented Aug 26, 2025

Rebased, now includes changes from #6957

@dracic
Copy link
Copy Markdown
Contributor Author

dracic commented Aug 28, 2025

@abhipatel12 this is also custom commands related. When you have some time, review it, and then tell me what you think.

@gemini-cli gemini-cli bot added kind/enhancement priority/p2 Important but can be addressed in a future release. labels Aug 29, 2025
Support both slash and at-symbol completion modes for custom commands from .toml files while maintaining existing behavior for built-in commands. Added tests to verify the new functionality.
Introduce CompletionMode enum to distinguish between different suggestion types and replace the slash command detection logic. This provides more flexibility for future suggestion modes and improves code maintainability.
- Replace linear search with memoized Map for O(1) command lookups
- Add truncation utility for long file paths in suggestions display
- Add comprehensive edge case tests for command parsing
…n linting errors

The changes add explicit type imports using the `type` keyword to improve type safety and make imports more explicit. This helps with tree-shaking and makes it clearer which imports are types versus runtime values.
- Reformat imports and code for better readability
- Add string type check in truncateWithEllipsis utility
- Replace magic number with constant for suggestion width ratio
- Enhance command completion logic with better whitespace handling
- Add test case for empty @ query with whitespace
@dracic dracic force-pushed the feature/customcomands-path-autocomplete branch from a6a6a85 to 6d6bfe4 Compare September 7, 2025 15:16
@dracic
Copy link
Copy Markdown
Contributor Author

dracic commented Sep 7, 2025

Rebased. now includes changes from #7797 and #7847

@jacob314 jacob314 requested a review from abhipatel12 September 8, 2025 21:32
Support both slash and at-symbol completion modes for custom commands from .toml files while maintaining existing behavior for built-in commands. Added tests to verify the new functionality.
Introduce CompletionMode enum to distinguish between different suggestion types and replace the slash command detection logic. This provides more flexibility for future suggestion modes and improves code maintainability.
- Replace linear search with memoized Map for O(1) command lookups
- Add truncation utility for long file paths in suggestions display
- Add comprehensive edge case tests for command parsing
…n linting errors

The changes add explicit type imports using the `type` keyword to improve type safety and make imports more explicit. This helps with tree-shaking and makes it clearer which imports are types versus runtime values.
- Reformat imports and code for better readability
- Add string type check in truncateWithEllipsis utility
- Replace magic number with constant for suggestion width ratio
- Enhance command completion logic with better whitespace handling
- Add test case for empty @ query with whitespace
Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

Hey thanks for making this change and sorry for the delayed review. Left a few comments, let me know what you think.

}, [slashCommands]);

// Helper function to check if a command is a custom command (from .toml files)
const isCustomCommand = useCallback(
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.

Is there a case where we want this for MCP prompts as commands? Or are they being excluded on purpose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did it on purpose because of discussion on #6685:

This is intentional. Commands do not necessarily take file path inputs and it would be misleading to imply that they do. Commands that do take file path inputs can support autocomplete if they want to, tho.

So i focused only on custom commands

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you suggest?

completionMode: CompletionMode;
}

export function useCommandCompletion(
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.

What happens to the autocomplete for the command if the cursor is moved back? For example:

/foo-command<CURSOR> @some/file?

Do you still get suggestions for the command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. I have a bug in line 132 where the backwards search for '@' symbol starts at cursorCol - 1 instead of cursorCol. When the cursor is positioned right before the '@' symbol, the loop misses it entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

      // Start from cursorCol, but if it's a space, also check cursorCol - 1
      const startSearch =
        cursorCol < codePoints.length && codePoints[cursorCol] === ' '
          ? cursorCol - 1
          : cursorCol;

- Resolved conflicts in SuggestionsDisplay.tsx
- Updated to use Colors system instead of theme system
- Preserved custom command completion functionality
- Maintained file autocomplete dual-mode behavior
…tility

Add comprehensive test suite for SuggestionsDisplay component including:
- Utility function tests for truncateWithEllipsis
- Component rendering tests
- Truncation behavior in different completion modes
- Loading and empty states
@dracic dracic requested a review from a team as a code owner September 13, 2025 14:55
- Fix inconsistent indentation in SuggestionsDisplay component
- Improve command completion search to handle spaces after cursor
- Update test formatting for better readability
@dracic
Copy link
Copy Markdown
Contributor Author

dracic commented Sep 21, 2025

Given the multiple changes, it no longer makes sense to correct this. It is better to do everything from scratch.

@dracic dracic closed this Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ file suggestions don't shown when using /commands

2 participants