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

Expose programmatic context provider registration #1288

Merged
merged 2 commits into from
May 23, 2024
Merged
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
12 changes: 11 additions & 1 deletion core/config/handler.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,6 +10,7 @@ import {
export class ConfigHandler {
private savedConfig: ContinueConfig | undefined;
private savedBrowserConfig?: BrowserSerializedContinueConfig;
private additionalContextProviders: IContextProvider[] = [];

constructor(
private readonly ide: IDE,
Expand Down Expand Up @@ -82,6 +83,10 @@ export class ConfigHandler {
ideInfo.extensionVersion,
);

(this.savedConfig.contextProviders ?? []).push(
...this.additionalContextProviders,
);

return this.savedConfig;
}

Expand All @@ -95,4 +100,9 @@ export class ConfigHandler {

return model;
}

registerCustomContextProvider(contextProvider: IContextProvider) {
this.additionalContextProviders.push(contextProvider);
this.reloadConfig();
}
}
9 changes: 9 additions & 0 deletions extensions/vscode/src/activation/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions extensions/vscode/src/activation/api.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 2 additions & 2 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +30,7 @@ async function dynamicImportAndActivate(context: vscode.ExtensionContext) {
}

export function activate(context: vscode.ExtensionContext) {
dynamicImportAndActivate(context);
return dynamicImportAndActivate(context);
}

export function deactivate() {
Expand Down
5 changes: 5 additions & 0 deletions extensions/vscode/src/extension/vscodeExtension.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -308,4 +309,8 @@ export class VsCodeExtension {
console.log("Codebase Indexing Complete");
}
}

registerCustomContextProvider(contextProvider: IContextProvider) {
this.configHandler.registerCustomContextProvider(contextProvider);
}
}