Introduce IDE mode installer (#4877)

This commit is contained in:
christine betts
2025-07-30 21:26:31 +00:00
committed by GitHub
parent cb6a2161fe
commit 3e1b2dc33a
18 changed files with 433 additions and 277 deletions

View File

@@ -4,6 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {
detectIde,
DetectedIde,
getIdeDisplayName,
} from '../ide/detect-ide.js';
import { ideContext, IdeContextNotificationSchema } from '../ide/ideContext.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
@@ -32,13 +37,34 @@ export class IdeClient {
private state: IDEConnectionState = {
status: IDEConnectionStatus.Disconnected,
};
private static instance: IdeClient;
private readonly currentIde: DetectedIde | undefined;
private readonly currentIdeDisplayName: string | undefined;
constructor() {
private constructor(ideMode: boolean) {
if (!ideMode) {
return;
}
this.currentIde = detectIde();
if (this.currentIde) {
this.currentIdeDisplayName = getIdeDisplayName(this.currentIde);
}
this.init().catch((err) => {
logger.debug('Failed to initialize IdeClient:', err);
});
}
static getInstance(ideMode: boolean): IdeClient {
if (!IdeClient.instance) {
IdeClient.instance = new IdeClient(ideMode);
}
return IdeClient.instance;
}
getCurrentIde(): DetectedIde | undefined {
return this.currentIde;
}
getConnectionStatus(): IDEConnectionState {
return this.state;
}
@@ -141,6 +167,14 @@ export class IdeClient {
if (this.state.status === IDEConnectionStatus.Connected) {
return;
}
if (!this.currentIde) {
this.setState(
IDEConnectionStatus.Disconnected,
'Not running in a supported IDE, skipping connection.',
);
return;
}
this.setState(IDEConnectionStatus.Connecting);
if (!this.validateWorkspacePath()) {
@@ -154,4 +188,8 @@ export class IdeClient {
await this.establishConnection(port);
}
getDetectedIdeDisplayName(): string | undefined {
return this.currentIdeDisplayName;
}
}