From df088c7eaef4a8414a71dcd22913984d19e2569e Mon Sep 17 00:00:00 2001 From: Adam Shedivy <50843283+ajshedivy@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:26:03 -0500 Subject: [PATCH] update docs with VSCode API example (#1476) * add vscode api docs * update func ref * fix typo --- docs/docs/customization/context-providers.md | 65 ++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/docs/docs/customization/context-providers.md b/docs/docs/customization/context-providers.md index fae39432f..cbf5b8449 100644 --- a/docs/docs/customization/context-providers.md +++ b/docs/docs/customization/context-providers.md @@ -480,3 +480,68 @@ If you'd like to write a context provider in a language other than TypeScript, y ``` Then, create a server that responds to requests as are made from [HttpContextProvider.ts](../../../core/context/providers/HttpContextProvider.ts). See the `hello` endpoint in [context_provider_server.py](../../../core/context/providers/context_provider_server.py) for an example that uses FastAPI. + +### Extension API for VSCode + +Continue exposes an API for registering context providers from a 3rd party VSCode extension. This is useful if you have a VSCode extension that provides some additional context that you would like to use in Continue. To use this API, add the following to your `package.json`: + +```json +{ + "extensionDependencies": [ + "continue.continue" + ], +} +``` + +Or copy `~/.continue/type/core/index.d.ts` to your extension repository. + +Then, you can use the `registerCustomContextProvider` function to register your context provider. Your custom context provider must implement the `IContextProvider` interface. +Here is an example: + +```typescript +import * as vscode from "vscode"; + +class MyCustomProvider implements IContextProvider { + + get description(): ContextProviderDescription { + return { + title: "custom", + displayTitle: "Custom", + description: "Custom description", + type: "normal", + }; + } + + async getContextItems( + query: string, + extras: ContextProviderExtras + ): Promise { + return [ + { + name: "Custom", + description: "Custom description", + content: "Custom content", + }, + ]; + } + + async loadSubmenuItems( + args: LoadSubmenuItemsArgs + ): Promise { + return []; + } +} + +// create an instance of your custom provider +const customProvider = new MyCustomProvider(); + +// get Continue extension using vscode API +const continueExt = vscode.extensions.getExtension("continue.continue"); + +// get the API from the extension +const continueApi = continueExt?.exports; + +// register your custom provider +continueApi?.registerCustomContextProvider(customProvider); + +``` \ No newline at end of file