diff --git a/.gitignore b/.gitignore index 78880810a..bc9856690 100644 --- a/.gitignore +++ b/.gitignore @@ -153,6 +153,8 @@ continue_server.dist Icon Icon? +.continue +.continuerc.json .prompts/ .aider* diff --git a/core/config/ConfigHandler.test.ts b/core/config/ConfigHandler.test.ts index ef4e1814d..e817713bb 100644 --- a/core/config/ConfigHandler.test.ts +++ b/core/config/ConfigHandler.test.ts @@ -28,6 +28,10 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => { fs.writeFileSync(getConfigTsPath(), configTs); await new Promise((resolve) => setTimeout(resolve, 1000)); const config = await testConfigHandler.reloadConfig(); + /** + * @ts-ignore is applied because this test is skipped + */ + // @ts-ignore expect(config.systemMessage).toBe("SYSTEM"); }); @@ -37,6 +41,10 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => { JSON.stringify({ systemMessage: "SYSTEM2" }), ); const config = await testConfigHandler.reloadConfig(); + /** + * @ts-ignore is applied because this test is skipped + */ + // @ts-ignore expect(config.systemMessage).toBe("SYSTEM2"); }); }); diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 99f77270f..ef5cd3ec2 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -12,97 +12,24 @@ import { } from "../index.js"; import Ollama from "../llm/llms/Ollama.js"; import { GlobalContext } from "../util/GlobalContext.js"; -import { finalToBrowserConfig } from "./load.js"; +import { ConfigResult } from "./load.js"; import { LOCAL_ONBOARDING_CHAT_MODEL, ONBOARDING_LOCAL_MODEL_TITLE, } from "./onboarding.js"; import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js"; -import { IProfileLoader } from "./profile/IProfileLoader.js"; import LocalProfileLoader from "./profile/LocalProfileLoader.js"; -export interface ProfileDescription { - title: string; - id: string; -} +import { + ProfileDescription, + ProfileLifecycleManager, +} from "./ProfileLifecycleManager.js"; + +export type { ProfileDescription }; + +type ConfigUpdateFunction = (payload: ConfigResult) => void; // Separately manages saving/reloading each profile -class ProfileLifecycleManager { - private savedConfig: ContinueConfig | undefined; - private savedBrowserConfig?: BrowserSerializedContinueConfig; - private pendingConfigPromise?: Promise; - - constructor(private readonly profileLoader: IProfileLoader) {} - - get profileId() { - return this.profileLoader.profileId; - } - - get profileTitle() { - return this.profileLoader.profileTitle; - } - - get profileDescription(): ProfileDescription { - return { - title: this.profileTitle, - id: this.profileId, - }; - } - - clearConfig() { - this.savedConfig = undefined; - this.savedBrowserConfig = undefined; - this.pendingConfigPromise = undefined; - } - - // Clear saved config and reload - async reloadConfig(): Promise { - this.savedConfig = undefined; - this.savedBrowserConfig = undefined; - this.pendingConfigPromise = undefined; - - return await this.profileLoader.doLoadConfig(); - } - - async loadConfig( - additionalContextProviders: IContextProvider[], - ): Promise { - // If we already have a config, return it - if (this.savedConfig) { - return this.savedConfig; - } else if (this.pendingConfigPromise) { - return this.pendingConfigPromise; - } - - // Set pending config promise - this.pendingConfigPromise = new Promise(async (resolve, reject) => { - const newConfig = await this.profileLoader.doLoadConfig(); - - // Add registered context providers - newConfig.contextProviders = (newConfig.contextProviders ?? []).concat( - additionalContextProviders, - ); - - this.savedConfig = newConfig; - resolve(newConfig); - }); - - // Wait for the config promise to resolve - this.savedConfig = await this.pendingConfigPromise; - this.pendingConfigPromise = undefined; - return this.savedConfig; - } - - async getSerializedConfig( - additionalContextProviders: IContextProvider[], - ): Promise { - if (!this.savedBrowserConfig) { - const continueConfig = await this.loadConfig(additionalContextProviders); - this.savedBrowserConfig = finalToBrowserConfig(continueConfig); - } - return this.savedBrowserConfig; - } -} export class ConfigHandler { private readonly globalContext = new GlobalContext(); @@ -202,7 +129,11 @@ export class ConfigHandler { async setSelectedProfile(profileId: string) { this.selectedProfileId = profileId; const newConfig = await this.loadConfig(); - this.notifyConfigListeners(newConfig); + this.notifyConfigListeners({ + config: newConfig, + errors: undefined, + configLoadInterrupted: false, + }); const selectedProfiles = this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; selectedProfiles[await this.getWorkspaceId()] = profileId; @@ -248,24 +179,31 @@ export class ConfigHandler { } } - private notifyConfigListeners(newConfig: ContinueConfig) { + private notifyConfigListeners(result: ConfigResult) { // Notify listeners that config changed for (const listener of this.updateListeners) { - listener(newConfig); + listener(result); } } - private updateListeners: ((newConfig: ContinueConfig) => void)[] = []; - onConfigUpdate(listener: (newConfig: ContinueConfig) => void) { + private updateListeners: ConfigUpdateFunction[] = []; + + onConfigUpdate(listener: ConfigUpdateFunction) { this.updateListeners.push(listener); } async reloadConfig() { // TODO: this isn't right, there are two different senses in which you want to "reload" - const newConfig = await this.currentProfile.reloadConfig(); - this.inactiveProfiles.forEach((profile) => profile.clearConfig()); - this.notifyConfigListeners(newConfig); - return newConfig; + + const { config, errors, configLoadInterrupted } = + await this.currentProfile.reloadConfig(); + + if (config) { + this.inactiveProfiles.forEach((profile) => profile.clearConfig()); + } + + this.notifyConfigListeners({ config, errors, configLoadInterrupted }); + return { config, errors }; } getSerializedConfig(): Promise { diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts new file mode 100644 index 000000000..b9788e328 --- /dev/null +++ b/core/config/ProfileLifecycleManager.ts @@ -0,0 +1,99 @@ +import { config } from "dotenv"; +import { + BrowserSerializedContinueConfig, + ContinueConfig, + IContextProvider, +} from "../index.js"; + +import { ConfigResult, finalToBrowserConfig } from "./load.js"; + +import { IProfileLoader } from "./profile/IProfileLoader.js"; + +export interface ProfileDescription { + title: string; + id: string; +} + +export class ProfileLifecycleManager { + private savedConfig: ContinueConfig | undefined; + private savedBrowserConfig?: BrowserSerializedContinueConfig; + private pendingConfigPromise?: Promise; + + constructor(private readonly profileLoader: IProfileLoader) {} + + get profileId() { + return this.profileLoader.profileId; + } + + get profileTitle() { + return this.profileLoader.profileTitle; + } + + get profileDescription(): ProfileDescription { + return { + title: this.profileTitle, + id: this.profileId, + }; + } + + clearConfig() { + this.savedConfig = undefined; + this.savedBrowserConfig = undefined; + this.pendingConfigPromise = undefined; + } + + // Clear saved config and reload + async reloadConfig(): Promise> { + this.savedConfig = undefined; + this.savedBrowserConfig = undefined; + this.pendingConfigPromise = undefined; + + return this.profileLoader.doLoadConfig(); + } + + async loadConfig( + additionalContextProviders: IContextProvider[], + ): Promise { + // If we already have a config, return it + if (this.savedConfig) { + return this.savedConfig; + } else if (this.pendingConfigPromise) { + return this.pendingConfigPromise; + } + + // Set pending config promise + this.pendingConfigPromise = new Promise(async (resolve, reject) => { + const { config: newConfig, errors } = + await this.profileLoader.doLoadConfig(); + + if (newConfig) { + // Add registered context providers + newConfig.contextProviders = (newConfig.contextProviders ?? []).concat( + additionalContextProviders, + ); + + this.savedConfig = newConfig; + resolve(newConfig); + } else if (errors) { + reject( + `Error in config.json: ${errors.map((item) => item.message).join(" | ")}`, + ); + } + }); + + // Wait for the config promise to resolve + this.savedConfig = await this.pendingConfigPromise; + this.pendingConfigPromise = undefined; + return this.savedConfig; + } + + async getSerializedConfig( + additionalContextProviders: IContextProvider[], + ): Promise { + if (!this.savedBrowserConfig) { + const continueConfig = await this.loadConfig(additionalContextProviders); + this.savedBrowserConfig = finalToBrowserConfig(continueConfig); + } + return this.savedBrowserConfig; + } +} diff --git a/core/config/load.ts b/core/config/load.ts index 0a2146d71..4edb2da82 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -64,9 +64,16 @@ import { DEFAULT_PROMPTS_FOLDER, getPromptFiles, slashCommandFromPromptFile, -} from "./promptFile"; +} from "./promptFile.js"; +import { validateConfig, ConfigValidationError } from "./validation.js"; + import { GlobalContext } from "../util/GlobalContext"; -import { Readable } from "stream"; + +export interface ConfigResult { + config: T | undefined; + errors: ConfigValidationError[] | undefined; + configLoadInterrupted: boolean; +} function resolveSerializedConfig(filepath: string): SerializedContinueConfig { let content = fs.readFileSync(filepath, "utf8"); @@ -102,7 +109,7 @@ function loadSerializedConfig( ideSettings: IdeSettings, ideType: IdeType, overrideConfigJson: SerializedContinueConfig | undefined, -): SerializedContinueConfig { +): ConfigResult { const configPath = getConfigJsonPath(ideType); let config: SerializedContinueConfig = overrideConfigJson!; if (!config) { @@ -113,6 +120,16 @@ function loadSerializedConfig( } } + const errors = validateConfig(config); + + if (errors?.some((error) => error.fatal)) { + return { + errors, + config: undefined, + configLoadInterrupted: true, + }; + } + if (config.allowAnonymousTelemetry === undefined) { config.allowAnonymousTelemetry = true; } @@ -147,7 +164,7 @@ function loadSerializedConfig( ? [...defaultSlashCommandsVscode] : [...defaultSlashCommandsJetBrains]; - return config; + return { config, errors, configLoadInterrupted: false }; } async function serializedToIntermediateConfig( @@ -686,15 +703,23 @@ async function loadFullConfigNode( writeLog: (log: string) => Promise, workOsAccessToken: string | undefined, overrideConfigJson: SerializedContinueConfig | undefined, -): Promise { +): Promise> { // Serialized config - let serialized = loadSerializedConfig( + let { + config: serialized, + errors, + configLoadInterrupted, + } = loadSerializedConfig( workspaceConfigs, ideSettings, ideType, overrideConfigJson, ); + if (!serialized || configLoadInterrupted) { + return { errors, config: undefined, configLoadInterrupted: true }; + } + // Convert serialized to intermediate config let intermediate = await serializedToIntermediateConfig(serialized, ide); @@ -762,7 +787,7 @@ async function loadFullConfigNode( writeLog, workOsAccessToken, ); - return finalConfig; + return { config: finalConfig, errors, configLoadInterrupted: false }; } export { diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 12fe16ec0..ec407974a 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -8,6 +8,7 @@ import { } from "../../index.js"; import { IProfileLoader } from "./IProfileLoader.js"; import doLoadConfig from "./doLoadConfig.js"; +import { ConfigResult } from "../load.js"; export default class ControlPlaneProfileLoader implements IProfileLoader { private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes @@ -36,7 +37,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader { }, ControlPlaneProfileLoader.RELOAD_INTERVAL); } - async doLoadConfig(): Promise { + async doLoadConfig(): Promise> { const settings = this.workspaceSettings ?? ((await this.controlPlaneClient.getSettingsForWorkspace( diff --git a/core/config/profile/IProfileLoader.ts b/core/config/profile/IProfileLoader.ts index b803e3f68..2d22a821e 100644 --- a/core/config/profile/IProfileLoader.ts +++ b/core/config/profile/IProfileLoader.ts @@ -1,11 +1,12 @@ // 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 { 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; + doLoadConfig(): Promise>; setIsActive(isActive: boolean): void; } diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index 69cfeb9a5..1b4f06696 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -1,5 +1,6 @@ import { ControlPlaneClient } from "../../control-plane/client.js"; import { ContinueConfig, IDE, IdeSettings } from "../../index.js"; +import { ConfigResult } from "../load.js"; import doLoadConfig from "./doLoadConfig.js"; import { IProfileLoader } from "./IProfileLoader.js"; @@ -15,7 +16,7 @@ export default class LocalProfileLoader implements IProfileLoader { private writeLog: (message: string) => Promise, ) {} - async doLoadConfig(): Promise { + async doLoadConfig(): Promise> { return doLoadConfig( this.ide, this.ideSettingsPromise, diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index e19feed85..0aaf21e8b 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -16,7 +16,7 @@ import ContinueProxyEmbeddingsProvider from "../../indexing/embeddings/ContinueP import ContinueProxy from "../../llm/llms/stubs/ContinueProxy.js"; import { Telemetry } from "../../util/posthog.js"; import { TTS } from "../../util/tts.js"; -import { loadFullConfigNode } from "../load.js"; +import { ConfigResult, loadFullConfigNode } from "../load.js"; export default async function doLoadConfig( ide: IDE, @@ -25,7 +25,7 @@ export default async function doLoadConfig( writeLog: (message: string) => Promise, overrideConfigJson: SerializedContinueConfig | undefined, workspaceId?: string, -) { +): Promise> { let workspaceConfigs: ContinueRcJson[] = []; try { workspaceConfigs = await ide.getWorkspaceConfigs(); @@ -38,7 +38,11 @@ export default async function doLoadConfig( const ideSettings = await ideSettingsPromise; const workOsAccessToken = await controlPlaneClient.getAccessToken(); - let newConfig = await loadFullConfigNode( + let { + config: newConfig, + errors, + configLoadInterrupted, + } = await loadFullConfigNode( ide, workspaceConfigs, ideSettings, @@ -48,6 +52,11 @@ export default async function doLoadConfig( workOsAccessToken, overrideConfigJson, ); + + if (configLoadInterrupted || !newConfig) { + return { errors, config: newConfig, configLoadInterrupted: true }; + } + newConfig.allowAnonymousTelemetry = newConfig.allowAnonymousTelemetry && (await ide.isTelemetryEnabled()); @@ -89,7 +98,7 @@ export default async function doLoadConfig( controlPlaneProxyInfo, ); - return newConfig; + return { config: newConfig, errors, configLoadInterrupted: false }; } // Pass ControlPlaneProxyInfo to objects that need it diff --git a/core/config/validation.ts b/core/config/validation.ts new file mode 100644 index 000000000..e6c4d4c07 --- /dev/null +++ b/core/config/validation.ts @@ -0,0 +1,120 @@ +import { SerializedContinueConfig } from "../"; + +export interface ConfigValidationError { + fatal: boolean; + message: string; +} + +/** + * Validates a SerializedContinueConfig object to ensure all properties are correctly formed. + * @param config The configuration object to validate. + * @returns An array of error messages if there are any. Otherwise, the config is valid. + */ +export function validateConfig(config: SerializedContinueConfig) { + const errors: ConfigValidationError[] = []; + + // Validate models + if (!Array.isArray(config.models) || config.models.length === 0) { + errors.push({ + fatal: true, + message: "The 'models' field should be a non-empty array.", + }); + } else { + config.models.forEach((model, index) => { + if (typeof model.title !== "string" || model.title.trim() === "") { + errors.push({ + fatal: true, + message: `Model at index ${index} has an invalid or missing 'title'.`, + }); + } + if (typeof model.provider !== "string") { + errors.push({ + fatal: true, + message: `Model at index ${index} has an invalid 'provider'.`, + }); + } + }); + } + + // Validate slashCommands + if (config.slashCommands) { + if (!Array.isArray(config.slashCommands)) { + errors.push({ + fatal: true, + message: "The 'slashCommands' field should be an array if defined.", + }); + } else { + config.slashCommands.forEach((command, index) => { + if (typeof command.name !== "string" || command.name.trim() === "") { + errors.push({ + fatal: true, + message: `Slash command at index ${index} has an invalid or missing 'name'.`, + }); + } + if (typeof command.description !== "string") { + errors.push({ + fatal: true, + message: `Slash command at index ${index} has an invalid or missing 'description'.`, + }); + } + }); + } + } + + // Validate contextProviders + if (config.contextProviders) { + if (!Array.isArray(config.contextProviders)) { + errors.push({ + fatal: true, + message: "The 'contextProviders' field should be an array if defined.", + }); + } else { + config.contextProviders.forEach((provider, index) => { + if (typeof provider.name !== "string" || provider.name.trim() === "") { + errors.push({ + fatal: true, + message: `Context provider at index ${index} has an invalid or missing 'name'.`, + }); + } + }); + } + } + + // Validate embeddingsProvider + if ( + config.embeddingsProvider && + typeof config.embeddingsProvider !== "object" + ) { + errors.push({ + fatal: true, + message: "The 'embeddingsProvider' field should be an object if defined.", + }); + } + + // Validate reranker + if (config.reranker && typeof config.reranker !== "object") { + errors.push({ + fatal: true, + message: "The 'reranker' field should be an object if defined.", + }); + } + + // Validate other boolean flags + const booleanFlags: Array< + keyof Pick< + SerializedContinueConfig, + "allowAnonymousTelemetry" | "disableIndexing" | "disableSessionTitles" + > + > = ["allowAnonymousTelemetry", "disableIndexing", "disableSessionTitles"]; + + booleanFlags.forEach((flag) => { + if (config[flag] !== undefined && typeof config[flag] !== "boolean") { + errors.push({ + fatal: true, + message: `The '${flag}' field should be a boolean if defined.`, + }); + } + }); + + return errors.length > 0 ? errors : undefined; +} diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 9cba2d841..d6c3b684c 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -420,25 +420,28 @@ export default class DocsService { this.globalContext.update("curEmbeddingsProviderId", embeddingsProvider.id); - configHandler.onConfigUpdate(async (newConfig) => { - const oldConfig = this.config; + configHandler.onConfigUpdate(async ({ config: newConfig }) => { + if (newConfig) { + const oldConfig = this.config; - // Need to update class property for config at the beginning of this callback - // to ensure downstream methods have access to the latest config. - this.config = newConfig; + // Need to update class property for config at the beginning of this callback + // to ensure downstream methods have access to the latest config. + this.config = newConfig; - if (oldConfig.docs !== newConfig.docs) { - await this.syncConfigAndSqlite(); - } + if (oldConfig.docs !== newConfig.docs) { + await this.syncConfigAndSqlite(); + } - const shouldReindex = await this.shouldReindexDocsOnNewEmbeddingsProvider( - newConfig.embeddingsProvider.id, - ); + const shouldReindex = + await this.shouldReindexDocsOnNewEmbeddingsProvider( + newConfig.embeddingsProvider.id, + ); - if (shouldReindex) { - await this.reindexDocsOnNewEmbeddingsProvider( - newConfig.embeddingsProvider, - ); + if (shouldReindex) { + await this.reindexDocsOnNewEmbeddingsProvider( + newConfig.embeddingsProvider, + ); + } } }); } diff --git a/core/package.json b/core/package.json index 951f84856..ffed10a93 100644 --- a/core/package.json +++ b/core/package.json @@ -4,6 +4,7 @@ "description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js", "scripts": { "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --runInBand", + "tsc:check": "tsc -p ./ --noEmit", "build:npm": "tsc -p ./tsconfig.npm.json", "lint": "eslint . --ext ts", "lint:fix": "eslint . --ext ts --fix" diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index d3b127fdc..eccb1e97e 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -1,7 +1,9 @@ +import { ConfigValidationError } from "../config/validation.js"; import type { ContextItemWithId, IndexingProgressUpdate } from "../index.js"; export type ToWebviewFromIdeOrCoreProtocol = { configUpdate: [undefined, void]; + configError: [ConfigValidationError[] | undefined, void]; getDefaultModelTitle: [undefined, string]; indexProgress: [IndexingProgressUpdate, void]; refreshSubmenuItems: [undefined, void]; diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 5959edbe9..d6054c6c5 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -520,6 +520,7 @@ "esbuild": "npm run esbuild-base -- --sourcemap", "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", "tsc": "tsc -p ./", + "tsc:check": "tsc -p ./ --noEmit", "tsc-watch": "tsc -watch -p ./", "rebuild": "electron-rebuild -v 19.1.8 node-pty", "lint": "eslint src --ext ts", diff --git a/extensions/vscode/src/autocomplete/statusBar.ts b/extensions/vscode/src/autocomplete/statusBar.ts index ae541151f..5f59b9660 100644 --- a/extensions/vscode/src/autocomplete/statusBar.ts +++ b/extensions/vscode/src/autocomplete/statusBar.ts @@ -40,9 +40,20 @@ export const getStatusBarStatusFromQuickPickItemLabel = ( } }; -const statusBarItemText = (status: StatusBarStatus | undefined) => { +const statusBarItemText = ( + status: StatusBarStatus | undefined, + loading?: boolean, + error?: boolean, +) => { + if (error) { + return "$(alert) Continue (FATAL ERROR)"; + } + switch (status) { case undefined: + if (loading) { + return "$(loading~spin) Continue"; + } case StatusBarStatus.Disabled: return "$(circle-slash) Continue"; case StatusBarStatus.Enabled: @@ -67,6 +78,7 @@ const statusBarItemTooltip = (status: StatusBarStatus | undefined) => { let statusBarStatus: StatusBarStatus | undefined = undefined; let statusBarItem: vscode.StatusBarItem | undefined = undefined; let statusBarFalseTimeout: NodeJS.Timeout | undefined = undefined; +let statusBarError: boolean = false; export function stopStatusBarLoading() { statusBarFalseTimeout = setTimeout(() => { @@ -74,9 +86,15 @@ export function stopStatusBarLoading() { }, 100); } +/** + * TODO: We should clean up how status bar is handled. + * Ideally, there should be a single 'status' value without + * 'loading' and 'error' booleans. + */ export function setupStatusBar( status: StatusBarStatus | undefined, loading?: boolean, + error?: boolean, ) { if (loading !== false) { clearTimeout(statusBarFalseTimeout); @@ -90,9 +108,19 @@ export function setupStatusBar( ); } - statusBarItem.text = loading - ? "$(loading~spin) Continue" - : statusBarItemText(status); + if (error !== undefined) { + statusBarError = error; + + if (status === undefined) { + status = statusBarStatus; + } + + if (loading === undefined) { + loading = loading; + } + } + + statusBarItem.text = statusBarItemText(status, loading, statusBarError); statusBarItem.tooltip = statusBarItemTooltip(status ?? statusBarStatus); statusBarItem.command = "continue.openTabAutocompleteConfigMenu"; diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 674a80d1f..ce0f97979 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -151,18 +151,29 @@ export class VsCodeExtension { verticalDiffCodeLens.refresh.bind(verticalDiffCodeLens); }); - this.configHandler.onConfigUpdate((newConfig) => { - this.sidebar.webviewProtocol?.request("configUpdate", undefined); + this.configHandler.onConfigUpdate( + ({ config: newConfig, errors, configLoadInterrupted }) => { + if (configLoadInterrupted) { + // Show error in status bar + setupStatusBar(undefined, undefined, true); + } else if (newConfig) { + setupStatusBar(undefined, undefined, false); - this.tabAutocompleteModel.clearLlm(); + this.sidebar.webviewProtocol?.request("configUpdate", undefined); - registerAllCodeLensProviders( - context, - this.diffManager, - this.verticalDiffManager.filepathToCodeLens, - newConfig, - ); - }); + this.tabAutocompleteModel.clearLlm(); + + registerAllCodeLensProviders( + context, + this.diffManager, + this.verticalDiffManager.filepathToCodeLens, + newConfig, + ); + } + + this.sidebar.webviewProtocol?.request("configError", errors); + }, + ); // Tab autocomplete const config = vscode.workspace.getConfiguration(EXTENSION_NAME); diff --git a/gui/package.json b/gui/package.json index 2f64ed22a..dae097902 100644 --- a/gui/package.json +++ b/gui/package.json @@ -6,6 +6,7 @@ "license": "Apache-2.0", "scripts": { "dev": "vite", + "tsc:check": "tsc -p ./ --noEmit", "build": "tsc && vite build", "preview": "vite preview", "test": "vitest run", diff --git a/gui/src/App.tsx b/gui/src/App.tsx index f5ef97e67..b384936c5 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -15,6 +15,8 @@ import MonacoPage from "./pages/monaco"; import MorePage from "./pages/More"; import SettingsPage from "./pages/settings"; import Stats from "./pages/stats"; +import { ROUTES } from "./util/navigation"; +import ConfigErrorPage from "./pages/config-error"; const router = createMemoryRouter([ { @@ -54,6 +56,10 @@ const router = createMemoryRouter([ path: "/more", element: , }, + { + path: ROUTES.CONFIG_ERROR, + element: , + }, { path: "/monaco", element: , diff --git a/gui/src/components/Footer.tsx b/gui/src/components/Footer.tsx index 671b000fb..4b6b012a8 100644 --- a/gui/src/components/Footer.tsx +++ b/gui/src/components/Footer.tsx @@ -1,10 +1,11 @@ import { Cog6ToothIcon, EllipsisHorizontalCircleIcon, + ExclamationTriangleIcon, } from "@heroicons/react/24/outline"; import { useContext } from "react"; import { useSelector } from "react-redux"; -import { useNavigate } from "react-router-dom"; +import { useLocation, useNavigate, useResolvedPath } from "react-router-dom"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; import { RootState } from "../redux/store"; @@ -12,21 +13,26 @@ import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial"; import ButtonWithTooltip from "./ButtonWithTooltip"; import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar"; import ProfileSwitcher from "./ProfileSwitcher"; +import { ROUTES } from "../util/navigation"; function Footer() { const navigate = useNavigate(); + const { pathname } = useLocation(); const defaultModel = useSelector(defaultModelSelector); const ideMessenger = useContext(IdeMessengerContext); const selectedProfileId = useSelector( (store: RootState) => store.state.selectedProfileId, ); + const configError = useSelector( + (store: RootState) => store.state.configError, + ); function onClickMore() { - if (location.pathname === "/more") { - navigate("/"); - } else { - navigate("/more"); - } + navigate(pathname === ROUTES.MORE ? "/" : ROUTES.MORE); + } + + function onClickError() { + navigate(pathname === ROUTES.CONFIG_ERROR ? "/" : ROUTES.CONFIG_ERROR); } function onClickSettings() { @@ -53,6 +59,16 @@ function Footer() {
+ {configError && ( + + + + )} + { const dispatch = useDispatch(); const ideMessenger = useContext(IdeMessengerContext); const onboardingCard = useOnboardingCard(); + const { pathname } = useLocation(); + + const configError = useConfigError(); + + const hasFatalErrors = useMemo(() => { + return configError?.some((error) => error.fatal); + }, [configError]); const dialogMessage = useSelector( (state: RootState) => state.uiState.dialogMessage, @@ -200,6 +209,20 @@ const Layout = () => { + {hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && ( +
navigate(ROUTES.CONFIG_ERROR)} + > + Error!{" "} + + Could not load config.json + +
Learn More
+
+ )} +