Skip to content

Commit

Permalink
Expose custom context provider registration through a vscode extensio…
Browse files Browse the repository at this point in the history
…n api. (#1288)
  • Loading branch information
samelhusseini authored May 23, 2024
1 parent 167b1a3 commit 2e1c2f5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
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);
}
}

0 comments on commit 2e1c2f5

Please sign in to comment.