[ide-mode] Create an IDE manager class to handle connecting to and exposing methods from the IDE server#4797
[ide-mode] Create an IDE manager class to handle connecting to and exposing methods from the IDE server#4797
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @chrstnb, 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 introduces a dedicated IdeModeManager class to centralize and abstract the logic for connecting to and managing the IDE server. This significant refactoring decouples the IDE integration from the general MCP server configuration and client handling, leading to a more extensible, maintainable, and robust IDE mode implementation. It also streamlines how the CLI reports the IDE connection status.
Highlights
- Centralized IDE Mode Management: A new
IdeModeManagerclass has been introduced inpackages/core/src/ide/ide-mode-manager.ts. This class encapsulates all logic related to connecting to the IDE server, managing its connection status, and handling IDE-specific notifications (likeOpenFilesNotificationSchema). It uses its own MCP client to connect to the IDE server, decoupling this integration from the general MCP server configuration. - Decoupled IDE Server Configuration: The manual configuration of the IDE server connection, previously handled within
packages/cli/src/config/config.tsbased onideModeand environment variables, has been removed. This logic is now managed entirely by the newIdeModeManager, simplifying the main configuration flow. - Simplified IDE Status Reporting: The
ide statuscommand in the CLI (packages/cli/src/ui/commands/ideCommand.tsand its tests) has been refactored to use theIdeModeManager'sgetConnectionStatus()method and the newIDEConnectionStatusenum. This streamlines the status reporting logic and provides clearer connection states (Connected, Disconnected, Connecting). - Refactored MCP Client for IDE: The general
mcp-client.tsinpackages/core/src/tools/no longer contains IDE-specific connection and notification handling. This responsibility has been fully transferred to theIdeModeManager, ensuring a cleaner separation of concerns. - IDE Tool Renaming: The VS Code IDE companion server (
packages/vscode-ide-companion/src/ide-server.ts) has updated the name of one of its exposed tools fromgetOpenFilestogetActiveFile, indicating a more precise capability for retrieving the currently active file.
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 or fill out our survey to provide feedback.
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 introduces a new IdeModeManager class to abstract and centralize the logic for connecting to the IDE server. This is a great architectural improvement that decouples the IDE-specific logic from the generic MCP client implementation. The refactoring across the codebase to use this new manager is clean and well-executed.
My review focuses on enhancing the robustness of the new IdeModeManager. I've identified a couple of areas where error handling can be improved to prevent silent failures, which are critical for maintainability and debugging.
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x' artifact from the main CI run. |
| console.debug('[DEBUG] [ImportProcessor]', ...args), | ||
| }; | ||
|
|
||
| export enum IDEConnectionStatus { |
There was a problem hiding this comment.
Given we're leaning on MCP for this any reason to not re-use our existing status details?
There was a problem hiding this comment.
I think it's possible we might want to support different protocols so wanted to keep them separate so the fact that it's relying on an MCP server is an implementation detail of the manager (now client). WDYT?
| client: Client | undefined = undefined; | ||
| connectionStatus: IDEConnectionStatus = IDEConnectionStatus.Disconnected; | ||
|
|
||
| constructor() { |
There was a problem hiding this comment.
- instead of initializing IDE mode implicitly, can we initialize it when the user invokes the /ide slash command? so the /ide slash command would act as a toggle for enabling / disabling IDE mode
- until we're ready to launch, we should still hide /ide behind the --ide-mode flag
There was a problem hiding this comment.
I moved it so it gets kicked off if ide-mode is enabled to match the current behavior, but we have more flexibility if we want to invoke it ad hoc! I think it makes sense in a follow up tho?
| const idePort = process.env['GEMINI_CLI_IDE_SERVER_PORT']; | ||
| if (!idePort) { | ||
| logger.debug( | ||
| 'Unable to connect to IDE mode MCP server. GEMINI_CLI_IDE_SERVER_PORT environment variable is not set.', |
There was a problem hiding this comment.
lets surface this error message to the user via /ide and indicate the companion extension must be installed + they must run in the VS Code integrated terminal
There was a problem hiding this comment.
I think this is a good idea but out of scope for this PR-- I think we should move all of the install stuff into this package as an 'install registry', allowing us to surface installable options but still allowing other options to connect via the protocol. WDYT?
|
Note: let's add support here for threading through the name of the IDE #4682 (comment) |
…posing methods from the IDE server (#4797)
…posing methods from the IDE server (google-gemini#4797)
…posing methods from the IDE server (google-gemini#4797)
…posing methods from the IDE server (google-gemini#4797)
…posing methods from the IDE server (google-gemini#4797)
TLDR
This is an incremental change towards an extensible implementation.
This uses its own mcp client to connect to the IDE server to decouple this from the user-installed MCP implementation-- we may want to expose this MCP server as part of the other MCP servers to the model in the future, but an alternative implementation is to define a tool the model can use.
In follow-ups:
Reviewer Test Plan
Test out the current IDE mode and ensure everything still works.
Testing Matrix
Linked issues / bugs
#4800