fix(ui): Custom commands file path autocompletion#6916
fix(ui): Custom commands file path autocompletion#6916dracic wants to merge 18 commits intogoogle-gemini:mainfrom
Conversation
There was a problem hiding this comment.
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
-
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. ↩
There was a problem hiding this comment.
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.
8e58111 to
362a2f3
Compare
|
Rebased, now includes changes from #6957 |
|
@abhipatel12 this is also custom commands related. When you have some time, review it, and then tell me what you think. |
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
a6a6a85 to
6d6bfe4
Compare
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
abhipatel12
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Is there a case where we want this for MCP prompts as commands? Or are they being excluded on purpose?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
What do you suggest?
| completionMode: CompletionMode; | ||
| } | ||
|
|
||
| export function useCommandCompletion( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
// 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
- Fix inconsistent indentation in SuggestionsDisplay component - Improve command completion search to handle spaces after cursor - Update test formatting for better readability
|
Given the multiple changes, it no longer makes sense to correct this. It is better to do everything from scratch. |
TLDR
Enables file path autocompletion for custom commands by implementing dual-mode completion that allows
@file suggestions to work with/custom-command @path/to/filesyntax. Also fixes post-rebase 35% width constraint issue affecting file path suggestion display.Key Changes:
.tomlfiles) now support both slash command completion and@file path completionDive 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
CommandKind.FILEenum to differentiate custom commands from built-in commands@detection for file path completionCompletionModepropagationTechnical Implementation
useCommandCompletion.tsx- Core dual-mode logic usingisCustomCommandhelperSuggestionsDisplay.tsx- Width constraint fix using explicit completion modeInputPrompt.tsx- Pass completion mode to UI componentsPerformance Enhancements
Map<string, SlashCommand>replaces O(n) array searchesReviewer Test Plan
Manual Testing Scenarios
1. Basic Dual-Mode Functionality
2. Edge Cases
3. Visual Validation
Automated Testing
Testing Matrix
Test Results:
Linked issues / bugs
Resolves #6685
Additional Context: