diff --git a/core/config/handler.ts b/core/config/handler.ts index f022015b98..25e7751f8f 100644 --- a/core/config/handler.ts +++ b/core/config/handler.ts @@ -1,4 +1,4 @@ -import { ContinueConfig, ContinueRcJson, IDE, ILLM } from "../index.js"; +import { ContinueConfig, ContinueRcJson, IDE, ILLM, IContextProvider } from "../index.js"; import { IdeSettings } from "../protocol.js"; import { Telemetry } from "../util/posthog.js"; import { @@ -10,6 +10,7 @@ import { export class ConfigHandler { private savedConfig: ContinueConfig | undefined; private savedBrowserConfig?: BrowserSerializedContinueConfig; + private additionalContextProviders: IContextProvider[] = []; constructor( private readonly ide: IDE, @@ -82,6 +83,10 @@ export class ConfigHandler { ideInfo.extensionVersion, ); + (this.savedConfig.contextProviders ?? []).push( + ...this.additionalContextProviders, + ); + return this.savedConfig; } @@ -95,4 +100,9 @@ export class ConfigHandler { return model; } + + registerCustomContextProvider(contextProvider: IContextProvider) { + this.additionalContextProviders.push(contextProvider); + this.reloadConfig(); + } } diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index cf248110d6..de3ddc872a 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -7,6 +7,7 @@ import registerQuickFixProvider from "../lang-server/codeActions"; import { getExtensionVersion } from "../util/util"; import { getExtensionUri } from "../util/vscode"; import { setupInlineTips } from "./inlineTips"; +import { VsCodeContinueApi } from "./api"; export async function activateExtension(context: vscode.ExtensionContext) { // Add necessary files @@ -34,4 +35,12 @@ export async function activateExtension(context: vscode.ExtensionContext) { extensionVersion: getExtensionVersion(), }); } + + const api = new VsCodeContinueApi(vscodeExtension); + const continuePublicApi = { + registerCustomContextProvider: api.registerCustomContextProvider.bind(api), + }; + + // 'export' public api-surface + return continuePublicApi; } diff --git a/extensions/vscode/src/activation/api.ts b/extensions/vscode/src/activation/api.ts new file mode 100644 index 0000000000..03a814ae98 --- /dev/null +++ b/extensions/vscode/src/activation/api.ts @@ -0,0 +1,10 @@ +import { VsCodeExtension } from "../extension/vscodeExtension"; +import { IContextProvider } from "core"; + +export class VsCodeContinueApi { + constructor(private readonly vscodeExtension: VsCodeExtension) {} + + registerCustomContextProvider(contextProvider: IContextProvider) { + this.vscodeExtension.registerCustomContextProvider(contextProvider); + } +} \ No newline at end of file diff --git a/extensions/vscode/src/extension.ts b/extensions/vscode/src/extension.ts index dc164b6eef..e04afe83e7 100644 --- a/extensions/vscode/src/extension.ts +++ b/extensions/vscode/src/extension.ts @@ -9,7 +9,7 @@ import { getExtensionVersion } from "./util/util"; async function dynamicImportAndActivate(context: vscode.ExtensionContext) { const { activateExtension } = await import("./activation/activate"); try { - await activateExtension(context); + return activateExtension(context); } catch (e) { console.log("Error activating extension: ", e); vscode.window @@ -30,7 +30,7 @@ async function dynamicImportAndActivate(context: vscode.ExtensionContext) { } export function activate(context: vscode.ExtensionContext) { - dynamicImportAndActivate(context); + return dynamicImportAndActivate(context); } export function deactivate() { diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index 4c45822c66..f001b05551 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -1,6 +1,7 @@ import { ConfigHandler } from "core/config/handler"; import { ContinueServerClient } from "core/continueServer/stubs/client"; import { CodebaseIndexer, PauseToken } from "core/indexing/indexCodebase"; +import { IContextProvider } from "core"; import { IdeSettings } from "core/protocol"; import { getConfigJsonPath, getConfigTsPath } from "core/util/paths"; import fs from "fs"; @@ -308,4 +309,8 @@ export class VsCodeExtension { console.log("Codebase Indexing Complete"); } } + + registerCustomContextProvider(contextProvider: IContextProvider) { + this.configHandler.registerCustomContextProvider(contextProvider); + } }