Fix(command): line/block Comments Incorrectly Parsed as Slash Commands#6957
Fix(command): line/block Comments Incorrectly Parsed as Slash Commands#6957NTaylorMullen merged 8 commits intogoogle-gemini:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @lifefloating, 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 addresses a critical bug where JavaScript and C-style comments were mistakenly parsed as slash commands within the CLI, leading to "Unknown command" errors and incorrect UI coloring. The core of the fix involves refining the isSlashCommand utility function to accurately distinguish between actual commands and code comments. This improved logic is then consistently applied across various UI components and the command processing flow, ensuring that comments are treated as normal text and the UI reflects the correct state.
Highlights
- Command Recognition Logic: The
isSlashCommandutility function has been updated to correctly differentiate between legitimate slash commands (e.g.,/help) and code comments (e.g.,// commentor/* comment */). It now explicitly excludes strings starting with//or/*. - UI Component Updates: UI components like
SuggestionsDisplay.tsxandUserMessage.tsxthat previously usedtext.startsWith('/')for styling and command mode detection now correctly utilize the enhancedisSlashCommandutility function. This resolves the incorrect pink/purple coloring for comments. - Command Processing Flow: The
useGeminiStreamhook now only attempts to process a query as a slash command ifisSlashCommandreturns true, preventing comments from being sent to the slash command processor. - Test Coverage: New test cases have been added to
useCommandCompletion.test.ts,useGeminiStream.test.tsx, andcommandUtils.test.tsto ensure that JavaScript and C-style comments are correctly identified as non-commands and do not trigger command-related behaviors or prompt completions.
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 pull request effectively resolves the issue of JavaScript and C-style comments being misinterpreted as slash commands. The approach of centralizing the logic in the isSlashCommand utility function and updating all call sites is clean and correct. The addition of comprehensive unit tests for both the utility function and its usage in various hooks is excellent. I have one suggestion to make the new isSlashCommand function more concise and maintainable, but overall this is a solid contribution.
abhipatel12
left a comment
There was a problem hiding this comment.
Hey! Thanks for the contribution! Left a few comments. Lmk what you think and then I can approve!
|
Hi @abhipatel12 You're absolutely right that comments such as these are not limited to C++/JavaScript. |
abhipatel12
left a comment
There was a problem hiding this comment.
Looks great, thanks for making the changes!
LGTM, I'll get this set up for final approval and merged. Thanks again for the contribution.
#6957) Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
google-gemini#6957) Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
…s (#6957) Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
google-gemini#6957) Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
google-gemini#6957) Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>


TLDR
Fixed an issue where JavaScript comments starting with
//were incorrectly parsed as slash commands, causing "Unknown command" errors and wrong UI coloring. The fix enhances theisSlashCommandfunction to properly distinguish between legitimate commands (/help) and code comments (//comment), ensuring comments are treated as normal text and sent directly to Gemini.Key changes:
//and/*commentsDive Deeper
Root Cause Analysis
The issue occurred at multiple levels:
Command Recognition Logic: The
isSlashCommandfunction used simplestartsWith('/')check, which caught both legitimate commands (/help) and JavaScript comments (//comment)UI Color Logic: Multiple UI components directly used
text.startsWith('/')for styling decisions instead of using the properisSlashCommandfunctionProcessing Flow: All inputs starting with
/were unconditionally passed to the slash command processor, even when they weren't actual commandsProblem Example
This resulted in:
Testing Matrix
Linked issues / bugs
#6953
#2240