diff --git a/clients/tabby-agent/src/config/index.ts b/clients/tabby-agent/src/config/index.ts index 59d358713784..fdf5fc2c2881 100644 --- a/clients/tabby-agent/src/config/index.ts +++ b/clients/tabby-agent/src/config/index.ts @@ -74,6 +74,8 @@ export class Configurations extends EventEmitter implements Feature { private configForLsp: TabbyLspConfig = { server: defaultConfigData["server"] }; // config for lsp client + private clientCapabilities: ClientCapabilities | undefined = undefined; + constructor(private readonly dataStore?: DataStore) { super(); } @@ -134,6 +136,8 @@ export class Configurations extends EventEmitter implements Feature { clientCapabilities: ClientCapabilities, clientProvidedConfig: ClientProvidedConfig, ): Promise { + this.clientCapabilities = clientCapabilities; + this.updateClientProvidedConfig(clientProvidedConfig); connection.onDidChangeConfiguration(async (params) => { @@ -151,6 +155,13 @@ export class Configurations extends EventEmitter implements Feature { return {}; } + async initialized(connection: Connection): Promise { + if (this.clientCapabilities?.tabby?.configDidChangeListener) { + const config = this.getConfigForLsp(); + connection.sendNotification(ConfigDidChangeNotification.type, config); + } + } + getClientProvidedConfig(): ClientProvidedConfig { return this.clientProvided; } diff --git a/clients/tabby-agent/src/http/tabbyApiClient.ts b/clients/tabby-agent/src/http/tabbyApiClient.ts index 5b4896fb89f1..4c658d8ec90e 100644 --- a/clients/tabby-agent/src/http/tabbyApiClient.ts +++ b/clients/tabby-agent/src/http/tabbyApiClient.ts @@ -247,19 +247,18 @@ export class TabbyApiClient extends EventEmitter { this.createTimeOutAbortSignal(), ]), }; + this.updateIsConnecting(true); try { if (!this.api) { throw new Error("http client not initialized"); } this.logger.debug(`Health check request: ${requestDescription}. [${requestId}]`); - this.updateIsConnecting(true); let response; if (method === "POST") { response = await this.api.POST(requestPath, requestOptions); } else { response = await this.api.GET(requestPath, requestOptions); } - this.updateIsConnecting(false); this.logger.debug(`Health check response status: ${response.response.status}. [${requestId}]`); if (response.error || !response.response.ok) { throw new HttpError(response.response); @@ -269,7 +268,6 @@ export class TabbyApiClient extends EventEmitter { this.serverHealth = response.data; this.updateStatus("ready"); } catch (error) { - this.updateIsConnecting(false); this.serverHealth = undefined; if (error instanceof HttpError && error.status == 405 && method !== "POST") { return await this.healthCheck(signal, "POST"); @@ -290,6 +288,7 @@ export class TabbyApiClient extends EventEmitter { this.updateStatus("noConnection"); } } + this.updateIsConnecting(false); } private async updateServerProvidedConfig(): Promise { diff --git a/clients/tabby-agent/src/server.ts b/clients/tabby-agent/src/server.ts index 9153d04fff46..b6b5be713d41 100644 --- a/clients/tabby-agent/src/server.ts +++ b/clients/tabby-agent/src/server.ts @@ -210,9 +210,11 @@ export class Server { private async initialized(): Promise { this.logger.info("Received initialized notification."); - await [this.completionProvider, this.chatFeature].mapAsync((feature: Feature) => { - return feature.initialized?.(this.connection); - }); + await [this.configurations, this.statusProvider, this.completionProvider, this.chatFeature].mapAsync( + (feature: Feature) => { + return feature.initialized?.(this.connection); + }, + ); // FIXME(@icycodes): remove deprecated methods if (this.clientCapabilities?.tabby?.agent) { diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index f31864b2b84b..e91b30680476 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -24,6 +24,7 @@ export class StatusProvider extends EventEmitter implements Feature { private readonly logger = getLogger("StatusProvider"); private lspConnection: Connection | undefined = undefined; + private clientCapabilities: ClientCapabilities | undefined = undefined; constructor( private readonly dataStore: DataStore, @@ -35,6 +36,7 @@ export class StatusProvider extends EventEmitter implements Feature { initialize(connection: Connection, clientCapabilities: ClientCapabilities): ServerCapabilities { this.lspConnection = connection; + this.clientCapabilities = clientCapabilities; connection.onRequest(StatusRequest.type, async (params) => { if (params?.recheckConnection) { @@ -79,6 +81,13 @@ export class StatusProvider extends EventEmitter implements Feature { return {}; } + async initialized(connection: Connection): Promise { + if (this.clientCapabilities?.tabby?.statusDidChangeListener) { + const statusInfo = await this.getStatusInfo(); + connection.sendNotification(StatusDidChangeNotification.type, statusInfo); + } + } + private async notify() { const statusInfo = await this.getStatusInfo(); this.emit("updated", statusInfo);