Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigHandler: make updateIdeSettings work (better) #3456

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/config/ConfigHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class ConfigHandler {
// Set local profile as default
const localProfileLoader = new LocalProfileLoader(
ide,
ideSettingsPromise,
controlPlaneClient,
writeLog,
);
Expand Down Expand Up @@ -111,7 +110,6 @@ export class ConfigHandler {
workspace.name,
this.controlPlaneClient,
this.ide,
this.ideSettingsPromise,
this.writeLog,
this.reloadConfig.bind(this),
);
Expand Down Expand Up @@ -210,7 +208,7 @@ export class ConfigHandler {
// TODO: this isn't right, there are two different senses in which you want to "reload"

const { config, errors, configLoadInterrupted } =
await this.currentProfile.reloadConfig();
await this.currentProfile.reloadConfig(this.ideSettingsPromise);

if (config) {
this.inactiveProfiles.forEach((profile) => profile.clearConfig());
Expand All @@ -224,6 +222,7 @@ export class ConfigHandler {
ConfigResult<BrowserSerializedContinueConfig>
> {
return this.currentProfile.getSerializedConfig(
this.ideSettingsPromise,
this.additionalContextProviders,
);
}
Expand All @@ -233,7 +232,8 @@ export class ConfigHandler {
}

async loadConfig(): Promise<ConfigResult<ContinueConfig>> {
return await this.currentProfile.loadConfig(
return this.currentProfile.loadConfig(
this.ideSettingsPromise,
this.additionalContextProviders,
);
}
Expand Down
11 changes: 7 additions & 4 deletions core/config/ProfileLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BrowserSerializedContinueConfig,
ContinueConfig,
IContextProvider,
IdeSettings,
} from "../index.js";

import { ConfigResult, finalToBrowserConfig } from "./load.js";
Expand Down Expand Up @@ -41,15 +42,16 @@ export class ProfileLifecycleManager {
}

// Clear saved config and reload
async reloadConfig(): Promise<ConfigResult<ContinueConfig>> {
async reloadConfig(ideSettingsPromise: Promise<IdeSettings>): Promise<ConfigResult<ContinueConfig>> {
this.savedConfigResult = undefined;
this.savedBrowserConfigResult = undefined;
this.pendingConfigPromise = undefined;

return this.loadConfig([], true);
return this.loadConfig(ideSettingsPromise, [], true);
}

async loadConfig(
ideSettingsPromise: Promise<IdeSettings>,
additionalContextProviders: IContextProvider[],
forceReload: boolean = false,
): Promise<ConfigResult<ContinueConfig>> {
Expand All @@ -64,7 +66,7 @@ export class ProfileLifecycleManager {

// Set pending config promise
this.pendingConfigPromise = new Promise(async (resolve, reject) => {
const result = await this.profileLoader.doLoadConfig();
const result = await this.profileLoader.doLoadConfig(ideSettingsPromise);

if (result.config) {
// Add registered context providers
Expand All @@ -88,12 +90,13 @@ export class ProfileLifecycleManager {
}

async getSerializedConfig(
ideSettingsPromise: Promise<IdeSettings>,
additionalContextProviders: IContextProvider[],
): Promise<ConfigResult<BrowserSerializedContinueConfig>> {
if (this.savedBrowserConfigResult) {
return this.savedBrowserConfigResult;
} else {
const result = await this.loadConfig(additionalContextProviders);
const result = await this.loadConfig(ideSettingsPromise, additionalContextProviders);
if (!result.config) {
return {
...result,
Expand Down
5 changes: 2 additions & 3 deletions core/config/profile/ControlPlaneProfileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
private workspaceTitle: string,
private readonly controlPlaneClient: ControlPlaneClient,
private readonly ide: IDE,
private ideSettingsPromise: Promise<IdeSettings>,
private writeLog: (message: string) => Promise<void>,
private readonly onReload: () => void,
) {
Expand All @@ -39,7 +38,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
}, ControlPlaneProfileLoader.RELOAD_INTERVAL);
}

async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
async doLoadConfig(ideSettingsPromise: Promise<IdeSettings>): Promise<ConfigResult<ContinueConfig>> {
const settings =
this.workspaceSettings ??
((await this.controlPlaneClient.getSettingsForWorkspace(
Expand All @@ -49,7 +48,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {

const results = await doLoadConfig(
this.ide,
this.ideSettingsPromise,
ideSettingsPromise,
this.controlPlaneClient,
this.writeLog,
serializedConfig,
Expand Down
7 changes: 5 additions & 2 deletions core/config/profile/IProfileLoader.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// ProfileHandlers manage the loading of a config, allowing us to abstract over different ways of getting to a ContinueConfig

import { ContinueConfig } from "../../index.js";
import {
ContinueConfig,
IdeSettings,
} from "../../index.js";
import { ConfigResult } from "../load.js";

// After we have the ContinueConfig, the ConfigHandler takes care of everything else (loading models, lifecycle, etc.)
export interface IProfileLoader {
profileTitle: string;
profileId: string;
doLoadConfig(): Promise<ConfigResult<ContinueConfig>>;
doLoadConfig(ideSettingsPromise: Promise<IdeSettings>): Promise<ConfigResult<ContinueConfig>>;
setIsActive(isActive: boolean): void;
}
5 changes: 2 additions & 3 deletions core/config/profile/LocalProfileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ export default class LocalProfileLoader implements IProfileLoader {

constructor(
private ide: IDE,
private ideSettingsPromise: Promise<IdeSettings>,
private controlPlaneClient: ControlPlaneClient,
private writeLog: (message: string) => Promise<void>,
) {}

async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
async doLoadConfig(ideSettingsPromise: Promise<IdeSettings>): Promise<ConfigResult<ContinueConfig>> {
return doLoadConfig(
this.ide,
this.ideSettingsPromise,
ideSettingsPromise,
this.controlPlaneClient,
this.writeLog,
undefined,
Expand Down