mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Introduce IDE mode installer (#4877)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user