From a52ac1bc500dcbc7089a9bc81646500643f8a84e Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Fri, 6 Dec 2024 12:38:04 +0800 Subject: [PATCH] fix(agent): fix datastore updated event. fix StatusRequest with reconnect to force refresh config. (#3521) --- clients/tabby-agent/src/config/index.ts | 13 ++++++++++++- clients/tabby-agent/src/dataStore/index.ts | 6 +++++- clients/tabby-agent/src/status.ts | 10 +++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/clients/tabby-agent/src/config/index.ts b/clients/tabby-agent/src/config/index.ts index 2b925b66afb8..da64206b5c21 100644 --- a/clients/tabby-agent/src/config/index.ts +++ b/clients/tabby-agent/src/config/index.ts @@ -80,6 +80,7 @@ export class Configurations extends EventEmitter implements Feature { private configForLsp: TabbyLspConfig = { server: defaultConfigData["server"] }; // config for lsp client + private lspConnection: Connection | undefined = undefined; private clientCapabilities: ClientCapabilities | undefined = undefined; constructor(private readonly dataStore: DataStore) { @@ -138,6 +139,7 @@ export class Configurations extends EventEmitter implements Feature { clientCapabilities: ClientCapabilities, clientProvidedConfig: ClientProvidedConfig, ): Promise { + this.lspConnection = connection; this.clientCapabilities = clientCapabilities; this.updateClientProvidedConfig(clientProvidedConfig); @@ -176,7 +178,16 @@ export class Configurations extends EventEmitter implements Feature { return this.configForLsp; } - updateClientProvidedConfig(config: ClientProvidedConfig) { + async refreshClientProvidedConfig(): Promise { + if (this.clientCapabilities?.workspace?.configuration) { + const config = await this.lspConnection?.workspace.getConfiguration(); + this.updateClientProvidedConfig(config); + return true; + } + return false; + } + + private updateClientProvidedConfig(config: ClientProvidedConfig) { if (!deepEqual(config, this.clientProvided)) { const old = this.clientProvided; this.clientProvided = config; diff --git a/clients/tabby-agent/src/dataStore/index.ts b/clients/tabby-agent/src/dataStore/index.ts index 993570e73e4d..64c8567ff3ba 100644 --- a/clients/tabby-agent/src/dataStore/index.ts +++ b/clients/tabby-agent/src/dataStore/index.ts @@ -100,7 +100,11 @@ export class DataStore extends EventEmitter implements Feature { }); } } else if (this.fileDataStore) { - await this.fileDataStore.write(this.data); + const oldData = (await this.fileDataStore.read()) as Partial; + if (!deepEqual(oldData, this.data)) { + await this.fileDataStore.write(this.data); + this.emit("updated", this.data, oldData); + } } } } diff --git a/clients/tabby-agent/src/status.ts b/clients/tabby-agent/src/status.ts index 2c41dc485a38..53cf852ab9c8 100644 --- a/clients/tabby-agent/src/status.ts +++ b/clients/tabby-agent/src/status.ts @@ -1,10 +1,11 @@ import type { Connection } from "vscode-languageserver"; import type { Feature } from "./feature"; -import type { DataStore } from "./dataStore"; +import type { DataStore, StoredData } from "./dataStore"; import type { Configurations } from "./config"; import type { TabbyApiClient } from "./http/tabbyApiClient"; import { EventEmitter } from "events"; import { ShowMessageRequest, ShowMessageRequestParams, MessageType } from "vscode-languageserver"; +import deepEqual from "deep-equal"; import { ClientCapabilities, ServerCapabilities, @@ -40,6 +41,7 @@ export class StatusProvider extends EventEmitter implements Feature { connection.onRequest(StatusRequest.type, async (params) => { if (params?.recheckConnection) { + await this.configurations.refreshClientProvidedConfig(); await this.tabbyApiClient.connect({ reset: true }); } return this.buildStatusInfo({ includeHelpMessage: true }); @@ -78,6 +80,12 @@ export class StatusProvider extends EventEmitter implements Feature { }, ); + this.dataStore.on("updated", async (data: Partial, old: Partial) => { + if (!deepEqual(data.statusIgnoredIssues, old.statusIgnoredIssues)) { + this.notify(); + } + }); + return {}; }