Skip to content

Commit

Permalink
fix(agent): fix datastore updated event. fix StatusRequest with recon…
Browse files Browse the repository at this point in the history
…nect to force refresh config. (#3521)
  • Loading branch information
icycodes authored Dec 6, 2024
1 parent 1078559 commit a52ac1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
13 changes: 12 additions & 1 deletion clients/tabby-agent/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -138,6 +139,7 @@ export class Configurations extends EventEmitter implements Feature {
clientCapabilities: ClientCapabilities,
clientProvidedConfig: ClientProvidedConfig,
): Promise<ServerCapabilities> {
this.lspConnection = connection;
this.clientCapabilities = clientCapabilities;

this.updateClientProvidedConfig(clientProvidedConfig);
Expand Down Expand Up @@ -176,7 +178,16 @@ export class Configurations extends EventEmitter implements Feature {
return this.configForLsp;
}

updateClientProvidedConfig(config: ClientProvidedConfig) {
async refreshClientProvidedConfig(): Promise<boolean> {
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;
Expand Down
6 changes: 5 additions & 1 deletion clients/tabby-agent/src/dataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoredData>;
if (!deepEqual(oldData, this.data)) {
await this.fileDataStore.write(this.data);
this.emit("updated", this.data, oldData);
}
}
}
}
10 changes: 9 additions & 1 deletion clients/tabby-agent/src/status.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -78,6 +80,12 @@ export class StatusProvider extends EventEmitter implements Feature {
},
);

this.dataStore.on("updated", async (data: Partial<StoredData>, old: Partial<StoredData>) => {
if (!deepEqual(data.statusIgnoredIssues, old.statusIgnoredIssues)) {
this.notify();
}
});

return {};
}

Expand Down

0 comments on commit a52ac1b

Please sign in to comment.